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

Commit 06b789a

Browse files
committed
Merge pull request #48 from edunham/custom-contrib-guide-link
Make the welcome message contribution guide link configurable per repo
2 parents 36b6ab5 + ac35385 commit 06b789a

File tree

3 files changed

+57
-14
lines changed

3 files changed

+57
-14
lines changed

README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,38 @@ To run tests, make sure the test-requirements are installed by running:
2626
Once the dependencies are installed, you can run tests by executing:
2727

2828
$ nosetests
29+
30+
Adding a Project
31+
================
32+
33+
To make rust-highfive interact with a new repo, add a configuration file in
34+
`highfive/configs`, with a filename of the form `reponame.json`.
35+
36+
It should look like:
37+
38+
```
39+
{
40+
"groups":{
41+
"all": ["@username", "@otheruser"],
42+
"subteamname": ["@subteammember", "@username"]
43+
},
44+
"dirs":{
45+
"dirname": ["subteamname", "@anotheruser"]
46+
}
47+
"contributing": "http://project.tld/contributing_guide.html"
48+
}
49+
```
50+
51+
The `groups` section allows you to alias lists of usernames. You should
52+
specify at least one user in the group "all"; others are optional.
53+
54+
The `dirs` section is where you map directories of the repo to users or
55+
groups who're eligible to review PRs affecting it. This section can be left
56+
blank.
57+
58+
`contributing` specifies the contribution guide link in the message which
59+
welcomes new contributors to the repository. If `contributing` is not
60+
present, the [Rust contributing.md][rustcontrib] will be linked instead.
61+
62+
[rustcontrib]: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md
63+

highfive/newpr.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,28 @@
3030
3131
If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. The way Github handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.
3232
33-
Please see [CONTRIBUTING.md](https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md) for more information.
33+
Please see [the contribution instructions](%s) for more information.
3434
"""
3535

3636

37-
def welcome_msg(reviewer):
37+
def welcome_msg(reviewer, config):
3838
if reviewer is None:
3939
text = welcome_without_reviewer
4040
else:
4141
text = welcome_with_reviewer % reviewer
42-
return raw_welcome % text
42+
# Default to the Rust contribution guide if "contributing" wasn't set
43+
link = config.get('contributing')
44+
if not link:
45+
link = "https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md"
46+
return raw_welcome % (text, link)
4347

4448
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'
4549
unsafe_warning_msg = 'These commits modify **unsafe code**. Please review it carefully!'
4650
submodule_warning_msg = 'These commits modify **submodules**.'
4751

4852
review_with_reviewer = 'r? @%s\n\n(rust_highfive has picked a reviewer for you, use r? to override)'
4953
review_without_reviewer = '@%s: no appropriate reviewer found, use r? to override'
54+
5055
def review_msg(reviewer, submitter):
5156
if reviewer is None:
5257
text = review_without_reviewer % submitter
@@ -151,8 +156,7 @@ def parse_header_links(value):
151156

152157
return links
153158

154-
def is_new_contributor(username, owner, repo, user, token):
155-
config = _load_json_file(repo + '.json')
159+
def is_new_contributor(username, owner, repo, user, token, config):
156160
if 'contributors' in config and username in config['contributors']:
157161
return False
158162

@@ -179,14 +183,13 @@ def find_reviewer(commit_msg):
179183
return match.group(1)
180184

181185
# Choose a reviewer for the PR
182-
def choose_reviewer(repo, owner, diff, exclude):
186+
def choose_reviewer(repo, owner, diff, exclude, config):
183187
if not (owner == 'rust-lang' or (owner == 'nrc' and repo == 'highfive')):
184188
return 'test_user_selection_ignore_this'
185189

186190
# Get JSON data on reviewers.
187-
reviewers = _load_json_file(repo + '.json')
188-
dirs = reviewers.get('dirs', {})
189-
groups = reviewers['groups']
191+
dirs = config.get('dirs', {})
192+
groups = config['groups']
190193

191194
# fill in the default groups, ensuring that overwriting is an
192195
# error.
@@ -297,7 +300,6 @@ def get_irc_nick(gh_name):
297300
return rustacean_data[0].get("irc")
298301
return None
299302

300-
301303
def new_pr(payload, user, token):
302304
owner = payload['pull_request']['base']['repo']['owner']['login']
303305
repo = payload['pull_request']['base']['repo']['name']
@@ -309,15 +311,18 @@ def new_pr(payload, user, token):
309311
msg = payload["pull_request"]['body']
310312
reviewer = find_reviewer(msg)
311313
post_msg = False
314+
315+
config = _load_json_file(repo + '.json')
316+
312317
if not reviewer:
313318
post_msg = True
314319
diff = api_req("GET", payload["pull_request"]["diff_url"])['body']
315-
reviewer = choose_reviewer(repo, owner, diff, author)
320+
reviewer = choose_reviewer(repo, owner, diff, author, config)
316321

317322
set_assignee(reviewer, owner, repo, issue, user, token, author)
318323

319-
if is_new_contributor(author, owner, repo, user, token):
320-
post_comment(welcome_msg(reviewer), owner, repo, issue, user, token)
324+
if is_new_contributor(author, owner, repo, user, token, config):
325+
post_comment(welcome_msg(reviewer, config), owner, repo, issue, user, token)
321326
elif post_msg:
322327
post_comment(review_msg(reviewer, author), owner, repo, issue, user, token)
323328

highfive/tests/test_newpr.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@ def test_submodule(self):
1313

1414
def test_choose_reviewer(self):
1515
normal_diff = self._load_fake('normal.diff')
16+
fake_config = { "groups": {"all":["@pnkfelix", "@nrc"]},
17+
"dirs": {} }
1618
reviewer = newpr.choose_reviewer('rust',
1719
'rust-lang',
1820
normal_diff,
19-
'nikomatsakis')
21+
'nikomatsakis',
22+
fake_config)
2023
self.assertNotEqual('nikomatsakis', reviewer)

0 commit comments

Comments
 (0)