Skip to content

feat: clear pending review requests and reviewer-assignees - #2675

Closed
anchit-goel wants to merge 13 commits into
hiero-ledger:mainfrom
anchit-goel:feat/pending-review-pr
Closed

anchit-goel wants to merge 13 commits into
hiero-ledger:mainfrom
anchit-goel:feat/pending-review-pr

Conversation

@anchit-goel

Copy link
Copy Markdown
Contributor

Description:

Withdraw pending review requests and remove reviewer-added assignees when a pull request is converted to draft.

  • Add clearReviewStateOnDraft in .github/scripts/bot-pr-add-reviewers-as-assignees.js to withdraw pending individual/team review requests and clean up reviewer assignees (excluding the PR author).
  • Trigger clear-review-state-on-draft job in .github/workflows/on-review.yml on pull_request_target.types: [converted_to_draft].
  • Add Jest unit tests in .github/scripts/__tests__/jest/bot-pr-add-reviewers-as-assignees.test.js covering draft-clearing logic and error-handling paths.

Related issue(s):

Fixes #2542

Notes for reviewer:

  • When a PR is converted to draft, pending individual reviewers and team review requests are withdrawn via github.rest.pulls.removeRequestedReviewers.
  • Only assignees who are also in the requested reviewers set are removed; the PR author and non-reviewer assignees remain intact.
  • Workflow concurrency is isolated per PR (reviewer-assignee-draft-${{ github.event.pull_request.number }}).
  • All 272 CI script tests (15 test suites) and pytest suites pass.

Checklist

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

…rsion

Signed-off-by: anchit-goel <anchitgoel5@gmail.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

Workflow concurrency, live draft-state validation, and independent error handling need correction.

Review effort: Lite
Findings: 3 Medium severity

Open (3)
What changed in this PR

Adds cleanup of pending review requests and reviewer assignees when a pull request is converted to draft.

Changes:

  • Adds draft-state cleanup logic.
  • Triggers cleanup on converted_to_draft.
  • Adds Jest coverage for cleanup and error handling.
File Summary
.github/​workflows/​on-review.yml Adds the draft cleanup workflow job.
.github/​scripts/​bot-pr-add-reviewers-as-assignees.js Implements review-state cleanup.
.github/​scripts/​__tests__/​jest/​bot-pr-add-reviewers-as-assignees.test.js Tests cleanup behavior and error paths.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread .github/workflows/on-review.yml Resolved
@coderabbitai

coderabbitai Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Review in 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

When a pull request is converted to draft, a workflow invokes a new function. The function fetches live pull request data, withdraws pending individual and team review requests, and removes eligible individual reviewers from assignees.

Changes

Draft review cleanup

Layer / File(s) Summary
Clear pending requests and assignees
.github/scripts/bot-pr-add-reviewers-as-assignees.js, .github/scripts/__tests__/jest/bot-pr-add-reviewers-as-assignees.test.js
The exported function fetches current pull request data and skips cleanup for non-draft pull requests. It withdraws valid individual and team review requests, then removes pending individual reviewers from assignees except the author. Tests cover cleanup behavior and error handling.
Run cleanup on draft conversion
.github/workflows/on-review.yml
The workflow handles converted_to_draft events for non-bot actors. It checks out the default branch and invokes the cleanup function. Runs are serialized by pull request. The affected jobs select a runner based on the repository owner.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Severity of issue fixed: Medium

Sequence Diagram(s)

sequenceDiagram
  participant GitHubActions
  participant clearReviewStateOnDraft
  participant GitHubPullsAPI
  GitHubActions->>clearReviewStateOnDraft: Invoke for converted_to_draft
  clearReviewStateOnDraft->>GitHubPullsAPI: Fetch current pull request data
  GitHubPullsAPI-->>clearReviewStateOnDraft: Return requested reviewers, teams, and assignees
  clearReviewStateOnDraft->>GitHubPullsAPI: Remove pending reviewer and team requests
  clearReviewStateOnDraft->>GitHubPullsAPI: Remove qualifying reviewers from assignees
Loading
Merge Risk: 🟡 Moderate · up to 8f77d

Draft conversion can leave pending review requests and reviewer assignees in place. Isolate cleanup from the shared queue before merging.

Security architecture risk: 🔵 Low · up to 42181

The cleanup is limited to the affected pull request, but it can remove an assignee who was assigned independently of the reviewer bot. An API failure can also leave review requests and assignees out of sync.

Retained concerns

  • Low · security · observed: Draft cleanup removes any non-author assignee who is also a pending reviewer, including someone assigned independently before the reviewer bot would have added them.
  • Low · reliability · inferred: Reviewer withdrawal and assignee removal are not atomic. If withdrawal succeeds but assignee removal fails, later cleanup derives its removal set from the now-empty pending-reviewer list and cannot clear the remaining assignee.
