From d6a77ceb491fd3df6543cade9a7c192192534105 Mon Sep 17 00:00:00 2001 From: Christophe Monniez Date: Thu, 5 Dec 2024 13:14:00 +0100 Subject: [PATCH] [IMP] runbot: qualify error contents on selected fields The current qualifying implementation is based solely on error content. With this commit the fields on which the regular expression will apply can be choosen with checkboxes. It defaults to the `content` field. --- runbot/models/build_error.py | 59 +++++++++++++++++------------- runbot/views/build_error_views.xml | 17 ++++++++- 2 files changed, 49 insertions(+), 27 deletions(-) diff --git a/runbot/models/build_error.py b/runbot/models/build_error.py index 794cbd0b..393ac4d8 100644 --- a/runbot/models/build_error.py +++ b/runbot/models/build_error.py @@ -518,7 +518,7 @@ class BuildErrorContent(models.Model): for record in self: all_qualifiers = {} for qualify_regex in qualify_regexes: - res = qualify_regex._qualify(record.content) # TODO, MAYBE choose the source field + res = qualify_regex._qualify(record) if res: # res.update({'qualifier_id': qualify_regex.id}) Probably not a good idea all_qualifiers.update(res) @@ -668,17 +668,13 @@ class ErrorQualifyRegex(models.Model): sequence = fields.Integer('Sequence', default=100) active = fields.Boolean('Active', default=True, tracking=True) regex = fields.Char('Regular expression', required=True) - source_field = fields.Selection( - [ - ("content", "Content"), - ("module", "Module Name"), - ("function", "Function Name"), - ("file_path", "File Path"), - ], - default="content", - string="Source Field", - help="Build error field on which the regex will be applied to extract a qualifier", - ) + + check_module_name = fields.Boolean('Check Module Name', default=False, help='Apply regex on Error Module Name') + check_file_path = fields.Boolean('Check File Path', default=False, help='Apply regex on Error Module Name') + check_function = fields.Boolean('Check Function name', default=False, help='Apply regex on Error Function Name') + check_content = fields.Boolean('Check content', default=True, help='Apply regex on Error Csontent') + + check_fields = fields.Char('Checked Fields', compute='_compute_check_fields', help='Fields on which regex is applied') test_ids = fields.One2many('runbot.error.qualify.test', 'qualify_regex_id', string="Test Sample", help="Error samples to test qualifying regex") @@ -717,30 +713,32 @@ for error_content in self: "The regular expresion should contain at least one named group pattern e.g: '(?P.+)'" ) - def _qualify(self, content): + @api.depends('check_module_name', 'check_file_path', 'check_function', 'check_content') + def _compute_check_fields(self): + for record in self: + res = [] + for cf in ['module_name', 'file_path', 'function', 'content']: + if record[f'check_{cf}']: + res.append(cf) + record.check_fields = ','.join(res) + + def _qualify(self, build_error_content): self.ensure_one() + content = '\n'.join([build_error_content[sf] for sf in self.check_fields.split(',') if self.check_fields]) result = False if content and self.regex: result = re.search(self.regex, content, flags=re.MULTILINE) return result.groupdict() if result else {} - @api.depends('regex', 'test_string') - def _compute_qualifiers(self): - for record in self: - if record.regex and record.test_string: - record.qualifiers = record._qualify(record.test_string) - else: - record.qualifiers = {} - class QualifyErrorTest(models.Model): _name = 'runbot.error.qualify.test' _description = 'Extended Relation between a qualify regex and a build error taken as sample' qualify_regex_id = fields.Many2one('runbot.error.qualify.regex', required=True) - error_content_id = fields.Many2one('runbot.build.error.content', string='Build Error', required=True) - build_error_summary = fields.Char(related='error_content_id.summary') - build_error_content = fields.Text(related='error_content_id.content') + error_content_id = fields.Many2one('runbot.build.error.content', string='Content Id', required=True) + build_error_summary = fields.Char(compute='_compute_summary') + build_error_content = fields.Text(compute='_compute_content') expected_result = JsonDictField('Expected Qualifiers') result = JsonDictField('Result', compute='_compute_result') is_matching = fields.Boolean(compute='_compute_result', default=False) @@ -748,5 +746,16 @@ class QualifyErrorTest(models.Model): @api.depends('qualify_regex_id.regex', 'error_content_id', 'expected_result', 'result') def _compute_result(self): for record in self: - record.result = record.qualify_regex_id._qualify(record.build_error_content) + record.result = record.qualify_regex_id._qualify(record.error_content_id) record.is_matching = record.result == record.expected_result and record.result != {} + + @api.depends('error_content_id') + def _compute_summary(self): + for record in self: + content = record.error_content_id.content + record.build_error_summary = content[:70] if content else False + + @api.depends('qualify_regex_id', 'error_content_id') + def _compute_content(self): + for record in self: + record.build_error_content = '\n'.join([record.error_content_id[sf] or '' for sf in record.qualify_regex_id.check_fields.split(',')]) diff --git a/runbot/views/build_error_views.xml b/runbot/views/build_error_views.xml index 30321fc6..898e22a1 100644 --- a/runbot/views/build_error_views.xml +++ b/runbot/views/build_error_views.xml @@ -424,7 +424,7 @@ - + @@ -443,7 +443,10 @@ - + + + + @@ -488,5 +491,15 @@ list,form + + runbot.qualify.regex.filter + runbot.error.qualify.regex + + + + + + +