Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
105 commits
Select commit Hold shift + click to select a range
e17ab98
First draft of github action on PR opening for auto-assigning reviewers
Rocketknight1 Jan 22, 2025
4333c61
fix missing import
Rocketknight1 Jan 22, 2025
e96ba83
Don't reassign reviewers if we already have them
Rocketknight1 Jan 22, 2025
ef3df76
Temporarily comment out the opened line so we can test the script
Rocketknight1 Jan 22, 2025
6b0f5b9
Correct path for codeowners file
Rocketknight1 Jan 22, 2025
8dc0846
Update workflow permissions
Rocketknight1 Jan 22, 2025
3d6105a
Update workflow permissions
Rocketknight1 Jan 22, 2025
27d2961
Update debug logs
Rocketknight1 Jan 22, 2025
adad028
Strip inline comments
Rocketknight1 Jan 22, 2025
8b20315
Remove prefix
Rocketknight1 Jan 22, 2025
580aa71
Request reviews instead of assigning
Rocketknight1 Jan 22, 2025
3a12f71
Request reviews instead of assigning
Rocketknight1 Jan 22, 2025
016ae27
Add TODO
Rocketknight1 Jan 23, 2025
f124ec0
Use pull-request-target instead
Rocketknight1 Jan 24, 2025
feafbe0
Update the script
Rocketknight1 Jan 24, 2025
fdaacaa
Set back to pull_request for testing
Rocketknight1 Jan 24, 2025
5a2ff5d
Set to pull_request_target, testing works!
Rocketknight1 Jan 24, 2025
68786cf
Merge pull request #2 from ydshieh/auto-assign-reviewers
ydshieh Feb 5, 2025
4071ed6
Update assign_reviewers.py
ydshieh Feb 5, 2025
3fc87be
Update assign_reviewers.py
ydshieh Feb 5, 2025
d6539bf
pipeline
ydshieh Feb 18, 2025
ec0b8ac
pipeline
ydshieh Feb 18, 2025
4606b90
pipeline
ydshieh Feb 18, 2025
982052d
pipeline
ydshieh Feb 18, 2025
278096b
pipeline
ydshieh Feb 18, 2025
fe59b15
pipeline
ydshieh Feb 18, 2025
0342142
pipeline
ydshieh Feb 18, 2025
ea62fae
pipeline
ydshieh Feb 18, 2025
e2f27fa
pipeline
ydshieh Feb 18, 2025
2af65fb
pipeline
ydshieh Feb 18, 2025
1b579f1
pipeline
ydshieh Feb 18, 2025
94dcd3d
pipeline
ydshieh Feb 18, 2025
81bd486
pipeline
ydshieh Feb 18, 2025
5b4d375
pipeline
ydshieh Feb 18, 2025
ae0b494
pipeline
ydshieh Feb 18, 2025
513e4f6
pipeline
ydshieh Feb 18, 2025
a4d611d
pipeline
ydshieh Feb 18, 2025
2bdc502
pipeline
ydshieh Feb 18, 2025
f9babea
pipeline
ydshieh Feb 18, 2025
783fa54
pipeline
ydshieh Feb 18, 2025
2cb406c
pipeline
ydshieh Feb 18, 2025
1e90765
pipeline
ydshieh Feb 18, 2025
8f665e2
pipeline
ydshieh Feb 18, 2025
52cf0a6
pipeline
ydshieh Feb 18, 2025
4ad6eaf
pipeline
ydshieh Feb 18, 2025
a7cae84
pipeline
ydshieh Feb 18, 2025
e91d852
pipeline
ydshieh Feb 18, 2025
abd233e
pipeline
ydshieh Feb 18, 2025
1e52c3f
pipeline
ydshieh Feb 18, 2025
28a9f78
pipeline
ydshieh Feb 18, 2025
d4bb8f3
pipeline
ydshieh Feb 18, 2025
8160cf8
pipeline
ydshieh Feb 18, 2025
f146875
pipeline
ydshieh Feb 18, 2025
aa01282
pipeline
ydshieh Feb 18, 2025
91fcb63
pipeline
ydshieh Feb 18, 2025
77abfbc
pipeline
ydshieh Feb 18, 2025
22a474c
pipeline
ydshieh Feb 19, 2025
58e25d8
pipeline
ydshieh Feb 19, 2025
16f7622
pipeline
ydshieh Feb 19, 2025
f795d01
pipeline
ydshieh Feb 19, 2025
21899e6
pipeline
ydshieh Feb 19, 2025
9397c8e
pipeline
ydshieh Feb 19, 2025
edeb703
pipeline
ydshieh Feb 19, 2025
4ae2277
pipeline
ydshieh Feb 19, 2025
e884144
pipeline
ydshieh Feb 19, 2025
ddd9e74
pipeline
ydshieh Feb 19, 2025
c2731f1
pipeline
ydshieh Feb 19, 2025
26ce4b5
pipeline
ydshieh Feb 19, 2025
99e0ea5
pipeline
ydshieh Feb 19, 2025
6cbc1d9
pipeline
ydshieh Feb 19, 2025
70d83f0
pipeline
ydshieh Feb 19, 2025
e087acf
pipeline
ydshieh Feb 19, 2025
507a5fc
pipeline
ydshieh Feb 19, 2025
139d237
pipeline
ydshieh Feb 19, 2025
6d4b9b0
pipeline
ydshieh Feb 19, 2025
d2b3650
pipeline
ydshieh Feb 19, 2025
a59280a
pipeline
ydshieh Feb 19, 2025
a06e3eb
pipeline
ydshieh Feb 19, 2025
b93d7eb
pipeline
ydshieh Feb 19, 2025
d99c069
pipeline
ydshieh Feb 19, 2025
051dc70
pipeline
ydshieh Feb 19, 2025
d740a95
pipeline
ydshieh Feb 19, 2025
155bf29
pipeline
ydshieh Feb 19, 2025
86da894
pipeline
ydshieh Feb 19, 2025
0307379
pipeline
ydshieh Feb 19, 2025
ad34ed4
pipeline
ydshieh Feb 19, 2025
ad9bb62
pipeline
ydshieh Feb 19, 2025
789c834
pipeline
ydshieh Feb 19, 2025
b7288b9
pipeline
ydshieh Feb 19, 2025
d0abad6
pipeline
ydshieh Feb 19, 2025
b4b05e3
pipeline
ydshieh Feb 19, 2025
617d0ba
pipeline
ydshieh Feb 19, 2025
26e8df6
pipeline
ydshieh Feb 19, 2025
ae73c64
pipeline
ydshieh Feb 19, 2025
f39e138
pipeline
ydshieh Feb 19, 2025
6491b9d
pipeline
ydshieh Feb 19, 2025
36e19e8
pipeline
ydshieh Feb 20, 2025
46e030d
pipeline
ydshieh Feb 20, 2025
6037fed
pipeline
ydshieh Feb 20, 2025
c088f89
pipeline
ydshieh Feb 20, 2025
c2ee191
pipeline
ydshieh Feb 20, 2025
0a53f3b
pipeline
ydshieh Feb 20, 2025
13f60f9
pipeline
ydshieh Feb 20, 2025
cdd63a4
pipeline
ydshieh Feb 20, 2025
2aa003d
pipeline
ydshieh Feb 20, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
steps:
- group: ":lock_with_ink_pen: Security Audits"
key: "group"
steps:
# - trigger: "ydshieh-transformers-2"
- label: "Generate"
# plugins:
# - docker#v5.12.0:
# image: "python:3.10-slim"
# always-pull: true
commands:
- "python3 -c \"print('I am good boy')\""
- 'tail -100 config.yml'
- 'tail -100 config.yml | buildkite-agent pipeline upload'
# - 'echo " - command: \"echo 5\"" | buildkite-agent pipeline upload'
key: generate
- label: "Build 1"
# plugins:
# - docker#v5.12.0:
# image: "python:3.10-slim"
# always-pull: true
commands:
- "echo 3"
- "echo 2"
- "mkdir logs"
- "echo 1 > logs/log.txt"
- "ls -l"
- "ls -l logs"
- "ls -l logs/log.txt"
# - "sleep 5"
artifact_paths:
- "logs/log.txt"
# - "conda init"
# - "conda activate py39"
# - "echo 4"
# - "conda deactivate"
# - "echo 6"
# - "echo 7"
key: build-1
# - label: "Build 2"
# # plugins:
# # - docker#v5.12.0:
# # image: "python:3.10-slim"
# # always-pull: true
# commands:
# - "echo 1"
# - "echo 2"
# - "echo 3"
# - "sleep 5"
# # - "conda init"
# # - "conda activate py39"
# # - "echo 4"
# # - "conda deactivate"
# # - "echo 6"
# # - "echo 7"
# key: build-2
# - label: "Build 3"
# # plugins:
# # - docker#v5.12.0:
# # image: "python:3.10-slim"
# # always-pull: true
# commands:
# - "echo 1"
# - "echo 2"
# - "echo 3"
# - "sleep 5"
# # - "conda init"
# # - "conda activate py39"
# # - "echo 4"
# # - "conda deactivate"
# # - "echo 6"
# # - "echo 7"
# key: build-3
- group: ":lock_with_ink_pen: Good boy!"
key: "group-2"
steps:
- label: "Build 1"
commands:
- "echo 3"
- "echo 2"
79 changes: 79 additions & 0 deletions .github/scripts/assign_reviewers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import os
import github
import json
from github import Github
from fnmatch import fnmatch
from collections import Counter
from pathlib import Path

