@@ -139,9 +139,10 @@ class IssueSyncer extends Base {
139139 return path . join ( issueSyncConfig . archiveDir , issue . milestone . title , filename ) ;
140140 }
141141
142- // For issues without a milestone, find the next release that was published after it was closed.
142+ // For issues without a milestone, find the earliest release that was published after it was closed.
143143 const closed = new Date ( issue . closedAt ) ;
144- const release = Object . values ( ReleaseSyncer . releases ) . find ( r => new Date ( r . publishedAt ) > closed ) ;
144+ const sortedReleases = Object . values ( ReleaseSyncer . releases || { } ) . sort ( ( a , b ) => new Date ( a . publishedAt ) - new Date ( b . publishedAt ) ) ;
145+ const release = sortedReleases . find ( r => new Date ( r . publishedAt ) > closed ) ;
145146
146147 // If a subsequent release exists, archive the issue under that release tag.
147148 if ( release ) {
@@ -282,37 +283,36 @@ class IssueSyncer extends Base {
282283 } ;
283284 }
284285
285- // Phase 2: Reconcile locations for all known issues, including those not in the delta.
286- // This is critical for archiving stale issues that haven't been updated but whose
287- // milestone now requires them to be moved.
288- logger . info ( 'Reconciling local file locations for all known issues...' ) ;
286+ // Phase 2: Reconcile locations for issues in the active directory.
287+ // This is for archiving stale issues that haven't been updated but should be archived.
288+ logger . info ( 'Reconciling active issue file locations...' ) ;
289289 for ( const issueNumber in newMetadata . issues ) {
290290 const issueData = newMetadata . issues [ issueNumber ] ;
291291
292- // Re-determine the correct path based on the issue's known state .
293- const correctPath = this . #getIssuePath ( {
294- number : issueNumber ,
295- state : issueData . state ,
296- labels : [ ] , // Labels for dropping are handled on pull, not needed here.
297- milestone : issueData . milestone ? { title : issueData . milestone } : null ,
298- closedAt : issueData . closedAt
299- } ) ;
300-
301- if ( correctPath && issueData . path !== correctPath ) {
302- logger . info ( `Mismatched path for # ${ issueNumber } . Expected: ${ correctPath } , Found: ${ issueData . path } ` ) ;
303- try {
304- await fs . mkdir ( path . dirname ( correctPath ) , { recursive : true } ) ;
305- await fs . rename ( issueData . path , correctPath ) ;
306- logger . info ( `📦 Moved # ${ issueNumber } : ${ issueData . path } → ${ correctPath } ` ) ;
307-
308- // Update the metadata with the new path
309- newMetadata . issues [ issueNumber ] . path = correctPath ;
310-
311- // This is a local-only operation, so only update the 'moved' statistic.
312- stats . pulled . moved = ( stats . pulled . moved || 0 ) + 1 ;
313-
314- } catch ( e ) {
315- logger . warn ( `Could not move # ${ issueNumber } during reconciliation. Error: ${ e . message } ` ) ;
292+ // ONLY check issues currently in the active folder. This is the critical safety guard .
293+ if ( issueData . path . startsWith ( issueSyncConfig . issuesDir ) ) {
294+ const correctPath = this . #getIssuePath ( {
295+ number : issueNumber ,
296+ state : issueData . state ,
297+ labels : [ ] , // Labels for dropping are handled on pull, not needed here.
298+ milestone : issueData . milestone ? { title : issueData . milestone } : null ,
299+ closedAt : issueData . closedAt
300+ } ) ;
301+
302+ // Check if the issue should be moved to an archive
303+ if ( correctPath && issueData . path !== correctPath ) {
304+ logger . info ( `Mismatched path for active issue # ${ issueNumber } . Expected: ${ correctPath } , Found: ${ issueData . path } ` ) ;
305+ try {
306+ await fs . mkdir ( path . dirname ( correctPath ) , { recursive : true } ) ;
307+ await fs . rename ( issueData . path , correctPath ) ;
308+ logger . info ( `📦 Moved # ${ issueNumber } : ${ issueData . path } → ${ correctPath } ` ) ;
309+
310+ newMetadata . issues [ issueNumber ] . path = correctPath ;
311+ stats . pulled . moved = ( stats . pulled . moved || 0 ) + 1 ;
312+
313+ } catch ( e ) {
314+ logger . warn ( `Could not move # ${ issueNumber } during reconciliation. Error: ${ e . message } ` ) ;
315+ }
316316 }
317317 }
318318 }
0 commit comments