[FIX] runbot_merge: when closing a staged PR, cancel the staging

This commit is contained in:
Xavier Morel 2018-05-31 16:50:36 +02:00 committed by xmo-odoo
parent 7233179d6a
commit b30bb09319
2 changed files with 31 additions and 3 deletions

View File

@ -149,6 +149,11 @@ def handle_pr(event):
# don't marked merged PRs as closed (!!!)
if event['action'] == 'closed' and pr_obj.state != 'merged':
pr_obj.state = 'closed'
pr_obj.staging_id.cancel(
"Closed PR %s:%s, removing staging %s",
pr_obj.repository.name, pr_obj.number,
pr_obj.staging_id
)
return 'Closed {}'.format(pr_obj.id)
if event['action'] == 'reopened' and pr_obj.state == 'closed':

View File

@ -338,10 +338,33 @@ def test_edit_retarget_managed(env, repo):
"""
@pytest.mark.skip(reason="What do?")
def test_edit_staged(env, repo):
pass
@pytest.mark.skip(reason="What do?")
"""
What should happen when editing the PR/metadata (not pushing) of a staged PR
"""
def test_close_staged(env, repo):
pass
"""
When closing a staged PR, cancel the staging
"""
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'})
prx = repo.make_pr('title', 'body', target='master', ctid=c, user='user')
repo.post_status(prx.head, 'success', 'legal/cla')
repo.post_status(prx.head, 'success', 'ci/runbot')
prx.post_comment('hansen r+', user='reviewer')
pr = env['runbot_merge.pull_requests'].search([
('repository.name', '=', 'odoo/odoo'),
('number', '=', prx.number),
])
env['runbot_merge.project']._check_progress()
assert pr.state == 'ready'
assert pr.staging_id
prx.close()
assert not pr.staging_id
assert not env['runbot_merge.stagings'].search([])
class TestRetry:
@pytest.mark.xfail(reason="This may not be a good idea as it could lead to tons of rebuild spam")