Security review details

Security Blast Radius

  • inferred — An actor able to convert a PR to draft can initiate privileged changes to that PR’s review requests and assignees. The helper targets the event PR and live API data, not an arbitrary reviewer list supplied to the workflow.

Security Findings and Attack Paths

  • inferred — If an independently assigned user is also a pending reviewer, draft conversion causes the workflow to remove that assignment. The evidence does not establish an effect on required-review enforcement.

Trust Boundaries and Controls

  • observed — The privileged job requires a converted_to_draft event from a non-bot actor; the helper checks live draft state before writing. The public-API-marked get and removal methods in the changed test ranges are mocks, not additional production entrypoints.

Resilience and Maintainability Implications

  • inferred — A partial failure can leave assignment ownership out of sync with pending reviews; the initial live-draft check and per-PR job concurrency do not reconcile mutations that have already succeeded.

Hardening Proposals

  • proposed — Define whether cleanup owns only bot-added assignments; if so, retain provenance rather than inferring ownership from reviewer membership. Consider a reconciliation path for partially completed API changes.
Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: clearing pending review requests and reviewer assignees.
Description check Passed The description directly explains the draft-conversion cleanup, workflow trigger, tests, error handling, and related issue.
Linked Issues check Passed The changes satisfy the coding requirements in [#2542]. clearReviewStateOnDraft fetches the live PR, requires draft status, validates individual reviewer logins, and withdraws individual and team re…
Out of Scope Changes check Passed The workflow change, draft cleanup function, error handling, and Jest tests directly implement [#2542]. The changes do not add review-queue label handling or unrelated functional behavior.
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files. (1 skipped: 1 …
Full details: Linked Issues check

Explanation

The changes satisfy the coding requirements in [#2542]. clearReviewStateOnDraft fetches the live PR, requires draft status, validates individual reviewer logins, and withdraws individual and team requests with separate pulls.removeRequestedReviewers calls. It removes only the intersection of requested individual reviewers and current assignees, and excludes the PR author. The workflow handles converted_to_draft, skips bot actors, uses PR-number concurrency, and has no ready_for_review restoration path. The implementation tolerates 403 errors and continues cleanup after non-403 request errors, then rethrows the first non-403 error. Jest coverage covers the required cleanup, preservation, no-op, and error paths.

Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files. (1 skipped: 1 unsupported.)

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

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository: hiero-ledger/hiero-sdk-python/.coderabbit.yaml

Review profile: ASSERTIVE

Plan: Advanced

Run ID: e55f2011-385f-4aa6-8c0b-e0d440e9bea1

📥 Commits

Reviewing files that changed from the base of the PR and between d925452 and 8cec2b0.

📒 Files selected for processing (3)
  • .github/scripts/__tests__/jest/bot-pr-add-reviewers-as-assignees.test.js
  • .github/scripts/bot-pr-add-reviewers-as-assignees.js
  • .github/workflows/on-review.yml

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

…urrency group

Signed-off-by: anchit-goel <anchitgoel5@gmail.com>
@github-actions github-actions Bot added open to community review PR is open for community review and feedback queue:junior-committer PR awaiting initial quality review labels Sep 26, 2026
@github-actions github-actions Bot added approved Issue has been approved by team member skill: intermediate requires some knowledge of the codebase with some defined steps to implement or examples labels Sep 26, 2026
Signed-off-by: anchit-goel <anchitgoel5@gmail.com>
@anchit-goel
anchit-goel force-pushed the feat/pending-review-pr branch from 75eae95 to e2abb47 Compare September 26, 2026 17:17

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository: hiero-ledger/hiero-sdk-python/.coderabbit.yaml

Review profile: ASSERTIVE

Plan: Advanced

Run ID: 5215d01e-af8b-4857-98cc-28c88c9fa549

📥 Commits

Reviewing files that changed from the base of the PR and between 8cec2b0 and e2abb47.

📒 Files selected for processing (3)
  • .github/scripts/__tests__/jest/bot-pr-add-reviewers-as-assignees.test.js
  • .github/scripts/bot-pr-add-reviewers-as-assignees.js
  • .github/workflows/on-review.yml

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@anchit-goel

Copy link
Copy Markdown
Contributor Author

@danielmarv kindly review.

@danielmarv danielmarv left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @anchit-goel sorry for the late review

One change needed before approval, plus a few smaller items.

1. Checkout ref (blocking)

The new job checks out github.event.pull_request.base.sha || github.sha. Everywhere else in the repo, including the add job in this file, pull_request_target jobs pin to the default branch. base.sha is the base commit the PR was last synced against, not the current tip of main. So after merge, any PR last synced before this lands will load a script without the new export and fail with TypeError: clearReviewStateOnDraft is not a function. The || github.sha fallback is also never reached.

          ref: ${{ github.event.repository.default_branch }}

2. Error handling across the two API calls (suggestion)

Right now only a 403 from removeRequestedReviewers lets the assignee cleanup continue. Any other error, such as a 422 because a request was withdrawn between the get and the remove, throws and skips the assignee step. That leaves the PR half cleaned up. Could you record the first error, still run the assignee cleanup, and rethrow at the end? Splitting the individual and team withdrawals into separate calls would also stop a problem with one from blocking the other. It would be worth confirming on a fork that GITHUB_TOKEN can withdraw team requests at all.

…p error handling

Signed-off-by: anchit-goel <anchitgoel5@gmail.com>
@anchit-goel

Copy link
Copy Markdown
Contributor Author

Thanks @danielmarv! Both items have been addressed:

  1. Checkout ref: Pinned the checkout ref in clear-review-state-on-draft to ${{ github.event.repository.default_branch }}, aligning with the other pull_request_target jobs in the repo.
  2. Error handling & split calls:
  • Split individual (reviewers) and team (team_reviewers) withdrawals into separate removeRequestedReviewers calls so an issue with one does not block the other.
  • Updated the flow to record any non-403 errors (e.g. 422/500) as firstError rather than aborting immediately. This ensures the assignee cleanup step always runs to completion, after which firstError is rethrown so the job status accurately reflects any failure.

@MonaaEid MonaaEid left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hi @anchit-goel , I suggest testing this on your fork and sharing the links to those tests. If you need any help with the testing, feel free to reach out to me... thank you

@anchit-goel
anchit-goel marked this pull request as draft October 2, 2026 10:56
@github-actions github-actions Bot removed queue:junior-committer PR awaiting initial quality review open to community review PR is open for community review and feedback labels Oct 2, 2026
@github-actions

Copy link
Copy Markdown

Hi @anchit-goel,

This pull request has had no activity for 10 days. Are you still working on it?
To keep the PR active, you can:

  • Push a new commit.
  • Comment /working on the linked issue (not this PR).

If you're no longer working on this, please comment /unassign on the linked issue to release it for others. Otherwise, this PR may be closed due to inactivity.

Reach out on discord or join our office hours if you need assistance.

From the Python SDK Team

@MonaaEid

Copy link
Copy Markdown
Contributor

Hey @anchit-goel, do you need any help testing this?

@anchit-goel

Copy link
Copy Markdown
Contributor Author

Hi @MonaaEid,

I've tested the end-to-end draft conversion flow on my fork. Here is the link to the successful test run: https://github.com/anchit-goel/hiero-sdk-python/actions/runs/39121000217

Additionally, I updated the workflow's runs-on config so it seamlessly falls back to ubuntu-latest when running on personal forks (while continuing to use hl-sdk-py-lin-md on hiero-ledger).

@anchit-goel
anchit-goel marked this pull request as ready for review October 18, 2026 10:58
@anchit-goel
anchit-goel requested a review from MonaaEid October 18, 2026 11:00
@github-actions github-actions Bot added open to community review PR is open for community review and feedback queue:junior-committer PR awaiting initial quality review labels Oct 18, 2026
@anchit-goel
anchit-goel marked this pull request as draft October 22, 2026 08:54
@github-actions github-actions Bot removed queue:junior-committer PR awaiting initial quality review open to community review PR is open for community review and feedback labels Oct 22, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
📥 Commits

Reviewing files that changed from the base of the PR and between fd8e09e and 8f77d1a.

📒 Files selected for processing: 1
  • .github/workflows/on-review.yml

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

github.event.action == 'converted_to_draft'

concurrency:
group: reviewer-assignee-${{ github.event.pull_request.number }}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Prevent later jobs from canceling pending draft cleanup.

This group is shared with add-reviewers-as-assignees. If that job is running when draft cleanup becomes pending, a later job for the same PR can replace the pending cleanup. GitHub’s default concurrency queue retains only one pending job, even with cancel-in-progress: false. A workflow_dispatch add-reviewers job can therefore leave the draft PR’s pending review requests intact. Configure the shared group to retain queued jobs, or use another approach that cannot drop draft cleanup. (docs.github.com)

@anchit-goel
anchit-goel deleted the feat/pending-review-pr branch October 22, 2026 20:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Issue has been approved by team member 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.

feat: clear pending review requests and reviewer-assignees when a PR is converted to draft

5 participants