-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[Github] Action to Auto-assign PR Reviewers (that respects CODEOWNERS.md and overrides) #5630
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
aa6184e to
0cc40e7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
picked up these module-owners mappings from this internal google sheet
| # Get team reviewers | ||
| team_result = subprocess.run( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For team reviewers, it would probably be helpful to randomly assign one reviewer in the team. That may also help automate the round-robin-style review balancing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i believe the CODEOWNERS already does this tyler, my action does not deal with the github teams (although the same information is present in module-owners.json)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so: GitHub assigns the whole team as a reviewer when the team is in the CODEOWNERS list, and then GitHub optionally sends a email notification to the whole team when the team is assigned as a reviewer. I'm not aware of any built-in mechanism to send a notification to a single person in that team.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it might even be appropriate to replace each team reviewer with a single person in the team. The CODEOWNERS requirement would still allow any member of the team to approve.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can leave that as a future improvement if you'd prefer, I'll approve this MR for now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I didn't realize this setting existed; I suppose each team can decide how they want to balance their own reviews this way. The built-in teams probably would be sufficient instead of this action if we were able to mix required and not-required CODEOWNERS.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but imagine a scenario where the CODEOWNERS has very specific module mappings, each with a team/individual. If a PR touches multiple of these, then all these teams will get tagged as required codeowner approvals. It is possible that some module-mappings are so specific that its probably just 1-2 people. And they will effectivley block the approval and merge of the PR.
If the person that's randomly selected by the CODEOWNER routing algorithm happens to be OOTO, then i believe it will block the merge too as the PR author won't have the ability to remove such a person.
but the github action can alleviate that.
It does seem like a trade-off between getting specific module-owner mappings vs not imposing too many codeowner-approvals. Ideally a "coarse" CODEOWNERS and a "fine" github action would be the balance right?
the above assumes that the CODEOWNERS-enabled assignments are rigid (and hence blocking).
What do you think @tburt-nv ? also tagging @juney-nvidia @zeroepoch @kevinch-nv @atrifex @hlu1 @MartinMarciniszyn
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the person that's randomly selected by the CODEOWNER routing algorithm happens to be OOTO, then i believe it will block the merge too as the PR author won't have the ability to remove such a person.
Other members of the team in that case can still be manually assigned to the PR after the fact and their approval would unblock the PR.
It comes down to what the goals are for enforcing reviews and approvals.
- If the goal is that module owners must explicitly approve every PR that touches their module, then using CODEOWNERs is the better solution since Github has built-in options requiring their approval, and we can guarantee the right individual or team is auto-assigned per PR.
- If module owner approval is optional, then it makes sense to have this system in place to auto-assign a few reviewers for visibility on changes, as IIRC no default reviewers are assigned if the code changes are outside the limited modules covered in CODEOWNERs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I thought I had already resolved this thread. I'm personally ok with the flexibility of maintaining both the required CODEOWNERs with native GitHub features and the optional module-owners.json with this script. I only wish GitHub supported both natively.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @kevinch-nv / @tburt-nv .
@kevinch-nv , with regards to the 2 goals you detailed above, i believe we should lean towards (1) over (2).
So that means the module-owners must explicitly approve every PR (atleast 1 of them) that touches their module. This can potentially blow up the required approvals (like in this PR you mentioned), but that's okay/necessary.
BUT if, for any reason, none of the module owners of specific CODEOWNERS rule/mapping are available for approval, we'll need an unblocking mechanism.
And I believe that is an override-approval by an administrator. I think that's okay, because the likelihood that none of the owners inside a team is available is very low, and in such a case we anyway should not ignore it.
I should also correct my original comment - the auto-routing done per-team, when the team is pulled by the CODEOWNERS for a particular change, does respect OOTO/Busy statuses (here).
so, if the following things are done properly, CODEOWNERS + team settings are alone enough:
- CODEOWNERS is fleshed out carefully, with the module-mappings in the right heirarchical order: This means more-specific paths come below less-specific ones. (
/tensorrt_llm/_torch/, followed by/tensorrt_llm/_torch/models/followed by/tensorrt_llm/_torch/models/modeling_qwen3.py) - Appropriate granularity of github teams need to be created, by expanding existing teams. For example,
@NVIDIA/trt-llm-torch-devsmaps to/tensorrt_llm/_torch, but we need another@NVIDIA/trt-llm-torch-custom-ops-devscreated as child team to@NVIDIA/trt-llm-torch-devs. This means for the/tensorrt_llm/_torch/custom_opsfiles,@NVIDIA/trt-llm-torch-devsneed not be spammed. - To avoid notifying all of the members of the coarser github teams (like
@NVIDIA/trt-llm-torch-devs, ~23 members), we need to enable auto-routing and notifying only 1-2 people from that team (in a load-balanced way). - In mappings where one needs to notify an individual, but not necessarily be blocked by that person, one should include both the teams + individuals to take advantage of notifying reviewers in a specific + randomized way:
/tensorrt_llm/_torch/modules/fused_moe.py @hlu1 @dongxuy04 @zongfeijing @HuiGao-NV @NVIDIA/trt-llm-torch-devs
I have another draft PR #5977 that expands CODEOWNERS, but basically takes care of the ordering and heirarchy, but maintains the same coverage as @kevinch-nv 's reverted #4105 . I think that should be a good starting point.
0cc40e7 to
63339cd
Compare
|
/bot run |
|
PR_Github #10878 [ run ] triggered by Bot |
|
PR_Github #10878 [ run ] completed with state |
87c4ea9 to
c0e3ec0
Compare
|
/bot run |
|
PR_Github #11161 [ run ] triggered by Bot |
|
PR_Github #11161 [ run ] completed with state |
.github/scripts/assign_reviewers.py
Outdated
|
|
||
| # Get modules and reviewers for module-mapped files | ||
| modules = get_modules_from_files(module_files, module_paths) | ||
| reviewers, modules_without_owners = get_reviewers_for_modules( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From my understanding of this code, all the reviewers for all the modules are placed in a set and randomly chosen.
If that's the case, it's possible that the final chosen reviewers do not span all the modules, thus leading to potential missed coverage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yea that is correct, it is a risk because choosing a reviwer randomly per-module can be done but might exceed reviewer_limit if the modules touched are arbitrarily high - and that will anyways cause missed coverage.
i guess instead of having a coarse reviewer_limit, we can have a per-module reviewer_limit (maybe 2?) so we ensure module coverage and yet stick to an upper bound.
i can include that in this PR too, does the above make sense @kevinch-nv ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are just review assignments that doesn't block merge right? In that case can we make sure that at least one person from each module is assigned?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
have resolved this in the latest push. now we have a per_module_reviewer_limit and ensures module coverage (that accounts for overlapping module-owners and overlapping modules)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
have verified it works with this comment
c0e3ec0 to
2597ad5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces a GitHub Action and supporting scripts to automatically assign PR reviewers based on module ownership, while respecting CODEOWNERS and manual overrides.
- Adds
assign_reviewers.pyscript with module-paths and module-owners JSON mappings - Defines a
auto-assign-reviewers.ymlworkflow with dry-run and force-assign options - Updates documentation and adds end-to-end tests covering various assignment scenarios
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| CONTRIBUTING.md | New section describing the auto-assignment feature |
| .github/module-paths.json | New mapping of repository paths to logical modules |
| .github/module-owners.json | New mapping of modules to owner lists |
| .github/workflows/module-owners.json | Extended list of module owners for CI workflows |
| .github/workflows/auto-assign-reviewers.yml | Workflow definition for automatic reviewer assignment |
| .github/scripts/assign_reviewers.py | Script to detect changed files, map modules, and assign reviewers |
| .github/scripts/tests/test_assign_reviewers.py | Comprehensive tests for assign_reviewers.py |
Comments suppressed due to low confidence (2)
.github/workflows/auto-assign-reviewers.yml:6
- The workflow_dispatch inputs block does not include an input for
pr_author, but the script relies onPR_AUTHOR. Consider adding apr_authorinput or usinggithub.actorto populate the PR author in manual dispatch.
inputs:
CONTRIBUTING.md:108
- The docs mention
REVIEWER_LIMITbut the code and workflow usePER_MODULE_REVIEWER_LIMIT. Update the documentation to reference the correct environment variable name.
* **Limits reviewer count**: Randomly samples up to 3 reviewers if more are eligible (configurable via `REVIEWER_LIMIT`)
|
|
||
| # Log if there were multiple matches (for debugging) | ||
| if len(matches) > 1: | ||
| matches[0][1] |
Copilot
AI
Jul 8, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This standalone expression is a no-op and appears to be leftover debugging code. It can be removed to improve readability.
| matches[0][1] |
|
/bot run |
|
PR_Github #11359 [ run ] triggered by Bot |
|
PR_Github #11359 [ run ] completed with state |
poweiw
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
| # Get team reviewers | ||
| team_result = subprocess.run( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can leave that as a future improvement if you'd prefer, I'll approve this MR for now
- Add logic to check existing reviewers before assignment - Skip auto-assignment if reviewers already exist (unless --force-assign) - Improve logging and error handling with status messages - Add force-assign option for manual override - Switch back to pull_request trigger for proper access - Fix workflow parameter handling for force_assign option Signed-off-by: Venky Ganesh <[email protected]>
Add comprehensive documentation about the GitHub action for automatic PR reviewer assignment, including its behavior with CODEOWNERS, module-based assignment, and existing reviewer respect. Signed-off-by: Venky Ganesh <[email protected]>
Signed-off-by: Venky Ganesh <[email protected]>
- Replace broad 'CI/CD' with 5 granular modules - Separate test concerns from pipeline logic - Move module-owners.json to .github/ for consistency Signed-off-by: Venky Ganesh <[email protected]>
…s and modules - Modified map_modules() to return both modules and unmapped files - Enhanced gather_reviewers() to track modules without owners - Added comprehensive feedback when no reviewers are assigned: - Warns about files with no module mapping - Warns about modules with no owners - Explains specific reasons for no assignment - Provides actionable guidance for fixing coverage gaps - Updated test cases to cover new functionality - Added test cases for unmapped files and modules without owners Signed-off-by: Venky Ganesh <[email protected]>
Signed-off-by: Venky Ganesh <[email protected]>
Signed-off-by: Venky Ganesh <[email protected]>
2597ad5 to
bb53b5b
Compare
|
closing this as auto-assignment has been taken care of by CODEOWNERS itself. |
PER_MODULE_REVIEWER_LIMITfor each module touched by the PR.