[FIX] runbot_merge: properly update squash flag on PR retarget

closes #82
This commit is contained in:
Xavier Morel 2019-03-04 09:52:21 +01:00
parent 8ab72ce8d1
commit 1d2c264728
2 changed files with 33 additions and 0 deletions

View File

@ -100,6 +100,7 @@ def handle_pr(env, event):
updates = {}
if source_branch != branch:
updates['target'] = branch.id
updates['squash'] = pr['commits'] == 1
if event['changes'].keys() & {'title', 'body'}:
updates['message'] = "{}\n\n{}".format(pr['title'].strip(), pr['body'].strip())
if updates:

View File

@ -594,6 +594,38 @@ def test_edit(env, repo):
('number', '=', prx.number)
]).target == branch_1
def test_retarget_update_commits(env, repo):
""" Retargeting a PR should update its commits count
"""
branch_1 = env['runbot_merge.branch'].create({
'name': '1.0',
'project_id': env['runbot_merge.project'].search([]).id,
})
master = env['runbot_merge.branch'].search([('name', '=', 'master')])
# master is 1 commit in advance of 1.0
m = repo.make_commit(None, 'initial', None, tree={'m': 'm'})
m2 = repo.make_commit(m, 'second', None, tree={'m': 'm2'})
repo.make_ref('heads/master', m2)
repo.make_ref('heads/1.0', m)
# the PR builds on master, but is errorneously targeted to 1.0
c = repo.make_commit(m2, 'first', None, tree={'m': 'm3'})
prx = repo.make_pr('title', 'body', target='1.0', ctid=c, user='user')
pr = env['runbot_merge.pull_requests'].search([
('repository.name', '=', repo.name),
('number', '=', prx.number)
])
assert not pr.squash
prx.base = 'master'
assert pr.target == master
assert pr.squash
prx.base = '1.0'
assert pr.target == branch_1
assert not pr.squash
@pytest.mark.skip(reason="what do?")
def test_edit_retarget_managed(env, repo):
""" A PR targeted to an un-managed branch is ignored but if the PR