Conversation
There was a problem hiding this comment.
Pull request overview
Adds a GitHub Actions workflow intended to automatically assign reviewers to PRs based on labels and a simple load-balancing heuristic.
Changes:
- Introduces
.github/workflows/auto-assign-reviewers.ymlto select and request reviewers when PRs are opened/updated/labeled. - Implements label-based eligibility (
assign-for-review) and weighting (size-*,priority-high) to prioritize larger/higher priority PRs. - Tracks current reviewer “load” across open PRs to pick the least-loaded candidates.
Aniruddh25
left a comment
There was a problem hiding this comment.
Idea is good, but missing testing to ensure this actually works.
… Usr/sogh/prreviewbot
| script: | | ||
| const reviewers = ["souvikghosh04", "Aniruddh25", "aaronburtle", "anushakolan", "RubenCerna2079", "JerryNixon"]; | ||
| const REQUIRED_REVIEWERS = 2; | ||
| const DRY_RUN = '${{ github.event.inputs.dry_run || 'true' }}' === 'true'; |
There was a problem hiding this comment.
DRY_RUN will always evaluate to true for pull_request_target runs because github.event.inputs.dry_run is only populated for workflow_dispatch. That means reviewer requests will never actually be made on PR open/label events, which prevents the workflow from achieving automated assignment as described. Consider sourcing DRY_RUN from an env/repo variable for PR-triggered runs (or defaulting to false on PR events and only honoring the input on workflow_dispatch).
| const DRY_RUN = '${{ github.event.inputs.dry_run || 'true' }}' === 'true'; | |
| const DRY_RUN = context.eventName === "workflow_dispatch" | |
| ? '${{ github.event.inputs.dry_run || 'true' }}' === 'true' | |
| : false; |
| // Fetch the set of configured reviewers who are requested OR have already submitted a review. | ||
| // GitHub removes reviewers from requested_reviewers once they submit, so we must check both. | ||
| async function getConfiguredReviewerSet(pr) { | ||
| const requested = (pr.requested_reviewers || []) | ||
| .map((r) => r.login) | ||
| .filter((r) => reviewers.includes(r)); | ||
|
|
There was a problem hiding this comment.
This workflow still ignores requested_teams when computing existing reviewers (configuredSet) and determining needed. If a PR already has team reviewers requested, this can result in extra individual assignments and incorrect load accounting. If teams should count toward the 2-reviewer threshold, include pr.requested_teams in the reviewer-count/eligibility logic (or explicitly encode that teams are intentionally excluded).
| const { data: reviews } = await github.rest.pulls.listReviews({ | ||
| owner, | ||
| repo, | ||
| pull_number: pr.number, | ||
| }); | ||
| const submitted = reviews | ||
| .map((r) => r.user.login) | ||
| .filter((r) => reviewers.includes(r)); | ||
|
|
There was a problem hiding this comment.
pulls.listReviews is not paginated here and doesn't set per_page, so only the first page of reviews is considered (default 30). On PRs with many reviews this can miss configured reviewers who already submitted, leading to incorrect configuredSet/load and potentially re-requesting reviewers. Use github.paginate (or paginate with per_page: 100) for listReviews.
| on: | ||
| pull_request_target: | ||
| types: [opened, reopened, labeled] | ||
|
|
There was a problem hiding this comment.
The workflow triggers on every pull_request_target opened event, but then always fetches all open PRs to find ones with assign-for-review. For repos with frequent PR activity this can cause unnecessary API usage and increase the chance of hitting rate limits. Consider narrowing triggers (e.g., only labeled for assign-for-review) or adding a job-level if: to quickly exit when the event isn't workflow_dispatch and isn't the assign-for-review label being applied.
| owner, | ||
| repo, | ||
| pull_number: pr.number, | ||
| reviewers: selected, |
There was a problem hiding this comment.
Does this action add the selected reviewer to the list of assignees of the PR or in the requested review column?
Why make this change?
Automate PR reviewer assignment to distribute review workload evenly across the team instead of relying on manual assignment or CODEOWNERS (which adds all owners).
What is this change?
Adds auto-assign-reviewers.yml, a label-driven GitHub Actions workflow that assigns exactly 2 reviewers per PR using load-balanced selection.
How is this tested?