[IMP] runbot: parse log redirects to the created error

When builds logs are parsed by using the contextual button, the client
stays on the same page even if a build error is created.

With this commit, the client is now redirected to the created/found
build error(s).
This commit is contained in:
Christophe Monniez 2020-11-12 15:40:06 +01:00
parent e51a27bbbb
commit c6a1d202a1
4 changed files with 21 additions and 6 deletions

View File

@ -6,7 +6,7 @@
<field name="type">ir.actions.server</field> <field name="type">ir.actions.server</field>
<field name="state">code</field> <field name="state">code</field>
<field name="code"> <field name="code">
records._parse_logs() action = records._parse_logs()
</field> </field>
</record> </record>
<record model="ir.actions.server" id="action_parse_log"> <record model="ir.actions.server" id="action_parse_log">
@ -16,7 +16,7 @@
<field name="type">ir.actions.server</field> <field name="type">ir.actions.server</field>
<field name="state">code</field> <field name="state">code</field>
<field name="code"> <field name="code">
records._parse_logs() action = records._parse_logs()
</field> </field>
</record> </record>
</odoo> </odoo>

View File

@ -1022,7 +1022,7 @@ class BuildResult(models.Model):
# only parse logs from builds in error and not already scanned # only parse logs from builds in error and not already scanned
builds_to_scan = self.search([('id', 'in', self.ids), ('local_result', '=', 'ko'), ('build_error_ids', '=', False)]) builds_to_scan = self.search([('id', 'in', self.ids), ('local_result', '=', 'ko'), ('build_error_ids', '=', False)])
ir_logs = self.env['ir.logging'].search([('level', '=', 'ERROR'), ('type', '=', 'server'), ('build_id', 'in', builds_to_scan.ids)]) ir_logs = self.env['ir.logging'].search([('level', '=', 'ERROR'), ('type', '=', 'server'), ('build_id', 'in', builds_to_scan.ids)])
BuildError._parse_logs(ir_logs) return BuildError._parse_logs(ir_logs)
def is_file(self, file, mode='r'): def is_file(self, file, mode='r'):
file_path = self._path(file) file_path = self._path(file)

View File

@ -129,21 +129,36 @@ class BuildError(models.Model):
fingerprint = self._digest(cleaning_regs.r_sub('%', log.message)) fingerprint = self._digest(cleaning_regs.r_sub('%', log.message))
hash_dict[fingerprint].append(log) hash_dict[fingerprint].append(log)
build_errors = self.env['runbot.build.error']
# add build ids to already detected errors # add build ids to already detected errors
for build_error in self.env['runbot.build.error'].search([('fingerprint', 'in', list(hash_dict.keys())), ('active', '=', True)]): existing_errors = self.env['runbot.build.error'].search([('fingerprint', 'in', list(hash_dict.keys())), ('active', '=', True)])
build_errors |= existing_errors
for build_error in existing_errors:
for build in {rec.build_id for rec in hash_dict[build_error.fingerprint]}: for build in {rec.build_id for rec in hash_dict[build_error.fingerprint]}:
build.build_error_ids += build_error build.build_error_ids += build_error
del hash_dict[build_error.fingerprint] del hash_dict[build_error.fingerprint]
# create an error for the remaining entries # create an error for the remaining entries
for fingerprint, logs in hash_dict.items(): for fingerprint, logs in hash_dict.items():
build_error = self.env['runbot.build.error'].create({ build_errors |= self.env['runbot.build.error'].create({
'content': logs[0].message, 'content': logs[0].message,
'module_name': logs[0].name, 'module_name': logs[0].name,
'function': logs[0].func, 'function': logs[0].func,
'build_ids': [(6, False, [r.build_id.id for r in logs])], 'build_ids': [(6, False, [r.build_id.id for r in logs])],
}) })
if build_errors:
window_action = {
"type": "ir.actions.act_window",
"res_model": "runbot.build.error",
"views": [[False, "tree"]],
"domain": [('id', 'in', build_errors.ids)]
}
if len(build_errors) == 1:
window_action["views"] = [[False, "form"]]
window_action["res_id"] = build_errors.id
return window_action
def link_errors(self): def link_errors(self):
""" Link errors with the first one of the recordset """ Link errors with the first one of the recordset
choosing parent in error with responsible, random bug and finally fisrt seen choosing parent in error with responsible, random bug and finally fisrt seen

View File

@ -179,7 +179,7 @@ class RunbotErrorLog(models.Model):
def _parse_logs(self): def _parse_logs(self):
BuildError = self.env['runbot.build.error'] BuildError = self.env['runbot.build.error']
BuildError._parse_logs(self) return BuildError._parse_logs(self)
def init(self): def init(self):
""" Create an SQL view for ir.logging """ """ Create an SQL view for ir.logging """