Skip to content

Commit dae3a50

Browse files
authored
fix: retrigger CodeRabbit plan on unlock and log skip reason (hiero-ledger#2350)
Signed-off-by: Anshul Kushwaha <137977998+sudo-anshul@users.noreply.github.com>
1 parent ce16902 commit dae3a50

3 files changed

Lines changed: 57 additions & 53 deletions

File tree

.github/scripts/coderabbit_plan_trigger.js

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
// Script to trigger CodeRabbit plan for intermediate and advanced issues
1+
// Script to trigger CodeRabbit plan for all difficulty-labeled issues (including GFI)
22

33
const CODERABBIT_MARKER = '<!-- CodeRabbit Plan Trigger -->';
4-
const { DIFFICULTY_LABELS, GOOD_FIRST_ISSUE_LABEL } = require('./shared/labels.js');
4+
const { DIFFICULTY_LABELS } = require('./shared/labels.js');
55

66
async function triggerCodeRabbitPlan(github, owner, repo, issue, marker = CODERABBIT_MARKER) {
77
const comment = `${marker} @coderabbitai plan`;
@@ -27,13 +27,10 @@ async function triggerCodeRabbitPlan(github, owner, repo, issue, marker = CODERA
2727
}
2828
}
2929

30-
function hasBeginnerOrHigherLabel(issue, label) {
31-
// Only beginner+ labels qualify here; GFI gets its own CodeRabbit plan
32-
// trigger via the assignment bot chain (bot-gfi-assign-on-comment.js).
33-
const beginnerPlus = DIFFICULTY_LABELS
34-
.filter(d => d !== GOOD_FIRST_ISSUE_LABEL)
35-
.map(d => d.toLowerCase());
36-
const allowed = new Set(beginnerPlus);
30+
function hasDifficultyLabel(issue, label) {
31+
// All difficulty labels now qualify — CodeRabbit plan is delivered on
32+
// approval for every difficulty tier, including Good First Issue.
33+
const allowed = new Set(DIFFICULTY_LABELS.map(d => d.toLowerCase()));
3734

3835
const hasAllowedLabel = issue.labels?.some(l => allowed.has(l?.name?.toLowerCase()));
3936

@@ -80,6 +77,30 @@ async function hasExistingCodeRabbitPlan(github, owner, repo, issueNumber) {
8077
}
8178
}
8279

80+
async function getLatestIssue(github, owner, repo, issue) {
81+
if (!issue?.number) return issue;
82+
83+
try {
84+
const { data } = await github.rest.issues.get({
85+
owner,
86+
repo,
87+
issue_number: issue.number,
88+
});
89+
90+
return data || issue;
91+
} catch (error) {
92+
console.log('Failed to refresh issue state; falling back to event payload:', {
93+
message: error?.message,
94+
status: error?.status,
95+
owner,
96+
repo,
97+
issueNumber: issue?.number,
98+
});
99+
100+
return issue;
101+
}
102+
}
103+
83104
function logSummary(owner, repo, issue) {
84105
console.log('=== Summary ===');
85106
console.log(`Repository: ${owner}/${repo}`);
@@ -92,13 +113,21 @@ function logSummary(owner, repo, issue) {
92113
async function main({ github, context }) {
93114
try {
94115
const { owner, repo } = context.repo;
95-
const { issue, label } = context.payload;
116+
const { issue: eventIssue, label } = context.payload;
96117

97118
// Validations
98-
if (!issue?.number) return console.log('No issue in payload');
119+
if (!eventIssue?.number) return console.log('No issue in payload');
120+
121+
// Refresh issue state to avoid stale payload fields (e.g., locked status)
122+
// when this script is invoked after earlier workflow steps mutate the issue.
123+
const issue = await getLatestIssue(github, owner, repo, eventIssue);
124+
125+
if (issue.locked) {
126+
return console.log(`Issue #${issue.number} is locked. CodeRabbit plan trigger will be deferred until the issue is approved and unlocked.`);
127+
}
99128

100-
if (!hasBeginnerOrHigherLabel(issue, label)) {
101-
return console.log('Issue does not have beginner/intermediate/advanced label');
129+
if (!hasDifficultyLabel(issue, label)) {
130+
return console.log('Issue does not have a difficulty label');
102131
}
103132

104133
if (await hasExistingCodeRabbitPlan(github, owner, repo, issue.number)) {

.github/workflows/approved-issues.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ defaults:
1313

1414
permissions:
1515
issues: write
16+
contents: read
1617

1718
concurrency:
1819
group: approve-issues-${{ github.event.issue.number }}
@@ -50,3 +51,17 @@ jobs:
5051
issue-number: ${{ github.event.issue.number }}
5152
body: |
5253
Approved by @hiero-ledger/hiero-sdk-python-triage and @hiero-ledger/hiero-sdk-python-committers and @hiero-ledger/hiero-sdk-python-maintainers.
54+
55+
- name: Checkout repository
56+
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
57+
with:
58+
persist-credentials: false
59+
60+
- name: Trigger CodeRabbit Plan
61+
env:
62+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
63+
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
64+
with:
65+
script: |
66+
const script = require('./.github/scripts/coderabbit_plan_trigger.js');
67+
await script({ github, context });

.github/workflows/bot-coderabbit-plan-trigger.yml

Lines changed: 0 additions & 40 deletions
This file was deleted.

0 commit comments

Comments
 (0)