Skip to content
This repository was archived by the owner on Mar 14, 2023. It is now read-only.

Commit 32a1b07

Browse files
author
edunham
committed
Warn if PR is against unexpected branch
And document it. Fixes issue #50, I think.
1 parent 46e64e4 commit 32a1b07

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ It should look like:
4343
},
4444
"dirs":{
4545
"dirname": ["subteamname", "@anotheruser"]
46-
}
47-
"contributing": "http://project.tld/contributing_guide.html"
46+
},
47+
"contributing": "http://project.tld/contributing_guide.html",
48+
"expected_branch": "develop"
4849
}
4950
```
5051

@@ -59,5 +60,10 @@ blank.
5960
welcomes new contributors to the repository. If `contributing` is not
6061
present, the [Rust contributing.md][rustcontrib] will be linked instead.
6162

63+
If PRs should be filed against a branch other than `master`, specify the
64+
correct destination in the `expected_branch` field. If `expected_branch` is
65+
left out, highfive will assume that PRs should be filed against `master` and
66+
post a warning if they're against some other branch.
67+
6268
[rustcontrib]: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md
6369

highfive/newpr.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ def welcome_msg(reviewer, config):
4848
warning_summary = '<img src="http://www.joshmatthews.net/warning.svg" alt="warning" height=20> **Warning** <img src="http://www.joshmatthews.net/warning.svg" alt="warning" height=20>\n\n%s'
4949
unsafe_warning_msg = 'These commits modify **unsafe code**. Please review it carefully!'
5050
submodule_warning_msg = 'These commits modify **submodules**.'
51+
surprise_branch_warning = "Pull requests are usually filed against the %s branch for this repo, but this one is against %s. Please double check that you specified the right target!"
52+
5153

5254
review_with_reviewer = 'r? @%s\n\n(rust_highfive has picked a reviewer for you, use r? to override)'
5355
review_without_reviewer = '@%s: no appropriate reviewer found, use r? to override'
@@ -288,6 +290,20 @@ def modifies_submodule(diff):
288290
return True
289291
return False
290292

293+
def unexpected_branch(payload, config):
294+
# Does the target branch of the PR (from payload) differ from the expected
295+
# branch in the config? If unspecified, assume master.
296+
expected_target = config["expected_branch"]
297+
if not expected_target:
298+
expected_target = "master"
299+
300+
# ie we want "stable" in this: "base": { "label": "rust-lang:stable"...
301+
actual_target = payload['pull_request']['base']['label'].split(':')[1]
302+
303+
if expected_target != actual_target:
304+
return (expected_target, actual_target)
305+
return False
306+
291307
def get_irc_nick(gh_name):
292308
""" returns None if the request status code is not 200,
293309
if the user does not exist on the rustacean database,
@@ -331,6 +347,10 @@ def new_pr(payload, user, token):
331347
#if modifies_unsafe(diff):
332348
# warnings += [unsafe_warning_msg]
333349

350+
surprise = unexpected_branch(payload, config)
351+
if surprise:
352+
warnings.append(surprise_branch_warning % surprise)
353+
334354
if modifies_submodule(diff):
335355
warnings.append(submodule_warning_msgs)
336356

0 commit comments

Comments
 (0)