@@ -26,6 +26,44 @@ async function triggerCodeRabbitPlan(github, owner, repo, issue, marker, dryRun)
2626 }
2727}
2828
29+ function hasIntermediateOrAdvancedLabel ( issue , label ) {
30+ // Check if issue has intermediate or advanced label (case-insensitive)
31+ const hasIntermediateLabel = issue . labels ?. some ( l => l ?. name ?. toLowerCase ( ) === 'intermediate' ) ;
32+ const hasAdvancedLabel = issue . labels ?. some ( l => l ?. name ?. toLowerCase ( ) === 'advanced' ) ;
33+
34+ // Also check if the newly added label is intermediate/advanced
35+ const isNewLabelIntermediate = label ?. name ?. toLowerCase ( ) === 'intermediate' ;
36+ const isNewLabelAdvanced = label ?. name ?. toLowerCase ( ) === 'advanced' ;
37+
38+ return hasIntermediateLabel || hasAdvancedLabel || isNewLabelIntermediate || isNewLabelAdvanced ;
39+ }
40+
41+ async function hasExistingCodeRabbitPlan ( github , owner , repo , issueNumber ) {
42+ // Check for existing CodeRabbit plan comment (limited to first 500 comments)
43+ const comments = [ ] ;
44+ const iterator = github . paginate . iterator ( github . rest . issues . listComments , {
45+ owner, repo, issue_number : issueNumber , per_page : 100
46+ } ) ;
47+
48+ let count = 0 ;
49+ for await ( const { data : page } of iterator ) {
50+ comments . push ( ...page ) ;
51+ count += page . length ;
52+ if ( count >= 500 ) break ; // Hard upper bound to prevent unbounded pagination
53+ }
54+
55+ return comments . some ( c => c . body ?. includes ( '@coderabbitai plan' ) ) ;
56+ }
57+
58+ function logSummary ( owner , repo , issue , dryRun ) {
59+ console . log ( '=== Summary ===' ) ;
60+ console . log ( `Repository: ${ owner } /${ repo } ` ) ;
61+ console . log ( `Issue Number: ${ issue . number } ` ) ;
62+ console . log ( `Issue Title: ${ issue . title || '(no title)' } ` ) ;
63+ console . log ( `Labels: ${ issue . labels ?. map ( l => l . name ) . join ( ', ' ) || 'none' } ` ) ;
64+ console . log ( `Dry Run: ${ dryRun } ` ) ;
65+ }
66+
2967module . exports = async ( { github, context } ) => {
3068 try {
3169 const { owner, repo } = context . repo ;
@@ -35,44 +73,18 @@ module.exports = async ({ github, context }) => {
3573 // Validations
3674 if ( ! issue ?. number ) return console . log ( 'No issue in payload' ) ;
3775
38- // Check if issue has intermediate or advanced label (case-insensitive)
39- const hasIntermediateLabel = issue . labels ?. some ( l => l ?. name ?. toLowerCase ( ) === 'intermediate' ) ;
40- const hasAdvancedLabel = issue . labels ?. some ( l => l ?. name ?. toLowerCase ( ) === 'advanced' ) ;
41-
42- // Also check if the newly added label is intermediate/advanced
43- const isNewLabelIntermediate = label ?. name ?. toLowerCase ( ) === 'intermediate' ;
44- const isNewLabelAdvanced = label ?. name ?. toLowerCase ( ) === 'advanced' ;
45-
46- if ( ! hasIntermediateLabel && ! hasAdvancedLabel && ! isNewLabelIntermediate && ! isNewLabelAdvanced ) {
76+ if ( ! hasIntermediateOrAdvancedLabel ( issue , label ) ) {
4777 return console . log ( 'Issue does not have intermediate or advanced label' ) ;
4878 }
4979
50- // Check for existing CodeRabbit plan comment (limited to first 500 comments)
51- const comments = [ ] ;
52- const iterator = github . paginate . iterator ( github . rest . issues . listComments , {
53- owner, repo, issue_number : issue . number , per_page : 100
54- } ) ;
55-
56- let count = 0 ;
57- for await ( const { data : page } of iterator ) {
58- comments . push ( ...page ) ;
59- count += page . length ;
60- if ( count >= 500 ) break ; // Hard upper bound to prevent unbounded pagination
61- }
62-
63- if ( comments . some ( c => c . body ?. includes ( '@coderabbitai plan' ) ) ) {
80+ if ( await hasExistingCodeRabbitPlan ( github , owner , repo , issue . number ) ) {
6481 return console . log ( `CodeRabbit plan already triggered for #${ issue . number } ` ) ;
6582 }
6683
6784 // Post CodeRabbit plan trigger
6885 await triggerCodeRabbitPlan ( github , owner , repo , issue , marker , dryRun ) ;
6986
70- console . log ( '=== Summary ===' ) ;
71- console . log ( `Repository: ${ owner } /${ repo } ` ) ;
72- console . log ( `Issue Number: ${ issue . number } ` ) ;
73- console . log ( `Issue Title: ${ issue . title || '(no title)' } ` ) ;
74- console . log ( `Labels: ${ issue . labels ?. map ( l => l . name ) . join ( ', ' ) || 'none' } ` ) ;
75- console . log ( `Dry Run: ${ dryRun } ` ) ;
87+ logSummary ( owner , repo , issue , dryRun ) ;
7688 } catch ( err ) {
7789 console . log ( '❌ Error:' , err . message ) ;
7890 }
0 commit comments