Add CodeRabbit approval handler and sync PR labels for review status#64
Add CodeRabbit approval handler and sync PR labels for review status#64kpj2006 wants to merge 3 commits intoAOSSIE-Org:mainfrom
Conversation
WalkthroughAdds a new GitHub Actions workflow that reacts to CodeRabbit approvals on PR reviews to swap labels, and augments the PR label sync workflow to assign a Changes
Sequence Diagram(s)sequenceDiagram
participant PR as Pull Request
participant GH as GitHub Actions
participant API as GitHub API
participant Bot as CodeRabbit (coderabbitai)
PR->>GH: pull_request_review (submitted)
GH->>Bot: inspect review author & state
GH->>GH: evaluate if reviewer == coderabbitai and state == approved
alt approved by CodeRabbit
GH->>API: DELETE label `pending-coderabbit-review` (ignore 404)
API-->>GH: 200 / 404 handled
GH->>API: POST label `coderabbit-approved`
API-->>GH: label added
GH-->>PR: emit summary/log
else not CodeRabbit-approved
GH-->>PR: no label changes
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
No actionable comments were generated in the recent review. 🎉 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 |
There was a problem hiding this comment.
Actionable comments posted: 4
🤖 Fix all issues with AI agents
In @.github/workflows/coderabbit-approval.yml:
- Around line 105-119: Update the "Summary" step script to avoid unconditionally
claiming labels were removed/added; instead read the prior step outputs (e.g.,
check steps.remove-pending-label.outputs.removed and
steps.add-coderabbit-label.outputs.added or whatever output names your
label-removal/label-add steps set) and conditionally log "Removed
'pending-coderabbit-review' label" only if removed==='true' and "Added
'coderabbit-approved' label" only if added==='true', otherwise log a best-effort
or attempted message; modify the console.log calls inside the Summary step
script accordingly so the messages reflect actual outcomes from those steps.
- Around line 3-5: Update the pull_request_review trigger to include the
"dismissed" type in addition to "submitted" and add a conditional job/step that
runs when github.event.action == 'dismissed' to remove the "coderabbit-approved"
label (and optionally add "pending-coderabbit-review"); specifically modify the
pull_request_review.types array and add a step that uses the existing label
handling logic (targeting the "coderabbit-approved" and
"pending-coderabbit-review" labels) to remove the approved label on dismissal
and restore the pending label if desired.
- Around line 86-103: The "Add CodeRabbit approved label" step currently calls
github.rest.issues.addLabels without error handling; wrap the await
github.rest.issues.addLabels(...) call in a try/catch, catch the error and log a
clear message including prNumber and the label name (e.g. 'coderabbit-approved')
and the error details, then surface the failure (either by rethrowing a new
Error with that message or calling core.setFailed) so the workflow fails with a
meaningful message instead of an opaque stack trace.
In @.github/workflows/sync-pr-labels.yml:
- Around line 318-333: The "Add pending CodeRabbit review label" step
unconditionally re-adds 'pending-coderabbit-review' on PR "edited" events and
lacks error handling; change the job step to run only when code-changing events
occur by adding a condition (if: github.event.action != 'edited') and wrap the
call to github.rest.issues.addLabels in a try/catch similar to the approval
workflow so failures (e.g., label missing) are caught and logged instead of
failing the run; locate the step by its name "Add pending CodeRabbit review
label" and update the script around prNumber and github.rest.issues.addLabels to
include the conditional gating and error handling/logging.
…nhance label management
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In @.github/workflows/coderabbit-approval.yml:
- Around line 12-13: The job key remove-pending-label is misleading; rename it
to a descriptive name like handle-coderabbit-review and update all references to
that job key (e.g., any "needs:" entries, workflow callers, or job status
checks) so CI still wires correctly; open the workflow YAML, change the job
identifier remove-pending-label to handle-coderabbit-review, and adjust any
usages/comments within the same file to match the new identifier to avoid
breaking dependencies.
- Around line 22-42: Extend the approval-check logic to detect the dismissed
case: add a boolean is_coderabbit_dismissed (compute as isCodeRabbit && state
=== 'dismissed'), set it via core.setOutput('is_coderabbit_dismissed',
is_coderabbit_dismissed), and return it in the step result alongside
isCodeRabbit/isApproved/shouldRemoveLabel; then add a new workflow step named
"Handle dismissed CodeRabbit review" that runs when
steps.check-approval.outputs.is_coderabbit_dismissed == 'true' and uses
actions/github-script to call github.rest.issues.removeLabel to remove
'coderabbit-approved' (ignore 404) and github.rest.issues.addLabels to add
'pending-coderabbit-review' (log errors), using
context.payload.pull_request.number (prNumber) and context.repo for owner/repo.
Addressed Issues:
Screenshots/Recordings:
Additional Notes:
Checklist
We encourage contributors to use AI tools responsibly when creating Pull Requests. While AI can be a valuable aid, it is essential to ensure that your contributions meet the task requirements, build successfully, include relevant tests, and pass all linters. Submissions that do not meet these standards may be closed without warning to maintain the quality and integrity of the project. Please take the time to understand the changes you are proposing and their impact.
Summary by CodeRabbit