diff --git a/homu/main.py b/homu/main.py index 0736c6f..5f94dd5 100644 --- a/homu/main.py +++ b/homu/main.py @@ -1200,7 +1200,9 @@ def start_build(state, repo_cfgs, buildbot_slots, logger, db, git_cfg): lazy_debug(logger, lambda: "start_build on {!r}".format(state.get_repo())) - assert state.head_sha == state.get_repo().pull_request(state.num).head.sha + pr = state.get_repo().pull_request(state.num) + assert state.head_sha == pr.head.sha + assert state.base_ref == pr.base.ref repo_cfg = repo_cfgs[state.repo_label] diff --git a/homu/server.py b/homu/server.py index a770fb6..2a005ef 100644 --- a/homu/server.py +++ b/homu/server.py @@ -448,6 +448,30 @@ def fail(err): state.save() + elif action == 'edited': + state = g.states[repo_label][pull_num] + + base_ref = info['pull_request']['base']['ref'] + if state.base_ref != base_ref: + state.base_ref = base_ref + state.set_mergeable(None) + # Remove PR approval when the branch changes, to prevent the PR + # authors to merge the changes on other branches + if state.get_status() != '': + state.approved_by = '' + state.set_status('') + state.change_labels(LabelEvent.PUSHED) + state.add_comment( + ':warning: The base branch changed to `{}`, and the ' + 'PR will need to be re-approved.\n\n' + ''.format(base_ref, g.my_username) + ) + + state.title = info['pull_request']['title'] + state.body = info['pull_request']['body'] + + state.save() + else: lazy_debug(logger, lambda: 'Invalid pull_request action: {}'.format(action)) # noqa