Skip to content

Handle base branch changes #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion homu/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
24 changes: 24 additions & 0 deletions homu/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
'<!-- @{} r- -->'.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

Expand Down