Skip to content

Commit a929c46

Browse files
Fix auto-assign reviewers (#36631)
* Fix auto-assign reviewers * Clean up endanchor a bit * We don't actually need the end anchor at all
1 parent 8585450 commit a929c46

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

.github/scripts/assign_reviewers.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,19 @@
1717
import github
1818
import json
1919
from github import Github
20-
from fnmatch import fnmatch
20+
import re
2121
from collections import Counter
2222
from pathlib import Path
2323

24+
def pattern_to_regex(pattern):
25+
start_anchor = pattern.startswith("/")
26+
pattern = re.escape(pattern)
27+
# Replace `*` with "any number of non-slash characters"
28+
pattern = pattern.replace(r"\*", "[^/]*")
29+
if start_anchor:
30+
pattern = "^" + pattern
31+
return pattern
32+
2433
def get_file_owners(file_path, codeowners_lines):
2534
# Process lines in reverse (last matching pattern takes precedence)
2635
for line in reversed(codeowners_lines):
@@ -36,18 +45,20 @@ def get_file_owners(file_path, codeowners_lines):
3645
owners = [owner.removeprefix("@") for owner in parts[1:]]
3746

3847
# Check if file matches pattern
39-
if fnmatch(file_path, pattern):
48+
file_regex = pattern_to_regex(pattern)
49+
if re.search(file_regex, file_path) is not None:
4050
return owners # Remember, can still be empty!
4151
return [] # Should never happen, but just in case
4252

4353
def main():
54+
script_dir = Path(__file__).parent.absolute()
55+
with open(script_dir / "codeowners_for_review_action") as f:
56+
codeowners_lines = f.readlines()
57+
4458
g = Github(os.environ['GITHUB_TOKEN'])
4559
repo = g.get_repo("huggingface/transformers")
4660
with open(os.environ['GITHUB_EVENT_PATH']) as f:
4761
event = json.load(f)
48-
script_dir = Path(__file__).parent.absolute()
49-
with open(script_dir / "codeowners_for_review_action") as f:
50-
codeowners_lines = f.readlines()
5162

5263
# The PR number is available in the event payload
5364
pr_number = event['pull_request']['number']

.github/scripts/codeowners_for_review_action

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ docs/ @stevhliu
1111
/src/transformers/models/*/image_processing* @qubvel
1212
/src/transformers/models/*/image_processing_*_fast* @yonigozlan
1313

14-
1514
# Owners of subsections of the library
1615
/src/transformers/generation/ @gante
1716
/src/transformers/pipeline/ @Rocketknight1 @yonigozlan
1817
/src/transformers/integrations/ @SunMarc @MekkCyber @muellerzr
1918
/src/transformers/quantizers/ @SunMarc @MekkCyber
20-
/src/transformers/tests/ @ydshieh
21-
/src/transformers/tests/generation/ @gante
19+
tests/ @ydshieh
20+
tests/generation/ @gante
21+
2222
/src/transformers/models/auto/ @ArthurZucker
2323
/src/transformers/utils/ @ArthurZucker @Rocketknight1
2424
/src/transformers/loss/ @ArthurZucker

0 commit comments

Comments
 (0)