Skip to content
This repository was archived by the owner on Mar 14, 2023. It is now read-only.

Commit 095bbc6

Browse files
authored
Merge pull request #336 from JohnTitor/ping-without-dirs
Ping reviewers even if `dirs` key is empty
2 parents d56ba37 + 92f1d27 commit 095bbc6

File tree

4 files changed

+59
-27
lines changed

4 files changed

+59
-27
lines changed

highfive/newpr.py

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -315,39 +315,39 @@ def get_to_mention(self, diff, author):
315315
"""
316316
Get the list of people to mention.
317317
"""
318-
dirs = self.repo_config.get('dirs', {})
319318
mentions = self.repo_config.get('mentions', {})
319+
if not mentions:
320+
return []
320321

321322
to_mention = set()
322323
# If there's directories with specially assigned groups/users
323324
# inspect the diff to find the directory with the most additions
324-
if dirs:
325-
cur_dir = None
326-
for line in diff.split('\n'):
327-
if line.startswith("diff --git "):
328-
# update cur_dir
329-
cur_dir = None
330-
parts = line[line.find(" b/") + len(" b/"):].split("/")
331-
if not parts:
332-
continue
333-
cur_dir = "/".join(parts[:2])
334-
full_dir = "/".join(parts)
325+
cur_dir = None
326+
for line in diff.split('\n'):
327+
if line.startswith("diff --git "):
328+
# update cur_dir
329+
cur_dir = None
330+
parts = line[line.find(" b/") + len(" b/"):].split("/")
331+
if not parts:
332+
continue
333+
cur_dir = "/".join(parts[:2])
334+
full_dir = "/".join(parts)
335335

336-
# A few heuristics to get better reviewers
337-
if cur_dir.startswith('src/librustc'):
338-
cur_dir = 'src/librustc'
339-
if cur_dir == 'src/test':
340-
cur_dir = None
341-
if len(full_dir) > 0:
342-
for entry in mentions:
343-
# Check if this entry is a prefix
344-
eparts = entry.split("/")
345-
if (len(eparts) <= len(parts) and
346-
all(a==b for a,b in zip(parts, eparts))
347-
):
348-
to_mention.add(entry)
349-
elif entry.endswith('.rs') and full_dir.endswith(entry):
350-
to_mention.add(entry)
336+
# A few heuristics to get better reviewers
337+
if cur_dir.startswith('src/librustc'):
338+
cur_dir = 'src/librustc'
339+
if cur_dir == 'src/test':
340+
cur_dir = None
341+
if len(full_dir) > 0:
342+
for entry in mentions:
343+
# Check if this entry is a prefix
344+
eparts = entry.split("/")
345+
if (len(eparts) <= len(parts) and
346+
all(a==b for a,b in zip(parts, eparts))
347+
):
348+
to_mention.add(entry)
349+
elif entry.endswith('.rs') and full_dir.endswith(entry):
350+
to_mention.add(entry)
351351

352352
mention_list = []
353353
for mention in to_mention:

highfive/tests/fakes.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,16 @@ def get_repo_configs():
6565
"reviewers": ["@pnkfelix"],
6666
}
6767
}
68+
},
69+
'mentions_without_dirs': {
70+
"groups": {"all": ["@JohnTitor"]},
71+
"dirs": {},
72+
"mentions": {
73+
"README.md": {
74+
"message": "should be pinged",
75+
"reviewers": ["@JohnTitor"],
76+
}
77+
}
6878
}
6979
}
7080

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
diff --git a/README.md b/README.md
2+
index 5ec94e189f8..b35fbba3fcd 100644
3+
--- a/README.md
4+
+++ b/README.md
5+
@@ -1,6 +1,6 @@
6+
# The Rust Programming Language
7+
8+
-This is the main source code repository for [Rust]. It contains the compiler,
9+
+Hey! This is the main source code repository for [Rust]. It contains the compiler,
10+
standard library, and documentation.
11+
12+
[Rust]: https://www.rust-lang.org

highfive/tests/test_newpr.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,6 +1033,7 @@ def make_fakes(cls):
10331033
'normal': load_fake('normal.diff'),
10341034
'travis-yml': load_fake('travis-yml.diff'),
10351035
'mentions': load_fake('mentions.diff'),
1036+
'mentions-without-dirs': load_fake('mentions-without-dirs.diff'),
10361037
},
10371038
'config': fakes.get_repo_configs(),
10381039
'global_': fakes.get_global_configs(),
@@ -1206,6 +1207,15 @@ def test_mentions(self):
12061207
# @ehuss should not be listed here
12071208
assert set(["@pnkfelix", "@GuillaumeGomez"]) == mentions
12081209

1210+
def test_mentions_without_dirs(self):
1211+
"""Test pinging people even if the dirs key is empty."""
1212+
self.handler = HighfiveHandlerMock(
1213+
Payload({}), repo_config=self.fakes['config']['mentions_without_dirs']
1214+
).handler
1215+
(chosen_reviewers, mentions) = self.choose_reviewers(
1216+
self.fakes['diff']['mentions-without-dirs'], "@JohnTitor",
1217+
)
1218+
assert set(["@JohnTitor"]) == mentions
12091219

12101220
class TestRun(TestNewPR):
12111221
@pytest.fixture(autouse=True)

0 commit comments

Comments
 (0)