[IMP] runbot_merge: downgrade PRs to priority 1 on r-

Before this change, `r-` on a pr[p=0] does essentially nothing. At
most it will unstage if the PR had been (somewhat unnecessarily) r+'d
in the past but then the PR will get re-staged immediately.

To avoid this odd behaviour, if r- is sent to a p=0 PR not only is
the PR unreviewed (if it was reviewed) it always gets unstaged, and
its priority gets reset to 1 (high priority but doesn't bypass CI and
review). Also send a comment on that subject so followers of the pr
are notified.

Fixes #313
This commit is contained in:
Xavier Morel 2020-02-10 11:50:40 +01:00 committed by xmo-odoo
parent d9661064d6
commit 05444aaf3f
2 changed files with 44 additions and 2 deletions

View File

@ -809,8 +809,16 @@ class PullRequests(models.Model):
msg = "This PR is already reviewed, reviewing it again is useless."
elif not param and is_author:
newstate = RMINUS.get(self.state)
if newstate:
self.state = newstate
if self.priority == 0 or newstate:
if newstate:
self.state = newstate
if self.priority == 0:
self.priority = 1
Feedback.create({
'repository': self.repository.id,
'pull_request': self.number,
'message': "PR priority reset to 1, as pull requests with priority 0 ignore review state.",
})
self.unstage("unreview (r-) by %s", author.github_login)
ok = True
else:

View File

@ -3020,6 +3020,40 @@ class TestRMinus:
assert pr2.state == 'validated', "state should have been reset"
assert not env['runbot_merge.split'].search([]), "there should be no split left"
def test_rminus_p0(self, env, repo, config, users):
""" In and of itself r- doesn't do anything on p=0 since they bypass
approval, so unstage and downgrade to p=1.
"""
with repo:
m = repo.make_commit(None, 'initial', None, tree={'m': 'm'})
repo.make_ref('heads/master', m)
c = repo.make_commit(m, 'first', None, tree={'m': 'c'})
prx = repo.make_pr(title='title', body=None, target='master', head=c)
repo.post_status(prx.head, 'success', 'ci/runbot')
repo.post_status(prx.head, 'success', 'legal/cla')
prx.post_comment('hansen p=0', config['role_reviewer']['token'])
env.run_crons()
pr = env['runbot_merge.pull_requests'].search([
('repository.name', '=', repo.name),
('number', '=', prx.number),
])
assert pr.priority == 0
assert pr.staging_id
with repo:
prx.post_comment('hansen r-', config['role_reviewer']['token'])
env.run_crons()
assert not pr.staging_id, "pr should have been unstaged"
assert pr.priority == 1, "priority should have been downgraded"
assert prx.comments == [
(users['reviewer'], 'hansen p=0'),
(users['reviewer'], 'hansen r-'),
(users['user'], "PR priority reset to 1, as pull requests with priority 0 ignore review state."),
]
class TestComments:
def test_address_method(self, repo, env, config):
with repo: