@@ -84,22 +84,30 @@ async function main() {
8484
8585 console . log ( `Found milestone: ${ nextReleaseMilestone . title } (ID: ${ nextReleaseMilestone . number } )` ) ;
8686
87- // Get all closed issues
87+ // Get all closed issues using search API, filtered to last 45 days
8888 console . log ( 'Fetching closed issues...' ) ;
89- const issues = await octokit . rest . issues . listForRepo ( {
90- owner,
91- repo,
92- state : 'closed' ,
93- per_page : 100
89+ const cutoffDate = new Date ( ) ;
90+ cutoffDate . setDate ( cutoffDate . getDate ( ) - 45 ) ;
91+ const cutoffISO = cutoffDate . toISOString ( ) . split ( 'T' ) [ 0 ] ;
92+
93+ const query = `repo:${ owner } /${ repo } is:issue is:closed reason:completed closed:>=${ cutoffISO } ` ;
94+
95+ const issuesResponse = await octokit . rest . search . issuesAndPullRequests ( {
96+ q : query ,
97+ per_page : 100 ,
98+ sort : 'updated' ,
99+ order : 'desc' ,
94100 } ) ;
101+ const issues = issuesResponse . data . items ;
95102
96- console . log ( `Found ${ issues . data . length } closed issues` ) ;
103+ console . log ( `Found ${ issues . length } closed issues` ) ;
97104
98105 let processedCount = 0 ;
99106 let assignedCount = 0 ;
107+ const assignedIssueNumbers = [ ] ;
100108
101109 // Process each issue
102- for ( const issue of issues . data ) {
110+ for ( const issue of issues ) {
103111 // Skip pull requests (they appear in issues API but have pull_request property)
104112 if ( issue . pull_request ) {
105113 continue ;
@@ -121,16 +129,17 @@ async function main() {
121129 issue_number : issue . number
122130 } ) ;
123131
124- const wasMergedToMain = timelineEvents . data . some ( event => {
125- return event . event === 'closed' &&
126- event . commit_id &&
127- event . source &&
128- event . source . issue &&
129- event . source . issue . pull_request &&
130- event . source . issue . pull_request . merged_at ;
132+ // Debug log: print all timeline events for this issue
133+ console . log ( `Timeline events for issue #${ issue . number } :` ) ;
134+ timelineEvents . data . forEach ( event => {
135+ console . log ( `- event: ${ event . event } , actor: ${ event . actor ?. login || 'N/A' } , commit_id: ${ event . commit_id || 'N/A' } , source type: ${ event . source ?. issue ?. pull_request ? 'PR' : 'Other' } ` ) ;
131136 } ) ;
132137
133- if ( wasMergedToMain ) {
138+ const wasClosedByMergedPR = timelineEvents . data . some ( event =>
139+ event . event === 'closed'
140+ ) ;
141+
142+ if ( wasClosedByMergedPR ) {
134143 console . log ( `${ isDryRun ? '[DRY RUN] Would assign' : 'Assigning' } milestone to issue #${ issue . number } : ${ issue . title } ` ) ;
135144
136145 if ( ! isDryRun ) {
@@ -144,15 +153,17 @@ async function main() {
144153
145154 console . log ( `✅ Successfully assigned milestone to issue #${ issue . number } ` ) ;
146155 assignedCount ++ ;
156+ assignedIssueNumbers . push ( issue . number ) ;
147157 } catch ( error ) {
148158 console . error ( `❌ Failed to assign milestone to issue #${ issue . number } :` , error . message ) ;
149159 }
150160 } else {
151161 console . log ( `[DRY RUN] Skipped actual assignment for issue #${ issue . number } ` ) ;
152162 assignedCount ++ ;
163+ assignedIssueNumbers . push ( issue . number ) ;
153164 }
154165 } else {
155- console . log ( `Issue #${ issue . number } was not merged to main , skipping` ) ;
166+ console . log ( `Issue #${ issue . number } was not detected as closed , skipping` ) ;
156167 }
157168 }
158169
@@ -161,6 +172,10 @@ async function main() {
161172 console . log ( `- ${ isDryRun ? 'Would assign' : 'Assigned' } milestone to ${ assignedCount } issues` ) ;
162173 console . log ( `${ isDryRun ? '[DRY RUN] Test complete!' : '✅ Milestone assignment complete!' } ` ) ;
163174
175+ if ( assignedIssueNumbers . length > 0 ) {
176+ console . log ( `\nIssues ${ isDryRun ? 'to be' : '' } assigned milestone: ${ assignedIssueNumbers . join ( ', ' ) } ` ) ;
177+ }
178+
164179 } catch ( error ) {
165180 console . error ( '❌ Script failed:' , error . message ) ;
166181 process . exit ( 1 ) ;
0 commit comments