From a12e593fbabcf31bbf8660cf2a20ea6f343b7657 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Mon, 18 Nov 2024 09:48:48 +0100 Subject: [PATCH] [FIX] runbot_merge: backport wizard - fix incorrect view specs (the action id comes first) - add a wizard form and hook it into the PR, completely forgot to do that - usability improvements: filter branches to be in the same project as the PR being backported, and older than the current PR's branch The latter is a somewhat incomplete condition: ideally we'd want to only allow selecting branches preceding the target of the *source* of the PR being backported, that way we don't risk errors when backporting forward-ports (the condition should be checked in the final action but still). Also we're only filtering by sequence, so we're missing the name part of the ordering, hence if multiple branches have the same sequence we may not allow selecting some of the preceding branches. --- runbot_merge/__manifest__.py | 1 + runbot_merge/models/backport/__init__.py | 12 ++++++++---- runbot_merge/models/backport/views.xml | 23 +++++++++++++++++++++++ 3 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 runbot_merge/models/backport/views.xml diff --git a/runbot_merge/__manifest__.py b/runbot_merge/__manifest__.py index a21ce712..a00eb8ba 100644 --- a/runbot_merge/__manifest__.py +++ b/runbot_merge/__manifest__.py @@ -19,6 +19,7 @@ 'views/templates.xml', 'models/project_freeze/views.xml', 'models/staging_cancel/views.xml', + 'models/backport/views.xml', ], 'assets': { 'web.assets_frontend': [ diff --git a/runbot_merge/models/backport/__init__.py b/runbot_merge/models/backport/__init__.py index ddc89c7a..7be4652a 100644 --- a/runbot_merge/models/backport/__init__.py +++ b/runbot_merge/models/backport/__init__.py @@ -1,7 +1,6 @@ import logging import re import secrets -import subprocess import requests @@ -44,7 +43,7 @@ class PullRequest(models.Model): return { 'type': 'ir.actions.act_window', 'name': f"Backport of {self.display_name}", - 'views': [('form', False)], + 'views': [(False, 'form')], 'target': 'new', 'res_model': w._name, 'res_id': w.id, @@ -56,7 +55,12 @@ class PullRequestBackport(models.TransientModel): _rec_name = 'pr_id' pr_id = fields.Many2one('runbot_merge.pull_requests', required=True) - target = fields.Many2one('runbot_merge.branch') + project_id = fields.Many2one(related='pr_id.repository.project_id') + source_seq = fields.Integer(related='pr_id.target.sequence') + target = fields.Many2one( + 'runbot_merge.branch', + domain="[('project_id', '=', project_id), ('sequence', '>', source_seq)]", + ) def action_apply(self) -> dict: if not self.target: @@ -135,7 +139,7 @@ class PullRequestBackport(models.TransientModel): return { 'type': 'ir.actions.act_window', 'name': "new backport", - 'views': [('form', False)], + 'views': [(False, 'form')], 'res_model': backport._name, 'res_id': backport.id, } diff --git a/runbot_merge/models/backport/views.xml b/runbot_merge/models/backport/views.xml new file mode 100644 index 00000000..ec34d972 --- /dev/null +++ b/runbot_merge/models/backport/views.xml @@ -0,0 +1,23 @@ + + + Backport Wizard + runbot_merge.pull_requests.backport + +
+ + + + + + +
+ + + Perform backport from current PR + ir.actions.server + + + code + action = record.backport() + +