Skip to content

Commit 1f47436

Browse files
authored
Merge pull request #12 from rust-ops/double-check-branch
Handle base branch changes
2 parents 2b46a6d + ef9171f commit 1f47436

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

homu/main.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1200,7 +1200,9 @@ def start_build(state, repo_cfgs, buildbot_slots, logger, db, git_cfg):
12001200

12011201
lazy_debug(logger, lambda: "start_build on {!r}".format(state.get_repo()))
12021202

1203-
assert state.head_sha == state.get_repo().pull_request(state.num).head.sha
1203+
pr = state.get_repo().pull_request(state.num)
1204+
assert state.head_sha == pr.head.sha
1205+
assert state.base_ref == pr.base.ref
12041206

12051207
repo_cfg = repo_cfgs[state.repo_label]
12061208

homu/server.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,30 @@ def fail(err):
448448

449449
state.save()
450450

451+
elif action == 'edited':
452+
state = g.states[repo_label][pull_num]
453+
454+
base_ref = info['pull_request']['base']['ref']
455+
if state.base_ref != base_ref:
456+
state.base_ref = base_ref
457+
state.set_mergeable(None)
458+
# Remove PR approval when the branch changes, to prevent the PR
459+
# authors to merge the changes on other branches
460+
if state.get_status() != '':
461+
state.approved_by = ''
462+
state.set_status('')
463+
state.change_labels(LabelEvent.PUSHED)
464+
state.add_comment(
465+
':warning: The base branch changed to `{}`, and the '
466+
'PR will need to be re-approved.\n\n'
467+
'<!-- @{} r- -->'.format(base_ref, g.my_username)
468+
)
469+
470+
state.title = info['pull_request']['title']
471+
state.body = info['pull_request']['body']
472+
473+
state.save()
474+
451475
else:
452476
lazy_debug(logger, lambda: 'Invalid pull_request action: {}'.format(action)) # noqa
453477

0 commit comments

Comments
 (0)