feat: add bot to automatically assign requested reviewers as assignees#2211
Conversation
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 36 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
e249026 to
84906fe
Compare
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
WalkthroughAdds a GitHub Actions bot and helpers that convert PR requested individual reviewers into assignees (ignoring teams), caps assignments to 2 users, includes unit tests covering success and error cases, and provides workflows to run the bot and tests. ChangesReviewers-to-Assignees Bot
Sequence DiagramsequenceDiagram
participant Event as GitHub Event
participant Workflow as on-review.yml
participant Bot as bot-pr-add-reviewers-as-assignees.js
participant API as GitHub REST API
Event->>Workflow: review_requested or workflow_dispatch
Workflow->>Bot: Execute handler with github + context
Bot->>API: pulls.get (fetch PR data)
API-->>Bot: PR with requested_reviewers
Bot->>Bot: Filter & deduplicate reviewers
Bot->>API: issues.addAssignees (add to PR)
API-->>Bot: Success or 403/500 error
Bot-->>Workflow: Log result or handle error
🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 📋 Issue PlannerLet us write the prompt for your AI agent so you can ship faster (with fewer bugs). View plan for ticket: ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@exploreriii , @NssGourav please review |
84906fe to
99bfe96
Compare
aceppaluni
left a comment
There was a problem hiding this comment.
Hi, @gangulysiddhartha22-cmyk , Was this tested on your fork?
There was a problem hiding this comment.
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 8dd2f3fd-cdee-4fb9-841b-a39c6231825c
📒 Files selected for processing (4)
.github/scripts/bot-pr-add-reviewers-as-assignees.js.github/scripts/test-bot-pr-add-reviewers-as-assignees.js.github/workflows/bot-pr-add-reviewers-as-assignees.yml.github/workflows/test-bot-pr-add-reviewers-as-assignees.yml
|
@aceppaluni , Yes, I tested the JS bot script locally using the dedicated test file .github/scripts/test-bot-pr-add-reviewers-as-assignees.js, which mocks the GitHub API and runs a few scenarios like covering team expansion, batching, deduplication, and error handling—all passed successfully. Do you have any specific test scenarios or fork testing suggestions you'd recommend? I'll prioritize them! |
|
Can you add a link to your testing? Thank you! |
99bfe96 to
33a06d7
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: cb174379-89e1-4082-bd67-b9e0670e997b
📒 Files selected for processing (4)
.github/scripts/bot-pr-add-reviewers-as-assignees.js.github/scripts/test-bot-pr-add-reviewers-as-assignees.js.github/workflows/bot-pr-add-reviewers-as-assignees.yml.github/workflows/test-bot-pr-add-reviewers-as-assignees.yml
fb68438 to
3bf4c38
Compare
NssGourav
left a comment
There was a problem hiding this comment.
Thanks for the implementation. I may be missing something but it looks like the current workflow skips forked PRs, and the tests still expect team expansion behavior.
Since issue #2133 asks to assign only the requested reviewers, could you please adjust the workflow and tests to match that behavior?
3bf4c38 to
b3c0f74
Compare
There was a problem hiding this comment.
♻️ Duplicate comments (1)
.github/workflows/bot-pr-add-reviewers-as-assignees.yml (1)
8-11:⚠️ Potential issue | 🟠 MajorUse
pull_request_targetfor reviewer-assignment writes, or fork PRs will silently no-op.With
pull_requeston forked PRs,GITHUB_TOKENis read-only for mutations, soissues.addAssigneesreturns a 403 error (lines 114–117). The error is silently caught and the handler exits without throwing, making the workflow appear successful while reviewers are never assigned.Switching to
pull_request_targetresolves this, as it provides a read-write token in the base-repo context for fork PRs. This script only performs metadata mutations (reading PR data and adding assignees) without executing pull-request code, so it is safe to usepull_request_target.on: - pull_request: + pull_request_target: types: - review_requestedAs per coding guidelines: "Workflows must behave safely when executed from forks."
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 56800073-908a-46a4-bc16-ccd479820a9f
📒 Files selected for processing (4)
.github/scripts/bot-pr-add-reviewers-as-assignees.js.github/scripts/test-bot-pr-add-reviewers-as-assignees.js.github/workflows/bot-pr-add-reviewers-as-assignees.yml.github/workflows/test-bot-pr-add-reviewers-as-assignees.yml
2bd969c to
ca832c2
Compare
|
Successful test run on my fork: Note about runner: Let me know if you prefer me to keep ubuntu-latest or revert it back to hl-sdk-py-lin-md. Thank you! |
ca832c2 to
97c855c
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
♻️ Duplicate comments (1)
.github/workflows/bot-pr-add-reviewers-as-assignees.yml (1)
36-36:⚠️ Potential issue | 🔴 Critical | ⚡ Quick winLine 36 uses the wrong event guard and skips all
pull_request_targetexecutions.The workflow triggers on
pull_request_target, but the job condition allows onlypull_requestandworkflow_dispatch. That makes the automated review-request path a no-op.✅ Proposed fix
- if: ${{ github.event_name == 'workflow_dispatch' || github.event_name == 'pull_request' }} + if: ${{ github.event_name == 'workflow_dispatch' || github.event_name == 'pull_request_target' }}#!/bin/bash set -euo pipefail FILE=".github/workflows/bot-pr-add-reviewers-as-assignees.yml" echo "Inspecting trigger and job guard in $FILE" rg -n 'pull_request_target|github\.event_name' "$FILE"
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 903a5b80-5767-4912-8f11-7d2b91f44064
📒 Files selected for processing (4)
.github/scripts/bot-pr-add-reviewers-as-assignees.js.github/scripts/test-bot-pr-add-reviewers-as-assignees.js.github/workflows/bot-pr-add-reviewers-as-assignees.yml.github/workflows/test-bot-pr-add-reviewers-as-assignees.yml
11b2582 to
1bbeb6d
Compare
425034b to
a53d29e
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
♻️ Duplicate comments (1)
.github/scripts/bot-pr-add-reviewers-as-assignees.js (1)
108-111: 🧹 Nitpick | 🔵 Trivial | ⚡ Quick winConsider logging when team reviewers are present but ignored.
The bot silently ignores
requested_teamswithout checking or logging. While this is documented in the fileoverview (Line 8), adding a runtime log message when teams are detected would improve operational transparency and reduce confusion when team reviews don't result in assignees.🔍 Proposed addition to improve observability
const requestedReviewers = pr.requested_reviewers || []; +const requestedTeams = pr.requested_teams || []; const currentAssignees = new Set((pr.assignees || []).map(a => a.login)); + +if (requestedTeams.length > 0) { + logger.info(`${requestedTeams.length} team reviewer(s) detected but ignored (only individual users are assigned)`); +}As per coding guidelines: "Log key decisions and early exits — avoid silent skips."
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 2f6709fc-64cd-42ea-8dc0-183cdfb7bb74
📒 Files selected for processing (7)
.github/scripts/bot-pr-add-reviewers-as-assignees.js.github/scripts/helpers/constants.js.github/scripts/helpers/index.js.github/scripts/helpers/logger.js.github/scripts/tests/test-bot-pr-add-reviewers-as-assignees.js.github/workflows/on-review.yml.github/workflows/test-on-review.yml
a53d29e to
9fe80ee
Compare
There was a problem hiding this comment.
Actionable comments posted: 3
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 38cb971d-df41-418f-8c75-8cd71f8acfb0
📒 Files selected for processing (7)
.github/scripts/bot-pr-add-reviewers-as-assignees.js.github/scripts/helpers/constants.js.github/scripts/helpers/index.js.github/scripts/helpers/logger.js.github/scripts/tests/test-bot-pr-add-reviewers-as-assignees.js.github/workflows/on-review.yml.github/workflows/test-on-review.yml
9fe80ee to
f64618a
Compare
There was a problem hiding this comment.
Actionable comments posted: 3
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 6ae33c61-6b24-4b99-bb68-aa1a6fa55a71
📒 Files selected for processing (7)
.github/scripts/bot-pr-add-reviewers-as-assignees.js.github/scripts/helpers/constants.js.github/scripts/helpers/index.js.github/scripts/helpers/logger.js.github/scripts/tests/test-bot-pr-add-reviewers-as-assignees.js.github/workflows/on-review.yml.github/workflows/test-on-review.yml
38783a2 to
0bf4c03
Compare
0bf4c03 to
735e003
Compare
exploreriii
left a comment
There was a problem hiding this comment.
Hi @gangulysiddhartha22-cmyk
Thanks for checking this
Overall, this looks pretty good but please can you use the custom runners.
Left some other ideas but i do not think they need changing or are blockers. You could also use a fresh payload.
I have questions about reviewer list never decreasing - but i think we can tackle that later.
Also you mocked the github response, is there any way you can verify the assignment permissions and double check this can actually assign users from the hiero org
aceppaluni
left a comment
There was a problem hiding this comment.
@gangulysiddhartha22-cmyk Thank you for this.
I noticed you have linked a test from you fork however upon inspection I am not seeing any indication of assignees. Can we verify this functionality?
|
Hi @exploreriii, Switched to custom runner hl-sdk-py-lin-md in both on-review.yml and test-on-review.yml Team reviewers: Currently intentionally ignored (only individual requested_reviewers are assigned). We can do a follow-up PR if we want to expand teams. Hi @aceppaluni , Here is a successful manual run of the bot using workflow_dispatch: I had to switch back to the main branch temporarily, but the code in my feature branch (add-reviewers-as-assignees) is identical to what I tested. Ready for re-review! |
Signed-off-by: Siddhartha Ganguly <gangulysiddhartha22@gmail.com>
Description:
This PR introduces a new GitHub bot that automatically adds requested reviewers (both individuals and team members) as assignees on Pull Requests.
Related issue(s):
Fixes #2133
Notes for reviewer:
Bot triggers on review_requested event and supports manual workflow_dispatch.
Checklist