Skip to content

Commit ce08e13

Browse files
committed
first commit
Signed-off-by: Venky Ganesh <[email protected]>
1 parent 6995200 commit ce08e13

File tree

4 files changed

+126
-0
lines changed

4 files changed

+126
-0
lines changed

.github/module-paths.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"cpp/": "Generic Runtime",
3+
"triton_backend/": "Triton Backend",
4+
"tensorrt_llm/_torch/peft/": "Lora/P-tuning",
5+
"tensorrt_llm/": "LLM API/Workflow",
6+
"benchmarks/": "Performance",
7+
"examples/disaggregated/": "Disaggregated Serving",
8+
"docs/": "Documentation",
9+
"docker/": "Installation"
10+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import argparse
2+
import json
3+
import os
4+
import subprocess
5+
from pathlib import Path
6+
7+
8+
def run_git_diff(base: str, head: str) -> list[str]:
9+
result = subprocess.run(
10+
["git", "diff", "--name-only", base, head],
11+
capture_output=True,
12+
text=True,
13+
check=True,
14+
)
15+
return [line.strip() for line in result.stdout.splitlines() if line.strip()]
16+
17+
18+
def load_json(path: str):
19+
with open(path, "r", encoding="utf-8") as f:
20+
return json.load(f)
21+
22+
23+
def map_modules(changed_files: list[str], module_paths: dict[str,
24+
str]) -> set[str]:
25+
modules: set[str] = set()
26+
for file in changed_files:
27+
for prefix, module in module_paths.items():
28+
if file.startswith(prefix):
29+
modules.add(module)
30+
break
31+
return modules
32+
33+
34+
def gather_reviewers(modules: set[str],
35+
module_owners: dict[str, list[str]],
36+
*,
37+
pr_author: str | None = None) -> list[str]:
38+
reviewers: set[str] = set()
39+
for module in modules:
40+
reviewers.update(module_owners.get(module, []))
41+
42+
if pr_author:
43+
reviewers.discard(pr_author)
44+
45+
return sorted(reviewers)
46+
47+
48+
def main() -> None:
49+
parser = argparse.ArgumentParser(
50+
description="Assign reviewers based on changed modules")
51+
parser.add_argument("--dry-run",
52+
action="store_true",
53+
help="Print the gh command instead of executing")
54+
args = parser.parse_args()
55+
56+
base_sha = os.environ["BASE_SHA"]
57+
head_sha = os.environ["HEAD_SHA"]
58+
pr_number = os.environ["PR_NUMBER"]
59+
reviewer_limit = int(os.environ.get("REVIEWER_LIMIT", "0"))
60+
pr_author = os.environ.get("PR_AUTHOR")
61+
62+
changed_files = run_git_diff(base_sha, head_sha)
63+
module_paths = load_json(Path(".github") / "module-paths.json")
64+
module_owners = load_json(Path(".github/workflows") / "module-owners.json")
65+
66+
modules = map_modules(changed_files, module_paths)
67+
reviewers = gather_reviewers(modules, module_owners, pr_author=pr_author)
68+
69+
if reviewer_limit:
70+
reviewers = reviewers[:reviewer_limit]
71+
72+
if reviewers:
73+
cmd = ["gh", "pr", "edit", pr_number]
74+
for reviewer in reviewers:
75+
cmd.extend(["--add-reviewer", reviewer])
76+
if args.dry_run:
77+
print("Dry run:", " ".join(cmd))
78+
else:
79+
subprocess.run(cmd, check=True)
80+
81+
print(f"Changed modules: {sorted(modules)}")
82+
print(f"Requested reviewers: {reviewers}")
83+
84+
85+
if __name__ == "__main__":
86+
main()
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Auto assign reviewers
2+
on:
3+
pull_request:
4+
types: [opened, synchronize, reopened]
5+
permissions:
6+
pull-requests: write
7+
jobs:
8+
assign:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
- uses: actions/setup-python@v5
13+
with:
14+
python-version: '3.12'
15+
- name: Assign reviewers
16+
env:
17+
BASE_SHA: ${{ github.event.pull_request.base.sha }}
18+
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
19+
PR_NUMBER: ${{ github.event.pull_request.number }}
20+
PR_AUTHOR: ${{ github.event.pull_request.user.login }}
21+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
22+
REVIEWER_LIMIT: '3'
23+
run: python3 .github/scripts/assign_reviewers.py

CONTRIBUTING.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,13 @@ Developer workflow for code contributions is as follows:
9393
3. Once the code changes are staged on the fork and ready for review, a [Pull Request](https://help.github.com/en/articles/about-pull-requests) (PR) can be [requested](https://help.github.com/en/articles/creating-a-pull-request) to merge the changes from a branch of the fork into a selected branch of upstream. PRs should typically target the `main` branch.
9494
* Creation of a PR creation kicks off the code review process.
9595
* At least one TensorRT-LLM engineer will be assigned for the review. When the PR is under review, the label `Pending Review` will be added to the PR.
96+
* Reviewers are automatically requested based on the modules affected in the PR. Module paths are defined in `.github/module-paths.json` and ownership in `.github/workflows/module-owners.json`.
97+
* You can test the assignment script locally with the `--dry-run` flag:
98+
```bash
99+
GH_TOKEN=<token> BASE_SHA=<base> HEAD_SHA=<head> PR_NUMBER=<pr> \
100+
PR_AUTHOR=<username> \
101+
python3 .github/scripts/assign_reviewers.py --dry-run
102+
```
96103
* If changes are requested, then the reviewer will add the label `Changes Requested` to the PR.
97104
* Once changes are approved, CI will be launched to validate the change. When CI passes, the reviewer will merge the PR.
98105
* If CI reports any failures, it's up to the requester to fix any CI failures before requesting another review.

0 commit comments

Comments
 (0)