-
Notifications
You must be signed in to change notification settings - Fork 144
feat: automate CodeRabbit plan for intermediate/advanced issues (#1289) #1332
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
exploreriii
merged 5 commits into
hiero-ledger:main
from
Mounil2005:feature/coderabbit-plan-for-intermediate-issues
Jan 6, 2026
+128
−0
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8b42a93
feat: automate CodeRabbit plan for intermediate/advanced issues (#1289)
Mounil2005 cebe684
fix: add concurrency control to CodeRabbit plan trigger
Mounil2005 3cf1332
fix: add pagination limit to prevent unbounded comment fetching
Mounil2005 45e84ab
fix: reduce cyclomatic complexity by extracting helper functions
Mounil2005 4d60a6b
fix: remove dry-run logic as it doesn't work for automatic triggers
Mounil2005 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| // Script to trigger CodeRabbit plan for intermediate and advanced issues | ||
|
|
||
| const marker = '<!-- CodeRabbit Plan Trigger -->'; | ||
Mounil2005 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| async function triggerCodeRabbitPlan(github, owner, repo, issue, marker) { | ||
| const comment = `${marker} @coderabbitai plan`; | ||
|
|
||
| try { | ||
| await github.rest.issues.createComment({ | ||
| owner, | ||
| repo, | ||
| issue_number: issue.number, | ||
| body: comment, | ||
| }); | ||
| console.log(`Triggered CodeRabbit plan for issue #${issue.number}`); | ||
| return true; | ||
| } catch (commentErr) { | ||
| console.log(`Failed to trigger CodeRabbit plan for issue #${issue.number}:`, commentErr.message || commentErr); | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| function hasIntermediateOrAdvancedLabel(issue, label) { | ||
| // Check if issue has intermediate or advanced label (case-insensitive) | ||
| const hasIntermediateLabel = issue.labels?.some(l => l?.name?.toLowerCase() === 'intermediate'); | ||
| const hasAdvancedLabel = issue.labels?.some(l => l?.name?.toLowerCase() === 'advanced'); | ||
|
|
||
| // Also check if newly added label is intermediate/advanced | ||
| const isNewLabelIntermediate = label?.name?.toLowerCase() === 'intermediate'; | ||
| const isNewLabelAdvanced = label?.name?.toLowerCase() === 'advanced'; | ||
|
|
||
| return hasIntermediateLabel || hasAdvancedLabel || isNewLabelIntermediate || isNewLabelAdvanced; | ||
| } | ||
|
|
||
| async function hasExistingCodeRabbitPlan(github, owner, repo, issueNumber) { | ||
| // Check for existing CodeRabbit plan comment (limited to first 500 comments) | ||
| const comments = []; | ||
| const iterator = github.paginate.iterator(github.rest.issues.listComments, { | ||
| owner, repo, issue_number: issueNumber, per_page: 100 | ||
| }); | ||
|
|
||
| let count = 0; | ||
| for await (const { data: page } of iterator) { | ||
| comments.push(...page); | ||
| count += page.length; | ||
| if (count >= 500) break; // Hard upper bound to prevent unbounded pagination | ||
| } | ||
|
|
||
| return comments.some(c => c.body?.includes('@coderabbitai plan')); | ||
| } | ||
|
|
||
| function logSummary(owner, repo, issue) { | ||
| console.log('=== Summary ==='); | ||
| console.log(`Repository: ${owner}/${repo}`); | ||
| console.log(`Issue Number: ${issue.number}`); | ||
| console.log(`Issue Title: ${issue.title || '(no title)'}`); | ||
| console.log(`Labels: ${issue.labels?.map(l => l.name).join(', ') || 'none'}`); | ||
| } | ||
|
|
||
| module.exports = async ({ github, context }) => { | ||
| try { | ||
| const { owner, repo } = context.repo; | ||
| const { issue, label } = context.payload; | ||
|
|
||
| // Validations | ||
| if (!issue?.number) return console.log('No issue in payload'); | ||
|
|
||
| if (!hasIntermediateOrAdvancedLabel(issue, label)) { | ||
| return console.log('Issue does not have intermediate or advanced label'); | ||
| } | ||
|
|
||
| if (await hasExistingCodeRabbitPlan(github, owner, repo, issue.number)) { | ||
| return console.log(`CodeRabbit plan already triggered for #${issue.number}`); | ||
| } | ||
|
|
||
| // Post CodeRabbit plan trigger | ||
| await triggerCodeRabbitPlan(github, owner, repo, issue, marker); | ||
|
|
||
| logSummary(owner, repo, issue); | ||
| } catch (err) { | ||
| console.log('❌ Error:', err.message); | ||
| } | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| # This workflow automatically triggers CodeRabbit's plan feature for intermediate and advanced issues. | ||
| name: CodeRabbit Plan Trigger | ||
| on: | ||
| issues: | ||
| types: [opened, labeled] | ||
Mounil2005 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| permissions: | ||
| issues: write | ||
| contents: read | ||
|
|
||
| jobs: | ||
| coderabbit_plan_trigger: | ||
| runs-on: ubuntu-latest | ||
| concurrency: | ||
| group: coderabbit-plan-${{ github.event.issue.number }} | ||
| cancel-in-progress: false | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # Only run for issues labeled with 'intermediate' or 'advanced' (case-insensitive) | ||
| if: > | ||
| (github.event_name == 'issues' && ( | ||
| contains(github.event.issue.labels.*.name, 'intermediate') || | ||
| contains(github.event.issue.labels.*.name, 'advanced') || | ||
| contains(github.event.issue.labels.*.name, 'Intermediate') || | ||
| contains(github.event.issue.labels.*.name, 'Advanced') || | ||
| (github.event.label && (github.event.label.name == 'intermediate' || github.event.label.name == 'advanced' || github.event.label.name == 'Intermediate' || github.event.label.name == 'Advanced')) | ||
exploreriii marked this conversation as resolved.
Show resolved
Hide resolved
exploreriii marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| )) | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| steps: | ||
| - name: Harden the runner | ||
| uses: step-security/harden-runner@20cf305ff2072d973412fa9b1e3a4f227bda3c76 # v2.14.0 | ||
| with: | ||
| egress-policy: audit | ||
|
|
||
| - name: Checkout repository | ||
| uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 #v6.0.1 | ||
|
|
||
| - name: Trigger CodeRabbit Plan | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
Mounil2005 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd #v8.0.0 | ||
| with: | ||
| script: | | ||
| const script = require('./.github/scripts/coderabbit_plan_trigger.js'); | ||
| await script({ github, context}); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.