diff --git a/highfive/newpr.py b/highfive/newpr.py index 223570e0..606ce48e 100644 --- a/highfive/newpr.py +++ b/highfive/newpr.py @@ -34,8 +34,8 @@ review_with_reviewer = 'r? @%s\n\n(rust-highfive has picked a reviewer for you, use r? to override)' review_without_reviewer = '@%s: no appropriate reviewer found, use r? to override' -reviewer_re = re.compile("\\b[rR]\?[:\- ]*@([a-zA-Z0-9\-]+)") -submodule_re = re.compile(".*\+Subproject\scommit\s.*", re.DOTALL | re.MULTILINE) +reviewer_re = re.compile(r"\\b[rR]\?[:\- ]*@([a-zA-Z0-9\-]+)") +submodule_re = re.compile(r".*\+Subproject\scommit\s.*", re.DOTALL | re.MULTILINE) rustaceans_api_url = "http://www.ncameron.org/rustaceans/user?username={username}" @@ -105,16 +105,25 @@ def api_req(self, method, url, data=None, media_type=None): def set_assignee(self, assignee, owner, repo, issue, user, author, to_mention): try: + assignees = [] if assignee == 'ghost' else [assignee] + self.api_req( "PATCH", issue_url % (owner, repo, issue), - {"assignee": assignee} + {"assignees": assignees} )['body'] except urllib.error.HTTPError as e: if e.code == 201: pass else: print(f"failed to assign {assignee} to {owner}/{repo}#{issue}") - raise e + print(f"error was: {e}") + if assignee == 'ghost': + raise Exception('assigned ghost') + print("posting error comment") + error_msg = f":stop_sign: @{assignee} could not be assigned. " \ + "(They may not be a member of **`@rust-lang`**!) " \ + "Please assign someone else with `r? @person`." + self.post_comment(error_msg, owner, repo, issue) self.run_commands(to_mention, owner, repo, issue, user) @@ -418,8 +427,8 @@ def new_comment(self): # Check the commenter is the submitter of the PR or the previous assignee. author = self.payload['issue', 'user', 'login'] if not (author == commenter or ( - self.payload['issue', 'assignee'] \ - and commenter == self.payload['issue', 'assignee', 'login'] + self.payload['issue', 'assignees'] \ + and commenter in map(lambda user: user['login'], self.payload['issue', 'assignees']) )): # Check if commenter is a collaborator. if not self.is_collaborator(commenter, owner, repo): diff --git a/highfive/tests/test_integration_tests.py b/highfive/tests/test_integration_tests.py index 072b7418..df6d8750 100644 --- a/highfive/tests/test_integration_tests.py +++ b/highfive/tests/test_integration_tests.py @@ -88,7 +88,7 @@ def test_new_pr_non_contributor(self): ( ( 'PATCH', newpr.issue_url % ('rust-lang', 'rust', '7'), - {'assignee': 'nrc'} + {'assignees': ['nrc']} ), {'body': {}}, ), @@ -130,7 +130,7 @@ def test_new_pr_empty_body(self): ( ( 'PATCH', newpr.issue_url % ('rust-lang', 'rust', '7'), - {'assignee': 'nrc'} + {'assignees': ['nrc']} ), {'body': {}}, ), @@ -171,7 +171,7 @@ def test_new_pr_contributor(self): ( ( 'PATCH', newpr.issue_url % ('rust-lang', 'rust', '7'), - {'assignee': 'nrc'} + {'assignees': ['nrc']} ), {'body': {}}, ), @@ -215,7 +215,7 @@ def test_new_pr_contributor_with_labels(self): ( ( 'PATCH', newpr.issue_url % ('rust-lang', 'rust', '7'), - {'assignee': 'nrc'} + {'assignees': ['nrc']} ), {'body': {}}, ), @@ -266,7 +266,7 @@ def test_author_is_commenter(self): ( ( 'PATCH', newpr.issue_url % ('rust-lang', 'rust', '1'), - {'assignee': 'davidalber'} + {'assignees': ['davidalber']} ), {'body': {}}, ), @@ -293,7 +293,7 @@ def test_author_not_commenter_is_collaborator(self): ( ( 'PATCH', newpr.issue_url % ('rust-lang', 'rust', '1'), - {'assignee': 'davidalber'} + {'assignees': ['davidalber']} ), {'body': {}}, ), diff --git a/highfive/tests/test_newpr.py b/highfive/tests/test_newpr.py index cd6a892a..31ca7b4a 100644 --- a/highfive/tests/test_newpr.py +++ b/highfive/tests/test_newpr.py @@ -511,7 +511,7 @@ def assert_api_req_call(self, assignee=''): 'PATCH', 'https://api.github.com/repos/%s/%s/issues/%s' % ( self.owner, self.repo, self.issue - ), {"assignee": assignee} + ), {"assignees": [assignee]} ) def test_api_req_good(self): @@ -908,7 +908,7 @@ def make_handler( 'issue': { 'state': state, 'number': issue_number, - 'assignee': None, + 'assignees': [], 'user': { 'login': author, }, @@ -930,7 +930,7 @@ def make_handler( if is_pull_request: payload._payload['issue']['pull_request'] = {} if assignee is not None: - payload._payload['issue']['assignee'] = {'login': assignee} + payload._payload['issue']['assignees'] = [{'login': assignee}] return HighfiveHandlerMock(payload).handler