[IMP] runbot_merge: backend UI

- Update branch name to prefix with project as it can be hard to
  differentiate when filtering by or trying to set targets, given some
  targets are extremely common (e.g. `master`/`main`) and not all
  fields are filtered by project (or even can be).
- Add a proper menu item and list view for batches, maybe it'll be of
  use one day.
- Upgrade label in PR search, it's more likely to be needed than
  author or target.
- Put PRs first in the mergebot menu, as it's *by far* the most likely
  item to look for, unless it's staging in order to cancel one.
This commit is contained in:
Xavier Morel 2024-07-15 15:52:08 +02:00
parent 47df8fac84
commit 7a0a6d4415
5 changed files with 59 additions and 14 deletions

View File

@ -52,8 +52,9 @@ class Batch(models.Model):
_description = "batch of pull request"
_inherit = ['mail.thread']
_parent_store = True
_order = "id desc"
name = fields.Char(compute="_compute_name")
name = fields.Char(compute="_compute_name", search="_search_name")
target = fields.Many2one('runbot_merge.branch', store=True, compute='_compute_target')
batch_staging_ids = fields.One2many('runbot_merge.staging.batch', 'runbot_merge_batch_id')
staging_ids = fields.Many2many(
@ -183,6 +184,9 @@ class Batch(models.Model):
for batch in self:
batch.name = batch.prs[:1].label or batch.all_prs[:1].label
def _search_name(self, operator, value):
return [('all_prs.label', operator, value)]
@api.depends("all_prs.target")
def _compute_target(self):
for batch in self:

View File

@ -284,7 +284,13 @@ class Branch(models.Model):
self._table, ['name', 'project_id'])
return res
@api.depends('active')
def name_get(self):
return [
(id, f"{b.project_id.name}:{name}")
for b, (id, name) in zip(self, super().name_get())
]
@api.depends('active', 'project_id.name')
def _compute_display_name(self):
super()._compute_display_name()
for b in self.filtered(lambda b: not b.active):

View File

@ -770,7 +770,7 @@ def test_ff_failure_batch(env, repo, users, config):
}
class TestPREdition:
def test_edit(self, env, repo, config):
def test_edit(self, env, project, repo, config):
""" Editing PR:
* title (-> message)
@ -814,7 +814,7 @@ class TestPREdition:
assert pr.target == branch_1
assert not pr.staging_id, "updated the base of a staged PR should have unstaged it"
assert st.state == 'cancelled', f"expected cancellation, got {st.state}"
assert st.reason == f"{pr.display_name} target (base) branch was changed from 'master' to '1.0'"
assert st.reason == f"{pr.display_name} target (base) branch was changed from '{project.name}:master' to '{project.name}:1.0'"
with repo: prx.base = '2.0'
assert not pr.exists()

View File

@ -1,4 +1,40 @@
<odoo>
<record id="runbot_merge_action_batches" model="ir.actions.act_window">
<field name="name">Batches</field>
<field name="res_model">runbot_merge.batch</field>
<field name="view_mode">tree,form</field>
</record>
<record id="runbot_merge_batch_search" model="ir.ui.view">
<field name="name">batches search</field>
<field name="model">runbot_merge.batch</field>
<field name="arch" type="xml">
<search>
<filter name="all" domain="['|', ('active', '=', True), ('active', '=', False)]"/>
<filter name="inactive" domain="[('active', '=', False)]"/>
<field name="name"/>
<field name="target"/>
<field name="id"/>
</search>
</field>
</record>
<record id="runbot_merge_batch_tree" model="ir.ui.view">
<field name="name">batches list</field>
<field name="model">runbot_merge.batch</field>
<field name="arch" type="xml">
<tree decoration-muted="not active">
<field name="id"/>
<field name="name"/>
<field name="target"/>
<field name="prs" widget="many2many_tags"/>
<field name="blocked"/>
<field name="active" invisible="1"/>
</tree>
</field>
</record>
<record id="runbot_merge_batch_form" model="ir.ui.view">
<field name="name">Batch form</field>
<field name="model">runbot_merge.batch</field>

View File

@ -88,9 +88,9 @@
name="open" string="Open"
domain="[('state', 'not in', ['merged', 'closed'])]"
/>
<field name="label"/>
<field name="number"/>
<field name="author"/>
<field name="label"/>
<field name="target"/>
<field name="repository"/>
<field name="state"/>
@ -416,17 +416,16 @@
</field>
</record>
<menuitem name="Mergebot" id="runbot_merge_menu"/>
<menuitem name="Projects" id="runbot_merge_menu_project"
parent="runbot_merge_menu"
action="runbot_merge_action_projects"/>
<menuitem name="Mergebot" id="runbot_merge_menu">
<menuitem name="Pull Requests" id="runbot_merge_menu_prs"
parent="runbot_merge_menu"
action="runbot_merge_action_prs"/>
action="runbot_merge_action_prs" sequence="5"/>
<menuitem name="Stagings" id="runbot_merge_menu_stagings"
parent="runbot_merge_menu"
action="runbot_merge_action_stagings"/>
action="runbot_merge_action_stagings" sequence="8"/>
<menuitem name="Projects" id="runbot_merge_menu_project"
action="runbot_merge_action_projects"/>
<menuitem name="Batches" id="runbot_merge_menu_batches"
action="runbot_merge_action_batches"/>
<menuitem name="Commits" id="runbot_merge_menu_commits"
parent="runbot_merge_menu"
action="runbot_merge_action_commits"/>
</menuitem>
</odoo>