From b25f709de101b58aa977a16304b81209ed14bbe1 Mon Sep 17 00:00:00 2001 From: Xavier-Do Date: Wed, 5 Mar 2025 15:57:45 +0100 Subject: [PATCH] [IMP] runbot: automatic error management Add an action to post the message for exceptions automatically as well as rebuilding the templates. --- runbot/models/upgrade.py | 25 +++++++++++++++++++++++-- runbot/views/upgrade.xml | 11 +++++++++-- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/runbot/models/upgrade.py b/runbot/models/upgrade.py index cea4fa2f..35b1aced 100644 --- a/runbot/models/upgrade.py +++ b/runbot/models/upgrade.py @@ -1,5 +1,5 @@ import re -from odoo import models, fields +from odoo import models, fields, api from odoo.exceptions import UserError @@ -11,10 +11,25 @@ class UpgradeExceptions(models.Model): active = fields.Boolean('Active', default=True, tracking=True) elements = fields.Text('Elements', required=True) bundle_id = fields.Many2one('runbot.bundle', index=True) + create_build_id = fields.Many2one('runbot.build', 'Build') + pr_ids = fields.Many2many('runbot.branch', string='Pull requests', default=lambda self: self.default_pr_ids()) info = fields.Text('Info') team_id = fields.Many2one('runbot.team', 'Assigned team', index=True) - message = fields.Text('Upgrade exception message', compute="_compute_message") + message = fields.Text('Upgrade exception message', compute="_compute_message", store=True) + def action_post_message(self): + if not self.env.user.has_group('runbot.group_runbot_admin'): + raise UserError('You are not allowed to send messages') + for pr in self.pr_ids: + pr.remote_id._github('/repos/:owner/:repo/issues/%s/comments' % pr.name, {'body': self.message}) + + def action_auto_rebuild(self): + builds = self.create_build_id.parent_id.children_ids if self.create_build_id.parent_id else self.create_build_id + for build in builds: + if not build.orphan_result and build.local_result == 'ko': + build._rebuild() + + @api.depends('create_date') def _compute_message(self): message_layout = self.env['ir.config_parameter'].sudo().get_param('runbot.runbot_upgrade_exception_message') for exception in self: @@ -25,6 +40,11 @@ class UpgradeExceptions(models.Model): if exceptions: return 'suppress_upgrade_warnings=%s' % (','.join(exceptions.mapped('elements'))).replace(' ', '').replace('\n', ',') return False + + def default_pr_ids(self): + bundle_id = self.env.context.get('default_bundle_id') + if bundle_id: + return self.env['runbot.branch'].search([('bundle_id', '=', bundle_id), ('is_pr', '=', True), ('alive', '=', True)]) class UpgradeRegex(models.Model): @@ -63,6 +83,7 @@ class BuildResult(models.Model): 'context': { 'default_elements': '\n'.join(exception), 'default_bundle_id': bundle, + 'default_create_build_id': self.id, 'default_info': 'Automatically generated from build %s' % self.id } } diff --git a/runbot/views/upgrade.xml b/runbot/views/upgrade.xml index 138b596c..49cf2425 100644 --- a/runbot/views/upgrade.xml +++ b/runbot/views/upgrade.xml @@ -26,7 +26,6 @@ - runbot.upgrade.exception runbot.upgrade.exception @@ -36,12 +35,20 @@ + + + + + + - + +