Skip to content

feat: add bot to automatically assign requested reviewers as assignees#2211

Open
gangulysiddhartha22-cmyk wants to merge 1 commit into
hiero-ledger:mainfrom
gangulysiddhartha22-cmyk:add-reviewers-as-assignees
Open

feat: add bot to automatically assign requested reviewers as assignees#2211
gangulysiddhartha22-cmyk wants to merge 1 commit into
hiero-ledger:mainfrom
gangulysiddhartha22-cmyk:add-reviewers-as-assignees

Conversation

@gangulysiddhartha22-cmyk
Copy link
Copy Markdown
Contributor

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

  • Documented (Code comments, README, etc.)
  • Tested (unit, integration, etc.)

@codacy-production
Copy link
Copy Markdown

codacy-production Bot commented Apr 29, 2026

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 36 complexity

Metric Results
Complexity 36

View in Codacy

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.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 29, 2026

Review Change Stack

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

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

Changes

Reviewers-to-Assignees Bot

Layer / File(s) Summary
Helper Modules
.github/scripts/helpers/constants.js, .github/scripts/helpers/logger.js, .github/scripts/helpers/index.js
Exports MAX_ASSIGNEES: 2, BOT_NAME_ASSIGNEES, and createLogger(botName) plus a re-export index.
Bot helper functions
.github/scripts/bot-pr-add-reviewers-as-assignees.js
Adds resolvePrNumber(context), getUsersToAssign(requestedReviewers, currentAssignees), and logAssigneeCapWarning(usersToAssign) to validate PR target and compute filtered/deduplicated candidate assignees.
Bot handler implementation
.github/scripts/bot-pr-add-reviewers-as-assignees.js
Exports async handler that fetches the PR, computes final assignees capped to MAX_ASSIGNEES, no-ops when nothing new, calls issues.addAssignees once, logs outcomes, returns early on 403, and rethrows other errors.
Test infrastructure & mocks
.github/scripts/tests/test-bot-pr-add-reviewers-as-assignees.js
Per-test isolated state, mock GitHub Actions context, mocked Octokit-like client and error mock factory for exercising success and failure paths.
Test cases & runner
.github/scripts/tests/test-bot-pr-add-reviewers-as-assignees.js
11 sequential tests covering reviewer assignment, team exclusion, full/partial dedupe, MAX_ASSIGNEES enforcement, workflow_dispatch pr_number handling, empty/invalid inputs, and 403/500 error behavior; includes a runner that exits non-zero on failure.
Production & test workflows
.github/workflows/on-review.yml, .github/workflows/test-on-review.yml
on-review.yml: triggers on pull_request_target review_requested and workflow_dispatch, runs bot with minimal permissions; test-on-review.yml: runs unit tests on relevant PRs or manually, sets up Node.js 24.

Sequence Diagram

sequenceDiagram
  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
Loading

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding a bot to automatically assign requested reviewers as assignees.
Description check ✅ Passed The description is related to the changeset, explaining the bot's purpose, trigger behavior, and noting it is tested and references the linked issue.
Linked Issues check ✅ Passed The PR meets all core requirements from #2133: provides a workflow and script to add individual CODEOWNERS reviewers as assignees, triggers on review_requested events with appropriate permissions, handles team expansion while assigning only users, follows repo patterns, includes comprehensive unit/integration tests, and handles edge cases.
Out of Scope Changes check ✅ Passed All changes are directly related to the linked issue objectives: bot implementation, helper modules, workflow definitions, and comprehensive tests. No out-of-scope changes detected.
Docstring Coverage ✅ Passed Docstring coverage is 96.77% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

📋 Issue Planner

Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).

View plan for ticket: #2133

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gangulysiddhartha22-cmyk
Copy link
Copy Markdown
Contributor Author

@exploreriii , @NssGourav please review

@exploreriii exploreriii added reviewer: junior committer request review from junior committers with triage permissions step: 1st 1st stage of the review approval process labels Apr 29, 2026
Copy link
Copy Markdown
Contributor

@aceppaluni aceppaluni left a comment

Choose a reason for hiding this comment

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

Hi, @gangulysiddhartha22-cmyk , Was this tested on your fork?

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between ce4713d and 99bfe96.

