From 60b211b4cc60b54512d1cfbf940129e7f7163fe6 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Sun, 2 Aug 2020 20:51:05 -0400 Subject: [PATCH 1/2] Use sets instead of rewriting the logic --- highfive/newpr.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/highfive/newpr.py b/highfive/newpr.py index fbd289af..b8781cd6 100644 --- a/highfive/newpr.py +++ b/highfive/newpr.py @@ -317,7 +317,7 @@ def get_to_mention(self, diff): 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,11 +339,10 @@ 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: From 7f29f7c64e1e72e3c7c17fe4e8bb2327fa19277e Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Sun, 2 Aug 2020 20:59:20 -0400 Subject: [PATCH 2/2] Don't ping the author of the PR --- highfive/newpr.py | 8 +++++--- highfive/tests/test_newpr.py | 10 +++++----- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/highfive/newpr.py b/highfive/newpr.py index b8781cd6..8c592dcc 100644 --- a/highfive/newpr.py +++ b/highfive/newpr.py @@ -310,7 +310,7 @@ 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. """ @@ -346,7 +346,9 @@ def get_to_mention(self, diff): 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): @@ -377,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