def get_file_owners(file_path, codeowners_lines):
# Process lines in reverse (last matching pattern takes precedence)
for line in reversed(codeowners_lines):
# Skip comments and empty lines, strip inline comments
line = line.split('#')[0].strip()
if not line:
continue

# Split into pattern and owners
parts = line.split()
pattern = parts[0]
owners = parts[1:] # Can be empty, e.g. for dummy files with explicitly no owner!

# Check if file matches pattern
if fnmatch(file_path, pattern):
return owners # Remember, can still be empty!
return [] # Should never happen, but just in case

def main():
g = Github(os.environ['GITHUB_TOKEN'])
repo = g.get_repo("ydshieh/transformers")
os.system("git branch")
os.system("git log -n 1")
with open(os.environ['GITHUB_EVENT_PATH']) as 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
pr_number = event['pull_request']['number']
pr = repo.get_pull(pr_number)
os.system("git branch")
os.system("git log -n 1")
pr_author = pr.user.login

existing_reviews = list(pr.get_reviews())
if existing_reviews:
print(f"Already has reviews: {[r.user.login for r in existing_reviews]}")
return

users_requested, teams_requested = pr.get_review_requests()
os.system("git branch")
os.system("git log -n 1")
users_requested = list(users_requested)
if users_requested:
print(f"Reviewers already requested: {users_requested}")
return

locs_per_owner = Counter()
for file in pr.get_files():
os.system("git branch")
os.system("git log -n 1")
owners = get_file_owners(file.filename, codeowners_lines)
for owner in owners:
locs_per_owner[owner] += file.changes

# Assign the top 2 based on locs changed as reviewers
top_owners = locs_per_owner.most_common(3)
print("Top owners", top_owners)
top_owners = [owner[0].removeprefix("@") for owner in top_owners]
top_owners = [owner for owner in top_owners if owner != pr_author][:2] # Max 2, and never ping the author
try:
pr.create_review_request(top_owners)
except github.GithubException as e:
print(f"Failed to request review for {top_owners}: {e}")



if __name__ == "__main__":
main()
Loading