Skip to content

PR review bot#3326

Open
souvikghosh04 wants to merge 10 commits intomainfrom
Usr/sogh/prreviewbot
Open

PR review bot#3326
souvikghosh04 wants to merge 10 commits intomainfrom
Usr/sogh/prreviewbot

Conversation

@souvikghosh04
Copy link
Copy Markdown
Contributor

@souvikghosh04 souvikghosh04 commented Mar 26, 2026

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.

  • Triggers on pull_request_target events and workflow_dispatch
  • Processes non-draft PRs with the assign-for-review label
  • Weights PRs by size/priority labels for load calculation
  • Picks least-loaded reviewers, excluding the PR author
  • Only counts configured reviewers (ignores CODEOWNERS auto-assigns)
  • Supports DRY_RUN mode (default: true) for safe testing

How is this tested?

  • Manually using Github Actions as automated tests won't apply here

@souvikghosh04 souvikghosh04 self-assigned this Mar 26, 2026
@souvikghosh04 souvikghosh04 marked this pull request as ready for review March 26, 2026 17:38
Copilot AI review requested due to automatic review settings March 26, 2026 17:38
@souvikghosh04 souvikghosh04 added this to the April 2026 milestone Mar 26, 2026
@souvikghosh04 souvikghosh04 linked an issue Mar 26, 2026 that may be closed by this pull request
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.yml to 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.

@souvikghosh04 souvikghosh04 moved this from Todo to In Progress in Data API builder Mar 27, 2026
@aaronburtle aaronburtle self-assigned this Mar 28, 2026
@aaronburtle aaronburtle moved this from In Progress to Review In Progress in Data API builder Mar 28, 2026
Copy link
Copy Markdown
Collaborator

@Aniruddh25 Aniruddh25 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Idea is good, but missing testing to ensure this actually works.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 4 comments.

script: |
const reviewers = ["souvikghosh04", "Aniruddh25", "aaronburtle", "anushakolan", "RubenCerna2079", "JerryNixon"];
const REQUIRED_REVIEWERS = 2;
const DRY_RUN = '${{ github.event.inputs.dry_run || 'true' }}' === 'true';
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Suggested change
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;

Copilot uses AI. Check for mistakes.
Comment on lines +51 to +57
// 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));

Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copilot uses AI. Check for mistakes.
Comment on lines +58 to +66
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));

Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +3 to +6
on:
pull_request_target:
types: [opened, reopened, labeled]

Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
owner,
repo,
pull_number: pr.number,
reviewers: selected,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this action add the selected reviewer to the list of assignees of the PR or in the requested review column?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Review In Progress

Development

Successfully merging this pull request may close these issues.

Automated PR review assignment bot

5 participants