📒 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

Comment thread .github/scripts/bot-pr-add-reviewers-as-assignees.js Outdated
Comment thread .github/scripts/test-bot-pr-add-reviewers-as-assignees.js Outdated
@gangulysiddhartha22-cmyk
Copy link
Copy Markdown
Contributor Author

@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!

@aceppaluni
Copy link
Copy Markdown
Contributor

@gangulysiddhartha22-cmyk

Can you add a link to your testing?
We ask this as part of the review to ensure the bot is working smoothly.

Thank you!

@aceppaluni aceppaluni added the skill: intermediate requires some knowledge of the codebase with some defined steps to implement or examples label Apr 30, 2026
@gangulysiddhartha22-cmyk gangulysiddhartha22-cmyk force-pushed the add-reviewers-as-assignees branch from 99bfe96 to 33a06d7 Compare May 1, 2026 00:37
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between 99bfe96 and 33a06d7.

📒 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

Comment thread .github/scripts/test-bot-pr-add-reviewers-as-assignees.js Outdated
Comment thread .github/scripts/test-bot-pr-add-reviewers-as-assignees.js Outdated
@gangulysiddhartha22-cmyk gangulysiddhartha22-cmyk force-pushed the add-reviewers-as-assignees branch 2 times, most recently from fb68438 to 3bf4c38 Compare May 1, 2026 01:36
Copy link
Copy Markdown
Contributor

@NssGourav NssGourav left a comment

Choose a reason for hiding this comment

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

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?

Comment thread .github/workflows/bot-pr-add-reviewers-as-assignees.yml Outdated
@gangulysiddhartha22-cmyk gangulysiddhartha22-cmyk force-pushed the add-reviewers-as-assignees branch from 3bf4c38 to b3c0f74 Compare May 1, 2026 07:01
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

♻️ Duplicate comments (1)
.github/workflows/bot-pr-add-reviewers-as-assignees.yml (1)

8-11: ⚠️ Potential issue | 🟠 Major

Use pull_request_target for reviewer-assignment writes, or fork PRs will silently no-op.

With pull_request on forked PRs, GITHUB_TOKEN is read-only for mutations, so issues.addAssignees returns 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_target resolves 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 use pull_request_target.

 on:
-  pull_request:
+  pull_request_target:
     types:
       - review_requested

As 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

📥 Commits

Reviewing files that changed from the base of the PR and between 33a06d7 and b3c0f74.

📒 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

@gangulysiddhartha22-cmyk gangulysiddhartha22-cmyk force-pushed the add-reviewers-as-assignees branch 2 times, most recently from 2bd969c to ca832c2 Compare May 1, 2026 07:26
@gangulysiddhartha22-cmyk
Copy link
Copy Markdown
Contributor Author

@aceppaluni ,

Successful test run on my fork:
https://github.com/gangulysiddhartha22-cmyk/hiero-sdk-python/actions/runs/25205899886
The tests are passing cleanly with ubuntu-latest.

Note about runner:
When I change runs-on to hl-sdk-py-lin-md, the job gets queued on my fork (expected, since the custom runner label only exists in the main repository). All tests run successfully with the custom runner in the main repo environment and also passed in my local setup.

Let me know if you prefer me to keep ubuntu-latest or revert it back to hl-sdk-py-lin-md.

Thank you!

@gangulysiddhartha22-cmyk gangulysiddhartha22-cmyk force-pushed the add-reviewers-as-assignees branch from ca832c2 to 97c855c Compare May 1, 2026 14:19
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (1)
.github/workflows/bot-pr-add-reviewers-as-assignees.yml (1)

36-36: ⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

Line 36 uses the wrong event guard and skips all pull_request_target executions.

The workflow triggers on pull_request_target, but the job condition allows only pull_request and workflow_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

📥 Commits

Reviewing files that changed from the base of the PR and between b3c0f74 and 97c855c.

📒 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

Comment thread .github/scripts/test/test-bot-pr-add-reviewers-as-assignees.js Outdated
@gangulysiddhartha22-cmyk gangulysiddhartha22-cmyk force-pushed the add-reviewers-as-assignees branch 2 times, most recently from 11b2582 to 1bbeb6d Compare May 2, 2026 13:41
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (1)
.github/scripts/bot-pr-add-reviewers-as-assignees.js (1)

