[IMP] runbot_merge: check squash on every PR event

All `pull_request` events seem to provide the `commits` count
property. As such we can use them all to check the `squash` state even
if we don't otherwise care for the event.

Also split out notifying an approved pull request about its missing
merge method into a separate cron from the one notifying a PR that its
siblings are ready.

Fixes #1036
This commit is contained in:
Xavier Morel 2025-01-30 11:39:20 +01:00
parent 645a10a7ca
commit 1099fc5119
3 changed files with 32 additions and 7 deletions

View File

@ -157,6 +157,10 @@ vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
)
def handle_pr(env, event):
pr = event['pull_request']
squash = pr['commits'] == 1
r = pr['base']['repo']['full_name']
if event['action'] in [
'assigned', 'unassigned', 'review_requested', 'review_request_removed',
'labeled', 'unlabeled'
@ -167,14 +171,19 @@ def handle_pr(env, event):
event['pull_request']['base']['repo']['full_name'],
event['pull_request']['number'],
)
if pr := env['runbot_merge.pull_requests'].search_fetch([
('repository.name', '=', r),
('number', '=', pr['number']),
('squash', '!=', squash),
]):
pr.squash = squash
return Response(
status=200,
mimetype="text/plain",
response="Not setup to receive action.",
)
pr = event['pull_request']
r = pr['base']['repo']['full_name']
b = pr['base']['ref']
repo = env['runbot_merge.repository'].search([('name', '=', r)])
@ -234,7 +243,7 @@ def handle_pr(env, event):
if source_branch != branch:
if branch != pr_obj.target:
updates['target'] = branch.id
updates['squash'] = pr['commits'] == 1
updates['squash'] = squash
if 'title' in event['changes'] or 'body' in event['changes']:
updates['message'] = utils.make_message(pr)
@ -330,7 +339,7 @@ def handle_pr(env, event):
pr_obj.head,
pr['head']['sha'],
event['sender']['login'],
pr['commits'] == 1
squash,
)
if pr['base']['ref'] != pr_obj.target.name:
env['runbot_merge.fetch_job'].create({
@ -343,10 +352,14 @@ def handle_pr(env, event):
'reviewed_by': False,
'error': False,
'head': pr['head']['sha'],
'squash': pr['commits'] == 1,
'squash': squash,
})
return Response(mimetype="text/plain", response=f'Updated to {pr_obj.head}')
if event['action'] not in ('closed', 'reopened'):
if pr_obj.squash != squash:
pr_obj.squash = squash
if event['action'] == 'ready_for_review':
pr_obj.draft = False
return Response(mimetype="text/plain", response=f'Updated {pr_obj.display_name} to ready')

View File

@ -65,6 +65,17 @@
<field name="doall" eval="False"/>
<field name="priority">50</field>
</record>
<record model="ir.cron" id="check_merge_method">
<field name="name">Warn on PRs which are approved and have no merge method or squash</field>
<field name="model_id" ref="model_runbot_merge_pull_requests"/>
<field name="state">code</field>
<field name="code">model._check_merge_method_configuration(True)</field>
<field name="interval_number">6</field>
<field name="interval_type">hours</field>
<field name="numbercall">-1</field>
<field name="doall" eval="False"/>
<field name="priority">50</field>
</record>
<record model="ir.cron" id="process_updated_commits">
<field name="name">Impact commit statuses on PRs and stagings</field>
<field name="model_id" ref="model_runbot_merge_commit"/>

View File

@ -893,7 +893,7 @@ For your own safety I've ignored *everything in your entire comment*.
self.batch_id.skipchecks = True
self.reviewed_by = author
if not (self.squash or self.merge_method):
self.env.ref('runbot_merge.check_linked_prs_status')._trigger()
self.env.ref('runbot_merge.check_merge_method')._trigger()
for p in self.batch_id.prs - self:
if not p.reviewed_by:
@ -1165,7 +1165,7 @@ For your own safety I've ignored *everything in your entire comment*.
format_args={'user': login, 'pr': self},
)
if not (self.squash or self.merge_method):
self.env.ref('runbot_merge.check_linked_prs_status')._trigger()
self.env.ref('runbot_merge.check_merge_method')._trigger()
return None
def _pr_acl(self, user) -> ACL:
@ -1516,6 +1516,7 @@ For your own safety I've ignored *everything in your entire comment*.
if commit:
self.env.cr.commit()
def _check_merge_method_configuration(self, commit=False):
# send feedback for multi-commit PRs without a merge_method (which
# we've not warned yet)
methods = ''.join(