Fix auto-assign reviewers (#36631)

* Fix auto-assign reviewers

* Clean up endanchor a bit

* We don't actually need the end anchor at all
This commit is contained in:
Matt
2025-03-10 15:52:13 +00:00
committed by GitHub
parent 858545047c
commit a929c466d0
2 changed files with 19 additions and 8 deletions

View File

@@ -17,10 +17,19 @@ import os
import github import github
import json import json
from github import Github from github import Github
from fnmatch import fnmatch import re
from collections import Counter from collections import Counter
from pathlib import Path from pathlib import Path
def pattern_to_regex(pattern):
start_anchor = pattern.startswith("/")
pattern = re.escape(pattern)
# Replace `*` with "any number of non-slash characters"
pattern = pattern.replace(r"\*", "[^/]*")
if start_anchor:
pattern = "^" + pattern
return pattern
def get_file_owners(file_path, codeowners_lines): def get_file_owners(file_path, codeowners_lines):
# Process lines in reverse (last matching pattern takes precedence) # Process lines in reverse (last matching pattern takes precedence)
for line in reversed(codeowners_lines): for line in reversed(codeowners_lines):
@@ -36,18 +45,20 @@ def get_file_owners(file_path, codeowners_lines):
owners = [owner.removeprefix("@") for owner in parts[1:]] owners = [owner.removeprefix("@") for owner in parts[1:]]
# Check if file matches pattern # Check if file matches pattern
if fnmatch(file_path, pattern): file_regex = pattern_to_regex(pattern)
if re.search(file_regex, file_path) is not None:
return owners # Remember, can still be empty! return owners # Remember, can still be empty!
return [] # Should never happen, but just in case return [] # Should never happen, but just in case
def main(): def main():
script_dir = Path(__file__).parent.absolute()
with open(script_dir / "codeowners_for_review_action") as f:
codeowners_lines = f.readlines()
g = Github(os.environ['GITHUB_TOKEN']) g = Github(os.environ['GITHUB_TOKEN'])
repo = g.get_repo("huggingface/transformers") repo = g.get_repo("huggingface/transformers")
with open(os.environ['GITHUB_EVENT_PATH']) as f: with open(os.environ['GITHUB_EVENT_PATH']) as f:
event = json.load(f) event = json.load(f)
script_dir = Path(__file__).parent.absolute()
with open(script_dir / "codeowners_for_review_action") as f:
codeowners_lines = f.readlines()
# The PR number is available in the event payload # The PR number is available in the event payload
pr_number = event['pull_request']['number'] pr_number = event['pull_request']['number']

View File

@@ -11,14 +11,14 @@ docs/ @stevhliu
/src/transformers/models/*/image_processing* @qubvel /src/transformers/models/*/image_processing* @qubvel
/src/transformers/models/*/image_processing_*_fast* @yonigozlan /src/transformers/models/*/image_processing_*_fast* @yonigozlan
# Owners of subsections of the library # Owners of subsections of the library
/src/transformers/generation/ @gante /src/transformers/generation/ @gante
/src/transformers/pipeline/ @Rocketknight1 @yonigozlan /src/transformers/pipeline/ @Rocketknight1 @yonigozlan
/src/transformers/integrations/ @SunMarc @MekkCyber @muellerzr /src/transformers/integrations/ @SunMarc @MekkCyber @muellerzr
/src/transformers/quantizers/ @SunMarc @MekkCyber /src/transformers/quantizers/ @SunMarc @MekkCyber
/src/transformers/tests/ @ydshieh tests/ @ydshieh
/src/transformers/tests/generation/ @gante tests/generation/ @gante
/src/transformers/models/auto/ @ArthurZucker /src/transformers/models/auto/ @ArthurZucker
/src/transformers/utils/ @ArthurZucker @Rocketknight1 /src/transformers/utils/ @ArthurZucker @Rocketknight1
/src/transformers/loss/ @ArthurZucker /src/transformers/loss/ @ArthurZucker