[FIX] runbot_merge: check CI status when reopening a PR

Previously, creating a PR would validate the head (in case it had
already passed CI) but reopening it would not, which is inconvenient
as the CI would not automatically run on a reopened PR.

Update both the state and the head of the PR on reopen to force a
revalidation, that way if the head has already passed CI the PR will
be reopened validated and there won't be an unclear need to perform an
explicit CI run.

Fixes #119
This commit is contained in:
Xavier Morel 2019-05-07 12:32:02 +02:00
parent b59ffc68e0
commit eb91e2371b
2 changed files with 35 additions and 1 deletions

View File

@ -193,6 +193,7 @@ def handle_pr(env, event):
WHERE id = %s AND state != 'merged'
''', [pr_obj.id])
env.cr.commit()
pr_obj.invalidate_cache(fnames=['state'], ids=[pr_obj.id])
if env.cr.rowcount:
env['runbot_merge.pull_requests.tagging'].create({
'pull_request': pr_obj.number,
@ -205,10 +206,16 @@ def handle_pr(env, event):
pr_obj.repository.name, pr_obj.number,
event['sender']['login']
)
return 'Closed {}'.format(pr_obj.id)
if event['action'] == 'reopened' and pr_obj.state == 'closed':
pr_obj.state = 'opened'
pr_obj.write({
'state': 'opened',
# updating the head triggers a revalidation
'head': pr['head']['sha'],
})
return 'Reopened {}'.format(pr_obj.id)
_logger.info("Ignoring event %s on PR %s", event['action'], pr['number'])

View File

@ -778,6 +778,33 @@ def test_ci_failure_after_review(env, repo, users):
(users['user'], "'ci/runbot' failed on this reviewed PR.".format_map(users)),
]
def test_reopen_state(env, repo):
""" The PR should be validated on opening and reopening in case there's
already a CI+ stored (as the CI might never trigger unless explicitly
re-requested)
"""
m = repo.make_commit(None, 'initial', None, tree={'m': 'm'})
repo.make_ref('heads/master', m)
c = repo.make_commit(m, 'fist', None, tree={'m': 'c1'})
repo.post_status(c, 'success', 'legal/cla')
repo.post_status(c, 'success', 'ci/runbot')
prx = repo.make_pr('title', 'body', target='master', ctid=c, user='user')
pr = env['runbot_merge.pull_requests'].search([
('repository.name', '=', repo.name),
('number', '=', prx.number),
])
assert pr.state == 'validated', \
"if a PR is created on a CI'd commit, it should be validated immediately"
prx.close()
assert pr.state == 'closed'
prx.open()
assert pr.state == 'validated', \
"if a PR is reopened and had a CI'd head, it should be validated immediately"
class TestRetry:
@pytest.mark.xfail(reason="This may not be a good idea as it could lead to tons of rebuild spam")
def test_auto_retry_push(self, env, repo):