tree: 2bfb414fcec1304e1c6e22ab525b2fad24349599 [search]
  1. shared/
  2. test/
  3. .gitignore
  4. Commands.md
  5. findPrsNeedingAttention.ts
  6. gatherMetrics.ts
  7. package-lock.json
  8. package.json
  9. processNewPrs.ts
  10. processPrUpdate.ts
  11. README.md
  12. tsconfig.json
  13. updateReviewers.ts
scripts/ci/pr-bot/README.md

PR Bot

This directory holds all the code (except for Actions Workflows) for our PR bot designed to improve the PR experience. For a list of commands to use when interacting with the bot, see Commands.md. For a design doc explaining the design and implementation, see Automate Reviewer Assignment

PR Bot Logic

The bot consists of three core workflows and a persistent state tracking system:

1. New PR Processing (processNewPrs.ts)

  • Runs periodically on a schedule (every 30 minutes).
  • Checks eligible open PRs (skips WIP, drafts, closed, PRs < 20 minutes old, PRs with notifications silenced, or PRs labeled awaiting triage).
  • Once CI checks pass, assigns reviewers based on configured label mappings in .github/REVIEWERS.yml (prioritizing least-recently-assigned reviewers).
  • If a non-committer reviewer approves, automatically assigns a committer for final review and merge.
  • Sets Next Action: Reviewers label.

2. PR Updates & Commands (processPrUpdate.ts)

  • Triggered on PR pushes (synchronize), draft transitions (converted_to_draft, ready_for_review), and comments (issue_comment: created).
  • Shifts attention to author (Next Action: Author) when a PR is marked as draft (converted_to_draft) and back to reviewers (Next Action: Reviewers) when taken out of draft (ready_for_review) or when the author pushes new commits or posts comments on a non-draft PR.
  • When a PR is marked ready_for_review and has no reviewers assigned yet, immediately assigns reviewers if it already has matching reviewer labels and passing CI checks.
  • Removes slow-review label upon receiving a comment from a non-author reviewer.
  • Processes commands like assign to next reviewer, waiting on author, stop reviewer notifications, assign set of reviewers, and remind me after tests pass.

3. Reviewer Reminders & Stale PRs (findPrsNeedingAttention.ts)

  • Runs daily to identify PRs needing action (skipping draft PRs, PRs with notifications silenced, or PRs labeled awaiting triage).
  • Flags PRs awaiting reviewer response as slow-review if inactive for ≥ 7 days (or ≥ 2 weekdays without comments).
  • If still no response after 2 more weekdays, reassigns to new reviewers, removes slow-review, and adds reassigned-reviewers.
  • Stale PR Cutoff: If a PR has both reassigned-reviewers and Next Action: Reviewers labels and review started > 60 days ago, it stops reviewer assignment loops and adds awaiting triage. PRs labeled awaiting triage are skipped.
  • Stale State Cleanup: Cleans up the oldest 100 state files for PRs that are no longer open to incrementally prune closed PR metadata from the state branch.

4. Persistent State (PersistentState)

  • Stores PR review progress and label assignment rotations on the pr-bot-state Git branch under state/pr-state/pr-<number>.json and state/reviewers-for-label-<label>.json.

Build/Test

To build, run:

npm install
npm run build

To run the tests:

npm test

Before checking in code, run prettier on it:

npm run format