diff --git a/highfive/newpr.py b/highfive/newpr.py index fbd289af..8c592dcc 100644 --- a/highfive/newpr.py +++ b/highfive/newpr.py @@ -310,14 +310,14 @@ def choose_reviewer(self, repo, owner, diff, exclude): # no eligible reviewer found return None - def get_to_mention(self, diff): + def get_to_mention(self, diff, author): """ Get the list of people to mention. """ dirs = self.repo_config.get('dirs', {}) mentions = self.repo_config.get('mentions', {}) - to_mention = [] + to_mention = set() # If there's directories with specially assigned groups/users # inspect the diff to find the directory with the most additions if dirs: @@ -339,15 +339,16 @@ def get_to_mention(self, diff): cur_dir = None if len(full_dir) > 0: for entry in mentions: - if full_dir.startswith(entry) and entry not in to_mention: - to_mention.append(entry) - elif (entry.endswith('.rs') and full_dir.endswith(entry) - and entry not in to_mention): - to_mention.append(entry) + if full_dir.startswith(entry): + to_mention.add(entry) + elif entry.endswith('.rs') and full_dir.endswith(entry): + to_mention.add(entry) mention_list = [] for mention in to_mention: - mention_list.append(mentions[mention]) + entry = mentions[mention] + if entry["reviewers"] != author: + mention_list.append(entry) return mention_list def add_labels(self, owner, repo, issue): @@ -378,7 +379,7 @@ def new_pr(self): reviewer = self.choose_reviewer( repo, owner, diff, author ) - to_mention = self.get_to_mention(diff) + to_mention = self.get_to_mention(diff, author) self.set_assignee( reviewer, owner, repo, issue, self.integration_user, diff --git a/highfive/tests/test_newpr.py b/highfive/tests/test_newpr.py index adfc0769..3076d4b4 100644 --- a/highfive/tests/test_newpr.py +++ b/highfive/tests/test_newpr.py @@ -817,7 +817,7 @@ def test_msg_reviewer_repeat_contributor(self): self.assert_set_assignee_branch_calls('foundReviewer', ['to']) self.mocks['choose_reviewer'].assert_not_called() - self.mocks['get_to_mention'].assert_called_once_with('diff') + self.mocks['get_to_mention'].assert_called_once_with('diff', 'prAuthor') self.mocks['welcome_msg'].assert_not_called() self.mocks['review_msg'].assert_not_called() self.mocks['post_comment'].assert_not_called() @@ -1037,13 +1037,13 @@ def make_fakes(cls): 'global_': fakes.get_global_configs(), } - def get_to_mention(self, diff, global_=None): - return self.get_to_mention_inner(diff, global_) + def get_to_mention(self, diff, author, global_=None): + return self.get_to_mention_inner(diff, author, global_) @mock.patch('highfive.newpr.HighfiveHandler._load_json_file') - def get_to_mention_inner(self, diff, global_, mock_load_json): + def get_to_mention_inner(self, diff, author, global_, mock_load_json): mock_load_json.return_value = deepcopy(global_ or {"groups": {}}) - return self.handler.get_to_mention(diff) + return self.handler.get_to_mention(diff, author) def choose_reviewer( self, repo, owner, diff, exclude, global_=None