|
20 | 20 | # contributor will happen early,
|
21 | 21 | contributors_url = "https://api.github.com/repos/%s/%s/contributors?per_page=100"
|
22 | 22 | post_comment_url = "https://api.github.com/repos/%s/%s/issues/%s/comments"
|
| 23 | +collabo_url = "https://api.github.com/repos/%s/%s/collaborators" |
23 | 24 | issue_url = "https://api.github.com/repos/%s/%s/issues/%s"
|
24 | 25 |
|
25 | 26 | 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):
|
128 | 129 | .format(irc_name_of_reviewer, owner, repo, issue, author))
|
129 | 130 |
|
130 | 131 |
|
| 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 | + |
131 | 142 | # This function is adapted from https://github.com/kennethreitz/requests/blob/209a871b638f85e2c61966f82e547377ed4260d9/requests/utils.py#L562
|
132 | 143 | # Licensed under Apache 2.0: http://www.apache.org/licenses/LICENSE-2.0
|
133 | 144 | def parse_header_links(value):
|
@@ -326,17 +337,21 @@ def new_comment(payload, user, token):
|
326 | 337 | if payload['issue']['state'] != 'open' or 'pull_request' not in payload['issue']:
|
327 | 338 | return
|
328 | 339 |
|
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. |
330 | 344 | 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 |
333 | 350 |
|
334 | 351 | # Check for r? and set the assignee.
|
335 | 352 | msg = payload["comment"]['body']
|
336 | 353 | reviewer = find_reviewer(msg)
|
337 | 354 | if reviewer:
|
338 |
| - owner = payload['repository']['owner']['login'] |
339 |
| - repo = payload['repository']['name'] |
340 | 355 | issue = str(payload['issue']['number'])
|
341 | 356 | set_assignee(reviewer, owner, repo, issue, user, token, author)
|
342 | 357 |
|
|
0 commit comments