From 38c2bc97f3f271b4ef09be8d9ba875fe147e1b56 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Thu, 28 Nov 2024 15:41:42 +0100 Subject: [PATCH] [IMP] runbot_merge: inspectability of patch parsing Show patch metadata on the patch screen, so it's easier to understand what the parser sees in case of issues. Behaviour is not *entirely* consisten, `file_ids` is correctly set but it looks like during the initial `web_read` it gets stripped out in at least some cases and the files list is empty even though files have been found in the patch. nm. Fixes #987 --- runbot_merge/models/patcher.py | 47 +++++++++++++++++++++-- runbot_merge/security/ir.model.access.csv | 1 + runbot_merge/views/queues.xml | 40 +++++++++++++------ 3 files changed, 73 insertions(+), 15 deletions(-) diff --git a/runbot_merge/models/patcher.py b/runbot_merge/models/patcher.py index 868b6a75..80fc20d3 100644 --- a/runbot_merge/models/patcher.py +++ b/runbot_merge/models/patcher.py @@ -17,7 +17,7 @@ from email import message_from_string, policy from email.utils import parseaddr from typing import Union -from odoo import models, fields, api +from odoo import models, fields, api, Command from odoo.exceptions import ValidationError from odoo.tools.mail import plaintext2html @@ -122,6 +122,13 @@ class PatchFailure(Exception): pass +class PatchFile(models.TransientModel): + _name = "runbot_merge.patch.file" + _description = "metadata for single file to patch" + + name = fields.Char() + + class Patch(models.Model): _name = "runbot_merge.patch" _inherit = ['mail.thread'] @@ -137,6 +144,16 @@ class Patch(models.Model): ("format-patch", "format-patch"), ("show", "show"), ], compute="_compute_patch_meta") + author = fields.Char(compute="_compute_patch_meta") + # TODO: should be a datetime, parse date + authordate = fields.Char(compute="_compute_patch_meta") + committer = fields.Char(compute="_compute_patch_meta") + # TODO: should be a datetime, parse date + commitdate = fields.Char(compute="_compute_patch_meta") + file_ids = fields.One2many( + "runbot_merge.patch.file", + compute="_compute_patch_meta", + ) message = fields.Text(compute="_compute_patch_meta") _sql_constraints = [ @@ -145,13 +162,37 @@ class Patch(models.Model): @api.depends("patch") def _compute_patch_meta(self) -> None: + File = self.env['runbot_merge.patch.file'] for p in self: if r := p._parse_patch(): p.format = r.kind + match r.author: + case [name, email]: + p.author = f"{name} <{email}>" + case [name, email, date]: + p.author = f"{name} <{email}>" + p.authordate = date + match r.committer: + case [name, email]: + p.committer = f"{name} <{email}>" + case [name, email, date]: + p.committer = f"{name} <{email}>" + p.commitdate = date + p.file_ids = File.concat(*( + File.new({'name': m['file_from']}) + for m in FILE_PATTERN.finditer(p.patch) + )) p.message = r.message else: - p.format = False - p.message = False + p.update({ + 'format': False, + 'author': False, + 'authordate': False, + 'committer': False, + 'commitdate': False, + 'file_ids': False, + 'message': False, + }) def _parse_patch(self) -> ParseResult | None: if not self.patch: diff --git a/runbot_merge/security/ir.model.access.csv b/runbot_merge/security/ir.model.access.csv index 13949597..bf33e71b 100644 --- a/runbot_merge/security/ir.model.access.csv +++ b/runbot_merge/security/ir.model.access.csv @@ -32,4 +32,5 @@ access_runbot_merge_review_rights_2,Users can see partners,model_res_partner_rev access_runbot_merge_review_override_2,Users can see partners,model_res_partner_override,base.group_user,1,0,0,0 access_runbot_merge_pull_requests_feedback_template,access_runbot_merge_pull_requests_feedback_template,runbot_merge.model_runbot_merge_pull_requests_feedback_template,base.group_system,1,1,0,0 access_runbot_merge_patch,Patcher access,runbot_merge.model_runbot_merge_patch,runbot_merge.group_patcher,1,1,1,0 +access_runbot_merge_patch_file,Patcher access to patch file,model_runbot_merge_patch_file,runbot_merge.group_patcher,1,0,0,0 access_runbot_merge_backport_admin,Admin access to backport wizard,model_runbot_merge_pull_requests_backport,runbot_merge.group_admin,1,1,1,0 diff --git a/runbot_merge/views/queues.xml b/runbot_merge/views/queues.xml index 45ed15f1..a24ab725 100644 --- a/runbot_merge/views/queues.xml +++ b/runbot_merge/views/queues.xml @@ -122,20 +122,36 @@ - - - - - - - - - + + + + + + + + - - - + + + + + + + + + + + + + + + + + + + +