@@ -459,11 +459,13 @@ All instances of \`${ruleId}\` violations have been fixed. This issue is now aut
459459 const category = fileIssues [ 0 ] . category ;
460460 const severity = fileIssues . some ( issue => issue . severity === 'error' ) ? 'error' : 'warning' ;
461461
462- // Create title using filename as requested by user
462+ // Create enhanced title with region context for API verify files
463+ const enhancedTitle = this . generateEnhancedTitle ( filePath , fileName ) ;
464+
463465 groups . push ( {
464466 category,
465- title : fileName ,
466- body : this . generateFileIssueBody ( fileName , filePath , fileIssues ) ,
467+ title : enhancedTitle ,
468+ body : this . generateFileIssueBody ( enhancedTitle , filePath , fileIssues ) ,
467469 labels : [
468470 'lint' ,
469471 'code-quality' ,
@@ -477,6 +479,67 @@ All instances of \`${ruleId}\` violations have been fixed. This issue is now aut
477479 return groups ;
478480 }
479481
482+ /**
483+ * Generates an enhanced title that includes region context for API verify files
484+ * @param filePath - Full path to the file
485+ * @param fileName - Base filename
486+ * @returns Enhanced title with region context if applicable
487+ */
488+ private generateEnhancedTitle ( filePath : string , fileName : string ) : string {
489+ // Check if this is a file in the API verify directory structure
490+ const apiVerifyMatch = filePath . match ( / a p p \/ a p i \/ v e r i f y \/ ( [ ^ \/ ] + ) \/ ( .+ ) $ / ) ;
491+
492+ if ( apiVerifyMatch ) {
493+ const regionFolder = apiVerifyMatch [ 1 ] ;
494+ const fileInRegion = apiVerifyMatch [ 2 ] ;
495+
496+ // Convert region folder name to proper case for display
497+ // e.g., "arizona" -> "Arizona", "districtofcolumbia" -> "District of Columbia"
498+ const regionName = this . formatRegionName ( regionFolder ) ;
499+
500+ return `${ regionName } - ${ fileInRegion } ` ;
501+ }
502+
503+ // For non-API verify files, return the original filename
504+ return fileName ;
505+ }
506+
507+ /**
508+ * Formats region folder names into proper display names
509+ * @param regionFolder - Raw folder name (e.g., "arizona", "districtofcolumbia")
510+ * @returns Formatted region name (e.g., "Arizona", "District of Columbia")
511+ */
512+ private formatRegionName ( regionFolder : string ) : string {
513+ // Handle special cases
514+ const specialCases : Record < string , string > = {
515+ 'districtofcolumbia' : 'District of Columbia' ,
516+ 'newhampshire' : 'New Hampshire' ,
517+ 'newjersey' : 'New Jersey' ,
518+ 'newmexico' : 'New Mexico' ,
519+ 'newyork' : 'New York' ,
520+ 'northcarolina' : 'North Carolina' ,
521+ 'northdakota' : 'North Dakota' ,
522+ 'rhodeisland' : 'Rhode Island' ,
523+ 'southcarolina' : 'South Carolina' ,
524+ 'southdakota' : 'South Dakota' ,
525+ 'westvirginia' : 'West Virginia' ,
526+ 'britishcolumbia' : 'British Columbia' ,
527+ 'newbrunswick' : 'New Brunswick' ,
528+ 'newfoundland&labrador' : 'Newfoundland & Labrador' ,
529+ 'novascotia' : 'Nova Scotia' ,
530+ 'princeedwardisland' : 'Prince Edward Island' ,
531+ 'puertorico' : 'Puerto Rico'
532+ } ;
533+
534+ // Check for special cases first
535+ if ( specialCases [ regionFolder . toLowerCase ( ) ] ) {
536+ return specialCases [ regionFolder . toLowerCase ( ) ] ;
537+ }
538+
539+ // For regular cases, just capitalize the first letter
540+ return regionFolder . charAt ( 0 ) . toUpperCase ( ) + regionFolder . slice ( 1 ) ;
541+ }
542+
480543 private generateSummaryIssueBody ( report : IssueReport ) : string {
481544 let body = `## 📊 Lint Analysis Summary\n\n` ;
482545
@@ -681,14 +744,18 @@ All instances of \`${ruleId}\` violations have been fixed. This issue is now aut
681744 return body ;
682745 }
683746
684- async checkExistingFileIssue ( fileName : string ) : Promise < { number : number ; title : string ; body : string } | null > {
747+ async checkExistingFileIssue ( enhancedTitle : string ) : Promise < { number : number ; title : string ; body : string } | null > {
685748 if ( ! this . token ) return null ;
686749
687750 try {
688- // Search for issues with the filename as title
689- const searchQuery = `repo:${ this . owner } /${ this . repo } +is:issue+is:open+"${ fileName } "+label:lint+label:automated` ;
751+ // Search for issues with the enhanced title or just the filename
752+ // This handles both old format (just filename) and new format (Region - filename)
753+ const fileNamePart = enhancedTitle . includes ( ' - ' ) ? enhancedTitle . split ( ' - ' ) [ 1 ] : enhancedTitle ;
690754
691- const response = await fetch (
755+ // First try exact match with enhanced title
756+ let searchQuery = `repo:${ this . owner } /${ this . repo } +is:issue+is:open+"${ enhancedTitle } "+label:lint+label:automated` ;
757+
758+ let response = await fetch (
692759 `${ this . apiBase } /search/issues?q=${ encodeURIComponent ( searchQuery ) } ` ,
693760 {
694761 headers : {
@@ -703,9 +770,9 @@ All instances of \`${ruleId}\` violations have been fixed. This issue is now aut
703770 const data = await response . json ( ) ;
704771 if ( data . total_count > 0 ) {
705772 // Find exact title match (case-insensitive)
706- const exactMatch = data . items . find ( ( issue : any ) => issue . title . toLowerCase ( ) === fileName . toLowerCase ( ) ) ;
773+ const exactMatch = data . items . find ( ( issue : any ) => issue . title . toLowerCase ( ) === enhancedTitle . toLowerCase ( ) ) ;
707774 if ( exactMatch ) {
708- console . log ( `🔍 Found existing file-based issue for ${ fileName } : #${ exactMatch . number } ` ) ;
775+ console . log ( `🔍 Found existing file-based issue for ${ enhancedTitle } : #${ exactMatch . number } ` ) ;
709776 return {
710777 number : exactMatch . number ,
711778 title : exactMatch . title ,
@@ -714,14 +781,46 @@ All instances of \`${ruleId}\` violations have been fixed. This issue is now aut
714781 }
715782 }
716783 }
784+
785+ // If no exact match found, try searching for just the filename part (for backward compatibility)
786+ if ( fileNamePart !== enhancedTitle ) {
787+ searchQuery = `repo:${ this . owner } /${ this . repo } +is:issue+is:open+"${ fileNamePart } "+label:lint+label:automated` ;
788+
789+ response = await fetch (
790+ `${ this . apiBase } /search/issues?q=${ encodeURIComponent ( searchQuery ) } ` ,
791+ {
792+ headers : {
793+ 'Authorization' : `Bearer ${ this . token } ` ,
794+ 'Accept' : 'application/vnd.github.v3+json' ,
795+ 'User-Agent' : 'ClearView-Lint-Automation'
796+ }
797+ }
798+ ) ;
799+
800+ if ( response . ok ) {
801+ const data = await response . json ( ) ;
802+ if ( data . total_count > 0 ) {
803+ // Find exact match with just the filename (for migration from old format)
804+ const exactMatch = data . items . find ( ( issue : any ) => issue . title . toLowerCase ( ) === fileNamePart . toLowerCase ( ) ) ;
805+ if ( exactMatch ) {
806+ console . log ( `🔍 Found existing file-based issue (old format) for ${ fileNamePart } : #${ exactMatch . number } ` ) ;
807+ return {
808+ number : exactMatch . number ,
809+ title : exactMatch . title ,
810+ body : exactMatch . body
811+ } ;
812+ }
813+ }
814+ }
815+ }
717816 } catch ( error ) {
718- console . warn ( `⚠️ Could not check existing issues for file ${ fileName } :` , error ) ;
817+ console . warn ( `⚠️ Could not check existing issues for file ${ enhancedTitle } :` , error ) ;
719818 }
720819
721820 return null ;
722821 }
723822
724- async closeOldIssueForMigration ( issueNumber : number , fileName : string ) : Promise < void > {
823+ async closeOldIssueForMigration ( issueNumber : number , enhancedTitle : string ) : Promise < void > {
725824 if ( ! this . token ) return ;
726825
727826 try {
@@ -731,7 +830,7 @@ All instances of \`${ruleId}\` violations have been fixed. This issue is now aut
731830This issue is being closed as we're migrating to a new file-based issue format for better organization.
732831
733832**Old format:** Rule-based grouping
734- **New format:** File-based grouping (\`${ fileName } \`)
833+ **New format:** File-based grouping with region context (\`${ enhancedTitle } \`)
735834
736835A new issue will be created with the updated format to track the same lint violations.
737836
@@ -755,7 +854,7 @@ A new issue will be created with the updated format to track the same lint viola
755854 } ) ;
756855
757856 if ( response . ok ) {
758- console . log ( `✅ Closed old format issue #${ issueNumber } for migration to file-based format ` ) ;
857+ console . log ( `✅ Closed old format issue #${ issueNumber } for migration to ${ enhancedTitle } ` ) ;
759858 } else {
760859 console . warn ( `⚠️ Failed to close old format issue #${ issueNumber } :` , response . statusText ) ;
761860 }
0 commit comments