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

Commit fc28df1

Browse files
Adjust reviewer selection to work on unprefixed group selection
Previously, `r? compiler-team` or `r? pnkfelix` would not be matched by the regexes, which meant that they'd be silently ignored. `r? rust-lang/compiler-team` already worked, though. Note that if a user and team name overlap, then `r? @foo` will always map to foo the user, while `r? foo` will map to the team. Since we generally don't want the `@` prefix on team-wide pings, since it subscribes a bunch of people for no reason, it's nice to avoid necessarily typing the prefix as well. Users in practice do invoke the command in that way.
1 parent 601816f commit fc28df1

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

highfive/newpr.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@
3333
review_with_reviewer = 'r? @%s\n\n(rust-highfive has picked a reviewer for you, use r? to override)'
3434
review_without_reviewer = '@%s: no appropriate reviewer found, use r? to override'
3535

36-
reviewer_re = re.compile(r"\b[rR]\?[:\- ]*@([a-zA-Z0-9\-]+)")
37-
reviewer_group_re = re.compile(r"\b[rR]\?[:\- ]*@?(?:([a-zA-Z0-9\-]+)/)([a-zA-Z0-9\-]+)")
36+
reviewer_re = re.compile(r"\b[rR]\?[:\- ]*(?:@?([a-zA-Z0-9\-]+)/)?(@?[a-zA-Z0-9\-]+)")
3837
submodule_re = re.compile(r".*\+Subproject\scommit\s.*", re.DOTALL | re.MULTILINE)
3938
target_re = re.compile("^[+-]{3} [ab]/compiler/rustc_target/src/spec/", re.MULTILINE)
4039

@@ -232,7 +231,7 @@ def is_new_contributor(self, username, owner, repo):
232231
raise e
233232

234233
def get_groups(self):
235-
groups = deepcopy(self.repo_config['groups'])
234+
groups = deepcopy(self.repo_config['groups'] if 'groups' in self.repo_config else {})
236235

237236
# fill in the default groups, ensuring that overwriting is an
238237
# error.
@@ -249,16 +248,18 @@ def find_reviewer(self, msg, exclude):
249248
None.
250249
"""
251250
if msg is not None:
252-
match = reviewer_group_re.search(msg)
251+
match = reviewer_re.search(msg)
253252
if match:
254253
groups = self.get_groups()
255254
potential = groups.get(match.group(2)) or groups.get("%s/%s" % (match.group(1), match.group(2))) or []
256-
potential.extend(groups["all"])
257-
return self.pick_reviewer(groups, potential, exclude)
258-
259-
match = reviewer_re.search(msg)
260-
if match:
261-
return match.group(1)
255+
if 'all' in groups:
256+
potential.extend(groups["all"])
257+
picked = self.pick_reviewer(groups, potential, exclude)
258+
if picked:
259+
return picked
260+
if match.group(1) is None and match.group(2):
261+
if match.group(2).startswith('@'):
262+
return match.group(2)[1:]
262263

263264

264265
def choose_reviewer(self, repo, owner, diff, exclude):

highfive/tests/fakes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def get_repo_configs():
8686
}
8787
},
8888
'teams': {
89-
"groups": {"all": [], "a": ["@pnkfelix"], "b/c": ["@nrc"]}
89+
"groups": {"all": [], "a": ["@pnkfelix"], "d": ["@e"], "compiler-team": ["@niko"], "b/c": ["@nrc"]}
9090
}
9191
}
9292

highfive/tests/test_newpr.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,8 @@ def test_find_reviewer(self):
348348
# https://github.com/rust-lang-nursery/highfive/issues/184
349349
None,
350350
)
351-
handler = HighfiveHandlerMock(Payload({})).handler
351+
config = {}
352+
handler = HighfiveHandlerMock(Payload({}), repo_config=config).handler
352353

353354
for (msg, reviewer) in found_cases:
354355
assert handler.find_reviewer(msg, None) == reviewer, \
@@ -1280,8 +1281,15 @@ def test_with_team_ping(self):
12801281
found_cases = (
12811282
("r? @foo/a", "pnkfelix"),
12821283
("r? foo/a", "pnkfelix"),
1284+
("r? rust-lang/compiler-team", "niko"),
1285+
("r? compiler-team", "niko"),
12831286
("r? @b/c", "nrc"),
12841287
("r? b/c", "nrc"),
1288+
1289+
# @d goes to the user
1290+
("r? @d", "d"),
1291+
# d goes to the team
1292+
("r? d", "e"),
12851293
)
12861294

12871295
not_found_cases = (

0 commit comments

Comments
 (0)