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
33const 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
66async 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+
83104function logSummary ( owner , repo , issue ) {
84105 console . log ( '=== Summary ===' ) ;
85106 console . log ( `Repository: ${ owner } /${ repo } ` ) ;
@@ -92,13 +113,21 @@ function logSummary(owner, repo, issue) {
92113async 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 ) ) {
0 commit comments