@@ -459,6 +459,125 @@ export class R2GitHubService {
459459 }
460460 }
461461
462+ // Get full details of all keys in the storage for debugging
463+ async dumpStorageKeys ( ) : Promise < {
464+ total_keys : number ;
465+ key_counts : Record < string , number > ;
466+ key_samples : Record < string , string [ ] > ;
467+ all_keys : string [ ] ;
468+ } > {
469+ try {
470+ this . log ( "Dumping all storage keys for debugging" ) ;
471+ const keys = await this . storage . getKeys ( ) ;
472+ this . log ( `Found ${ keys . length } total keys in storage` ) ;
473+
474+ // Organize keys by prefix for better debugging
475+ const keysByPrefix : Record < string , string [ ] > = { } ;
476+
477+ keys . forEach ( ( key ) => {
478+ const prefix = key . split ( ":" ) [ 0 ] || "unknown" ;
479+ if ( ! keysByPrefix [ prefix ] ) {
480+ keysByPrefix [ prefix ] = [ ] ;
481+ }
482+ keysByPrefix [ prefix ] . push ( key ) ;
483+ } ) ;
484+
485+ // Count each type
486+ const counts : Record < string , number > = { } ;
487+ Object . keys ( keysByPrefix ) . forEach ( ( prefix ) => {
488+ counts [ prefix ] = keysByPrefix [ prefix ] . length ;
489+ } ) ;
490+
491+ this . log ( `Key counts by prefix: ${ JSON . stringify ( counts ) } ` ) ;
492+
493+ // Sample a few keys from each prefix (max 5)
494+ const samples : Record < string , string [ ] > = { } ;
495+ Object . keys ( keysByPrefix ) . forEach ( ( prefix ) => {
496+ samples [ prefix ] = keysByPrefix [ prefix ] . slice ( 0 , 5 ) ;
497+ } ) ;
498+
499+ return {
500+ total_keys : keys . length ,
501+ key_counts : counts ,
502+ key_samples : samples ,
503+ all_keys : keys ,
504+ } ;
505+ } catch ( error ) {
506+ this . log ( `Error dumping storage keys: ${ error } ` , true ) ;
507+ return {
508+ total_keys : 0 ,
509+ key_counts : { } ,
510+ key_samples : { } ,
511+ all_keys : [ ] ,
512+ } ;
513+ }
514+ }
515+
516+ // Get a few sample values to see the structure
517+ async getSampleValues ( ) : Promise < {
518+ sample_count : number ;
519+ samples : Record < string , any > ;
520+ error ?: string ;
521+ } > {
522+ try {
523+ this . log ( "Fetching sample values from storage for debugging" ) ;
524+ const keys = await this . storage . getKeys ( ) ;
525+
526+ if ( keys . length === 0 ) {
527+ return {
528+ sample_count : 0 ,
529+ samples : { } ,
530+ error : "No keys found in storage" ,
531+ } ;
532+ }
533+
534+ // Sample up to 5 keys of different types
535+ const sampleValues : Record < string , any > = { } ;
536+ const prefixes = [ "repo:" , "commit:" , "check-run:" , "search-index" ] ;
537+
538+ for ( const prefix of prefixes ) {
539+ const matchingKeys = keys
540+ . filter ( ( key ) => key . startsWith ( prefix ) )
541+ . slice ( 0 , 2 ) ;
542+ if ( matchingKeys . length > 0 ) {
543+ sampleValues [ prefix ] = { } ;
544+ for ( const key of matchingKeys ) {
545+ try {
546+ const value = await this . storage . getItem ( key ) ;
547+ if ( value ) {
548+ sampleValues [ prefix ] [ key ] =
549+ typeof value === "string" ? JSON . parse ( value ) : value ;
550+ }
551+ } catch ( error ) {
552+ sampleValues [ prefix ] [ key ] = `Error parsing value: ${ error } ` ;
553+ }
554+ }
555+ }
556+ }
557+
558+ return {
559+ sample_count : Object . keys ( sampleValues ) . length ,
560+ samples : sampleValues ,
561+ } ;
562+ } catch ( error ) {
563+ this . log ( `Error getting sample values: ${ error } ` , true ) ;
564+ return {
565+ sample_count : 0 ,
566+ samples : { } ,
567+ error : `Could not get sample values: ${ error } ` ,
568+ } ;
569+ }
570+ }
571+
572+ // Expose the storage for debugging purposes
573+ // This is normally not recommended but useful for debugging R2 issues
574+ getStorageAccess ( ) {
575+ return {
576+ getKeys : async ( ) => await this . storage . getKeys ( ) ,
577+ getItem : async ( key : string ) => await this . storage . getItem ( key ) ,
578+ } ;
579+ }
580+
462581 // Index methods - fetching data from GitHub and storing in R2
463582 async indexRepository ( owner : string , repo : string ) : Promise < void > {
464583 try {
0 commit comments