108-111: 🧹 Nitpick | 🔵 Trivial | ⚡ Quick win

Consider logging when team reviewers are present but ignored.

The bot silently ignores requested_teams without 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

📥 Commits

Reviewing files that changed from the base of the PR and between ff82311 and a53d29e.

📒 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

Comment thread .github/scripts/tests/test-bot-pr-add-reviewers-as-assignees.js
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between a53d29e and 9fe80ee.

📒 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

Comment thread .github/scripts/tests/test-bot-pr-add-reviewers-as-assignees.js
Comment thread .github/workflows/on-review.yml
Comment thread .github/workflows/test-on-review.yml Outdated
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9fe80ee and f64618a.

📒 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

Comment thread .github/scripts/bot-pr-add-reviewers-as-assignees.js Outdated
Comment thread .github/scripts/tests/test-bot-pr-add-reviewers-as-assignees.js
Comment thread .github/scripts/tests/test-bot-pr-add-reviewers-as-assignees.js Outdated
@aceppaluni aceppaluni added step: 1st 1st stage of the review approval process status: Needs Developer Revision Author needs to apply suggested changes/improvements labels May 13, 2026
@gangulysiddhartha22-cmyk gangulysiddhartha22-cmyk force-pushed the add-reviewers-as-assignees branch 3 times, most recently from 38783a2 to 0bf4c03 Compare May 14, 2026 08:56
@aceppaluni aceppaluni added step: 2nd second stage of the review approval process and removed status: Needs Developer Revision Author needs to apply suggested changes/improvements labels May 14, 2026
aceppaluni
aceppaluni previously approved these changes May 14, 2026
@aceppaluni aceppaluni added the reviewer: maintainer PR needs a review from the maintainer team label May 14, 2026
@github-actions github-actions Bot added queue:maintainers PR awaiting maintainer final review and removed queue:junior-committer PR awaiting initial quality review labels May 14, 2026
Comment thread .github/workflows/on-review.yml
@exploreriii exploreriii removed reviewer: maintainer PR needs a review from the maintainer team step: 1st 1st stage of the review approval process labels May 14, 2026
@exploreriii exploreriii marked this pull request as draft May 14, 2026 16:53
@exploreriii exploreriii added notes: extra care requires extra attention to detail or requirements and removed step: 2nd second stage of the review approval process labels May 14, 2026
Copy link
Copy Markdown
Contributor

@exploreriii exploreriii left a comment

Choose a reason for hiding this comment

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

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

Comment thread .github/scripts/bot-pr-add-reviewers-as-assignees.js Outdated
Comment thread .github/scripts/bot-pr-add-reviewers-as-assignees.js Outdated
Comment thread .github/scripts/bot-pr-add-reviewers-as-assignees.js
Comment thread .github/workflows/on-review.yml Outdated
Comment thread .github/workflows/on-review.yml
Comment thread .github/workflows/test-on-review.yml Outdated
Comment thread .github/scripts/helpers/logger.js
Copy link
Copy Markdown
Contributor

@aceppaluni aceppaluni left a comment

Choose a reason for hiding this comment

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

@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?

@gangulysiddhartha22-cmyk
Copy link
Copy Markdown
Contributor Author

Hi @exploreriii,

Switched to custom runner hl-sdk-py-lin-md in both on-review.yml and test-on-review.yml
Improved resolvePrNumber() to remove duplicated logic
Made currentAssignees creation more readable
Enhanced JSDoc in logger.js with proper return type
Updated all tests to use completely fresh payloads (createMockContext) for better isolation
Added clarifying comments about team reviewer handling

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:
→ Workflow Run: https://github.com/gangulysiddhartha22-cmyk/hiero-sdk-python/actions/runs/26235346367/job/77206849324

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lang: javascript Uses Javascript programming language open to community review PR is open for community review and feedback queue:junior-committer PR awaiting initial quality review reviewer: committer request review help from a committer reviewer: maintainer PR needs a review from the maintainer team scope: CI/CD involves continuous integration or delivery skill: intermediate requires some knowledge of the codebase with some defined steps to implement or examples

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create workflow that assigns reviewers

5 participants