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

Commit 7d5d2cc

Browse files
committed
Merge pull request #51 from edunham/issue50
Warn if PR is against unexpected branch
2 parents 46e64e4 + 6e8b64d commit 7d5d2cc

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

README.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ Github hooks to provide an encouraging atmosphere for new contributors
66
Install
77
=======
88

9-
To install `highfive` you just need to execute the `setup.py` script or use `pip` directly. Both commands have to be executed from the directory where the `setup.py` script is located.
9+
To install `highfive` you just need to execute the `setup.py` script or use
10+
`pip` directly. Both commands have to be executed from the directory where the
11+
`setup.py` script is located.
1012

1113
$ python setup.py install
1214

@@ -43,8 +45,9 @@ It should look like:
4345
},
4446
"dirs":{
4547
"dirname": ["subteamname", "@anotheruser"]
46-
}
47-
"contributing": "http://project.tld/contributing_guide.html"
48+
},
49+
"contributing": "http://project.tld/contributing_guide.html",
50+
"expected_branch": "develop"
4851
}
4952
```
5053

@@ -59,5 +62,10 @@ blank.
5962
welcomes new contributors to the repository. If `contributing` is not
6063
present, the [Rust contributing.md][rustcontrib] will be linked instead.
6164

65+
If PRs should be filed against a branch other than `master`, specify the
66+
correct destination in the `expected_branch` field. If `expected_branch` is
67+
left out, highfive will assume that PRs should be filed against `master`.
68+
The bot posts a warning on any PR that targets an unexpected branch.
69+
6270
[rustcontrib]: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md
6371

highfive/newpr.py

Lines changed: 21 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,21 @@ def modifies_submodule(diff):
288290
return True
289291
return False
290292

293+
def unexpected_branch(payload, config):
294+
""" returns (expected_branch, actual_branch) if they differ, else None
295+
"""
296+
# If unspecified, assume master.
297+
expected_target = config["expected_branch"]
298+
if not expected_target:
299+
expected_target = "master"
300+
301+
# ie we want "stable" in this: "base": { "label": "rust-lang:stable"...
302+
actual_target = payload['pull_request']['base']['label'].split(':')[1]
303+
304+
if expected_target != actual_target:
305+
return (expected_target, actual_target)
306+
return False
307+
291308
def get_irc_nick(gh_name):
292309
""" returns None if the request status code is not 200,
293310
if the user does not exist on the rustacean database,
@@ -331,6 +348,10 @@ def new_pr(payload, user, token):
331348
#if modifies_unsafe(diff):
332349
# warnings += [unsafe_warning_msg]
333350

351+
surprise = unexpected_branch(payload, config)
352+
if surprise:
353+
warnings.append(surprise_branch_warning % surprise)
354+
334355
if modifies_submodule(diff):
335356
warnings.append(submodule_warning_msgs)
336357

0 commit comments

Comments
 (0)