Skip to content

Commit a1221c9

Browse files
committed
Allow all collaborators to change reviewer
closes servo#26
1 parent cf62818 commit a1221c9

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

newpr.py

+20-5
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
# contributor will happen early,
2121
contributors_url = "https://api.github.com/repos/%s/%s/contributors?per_page=100"
2222
post_comment_url = "https://api.github.com/repos/%s/%s/issues/%s/comments"
23+
collabo_url = "https://api.github.com/repos/%s/%s/collaborators"
2324
issue_url = "https://api.github.com/repos/%s/%s/issues/%s"
2425

2526
welcome_msg = """Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @%s (or someone else) soon.
@@ -128,6 +129,16 @@ def set_assignee(assignee, owner, repo, issue, user, token, author):
128129
.format(irc_name_of_reviewer, owner, repo, issue, author))
129130

130131

132+
def get_collaborators(owner, repo, user, token):
133+
try:
134+
result = api_req("GET", collabo_url % (owner, repo), None, user, token)['body']
135+
except urllib2.HTTPError, e:
136+
if e.code == 201:
137+
pass
138+
else:
139+
raise e
140+
return [c['login'] for c in json.loads(result)]
141+
131142
# This function is adapted from https://github.com/kennethreitz/requests/blob/209a871b638f85e2c61966f82e547377ed4260d9/requests/utils.py#L562
132143
# Licensed under Apache 2.0: http://www.apache.org/licenses/LICENSE-2.0
133144
def parse_header_links(value):
@@ -326,17 +337,21 @@ def new_comment(payload, user, token):
326337
if payload['issue']['state'] != 'open' or 'pull_request' not in payload['issue']:
327338
return
328339

329-
# Check the commenter is the submitter of the PR.
340+
owner = payload['repository']['owner']['login']
341+
repo = payload['repository']['name']
342+
343+
# Check the commenter is the submitter of the PR or the previous assignee.
330344
author = payload["issue"]['user']['login']
331-
if author != payload['comment']['user']['login']:
332-
return
345+
commenter = payload['comment']['user']['login']
346+
if not (author == commenter or (payload['issue']['assignee'] and commenter == payload['issue']['assignee']['login'])):
347+
# Get collaborators for this repo and check if the commenter is one of them
348+
if commenter not in get_collaborators(owner, repo, user, token):
349+
return
333350

334351
# Check for r? and set the assignee.
335352
msg = payload["comment"]['body']
336353
reviewer = find_reviewer(msg)
337354
if reviewer:
338-
owner = payload['repository']['owner']['login']
339-
repo = payload['repository']['name']
340355
issue = str(payload['issue']['number'])
341356
set_assignee(reviewer, owner, repo, issue, user, token, author)
342357

0 commit comments

Comments
 (0)