@@ -772,16 +772,10 @@ ${this.results.reduce((x, y) => {
772772 } )
773773 }
774774 if ( data . suborgproperties ) {
775- const promises = data . suborgproperties . map ( ( customProperty ) => {
776- return this . getReposForCustomProperty ( customProperty )
777- } )
778- await Promise . all ( promises ) . then ( res => {
779- res . forEach ( r => {
780- r . forEach ( e => {
781- this . storeSubOrgConfigIfNoConflicts ( subOrgConfigs , override . path , e . repository_name , data )
782- } )
783- } )
784- } )
775+ const subOrgRepositories = await this . getSubOrgRepositories ( data . suborgproperties )
776+ subOrgRepositories . forEach ( repo =>
777+ this . storeSubOrgConfigIfNoConflicts ( subOrgConfigs , override . path , repo . repository_name , data )
778+ )
785779 }
786780 }
787781
@@ -880,12 +874,54 @@ ${this.results.reduce((x, y) => {
880874 return this . github . paginate ( options )
881875 }
882876
883- async getReposForCustomProperty ( customPropertyTuple ) {
884- const name = Object . keys ( customPropertyTuple ) [ 0 ]
885- let q = `props.${ name } :${ customPropertyTuple [ name ] } `
886- q = encodeURIComponent ( q )
887- const options = this . github . request . endpoint ( ( `/orgs/${ this . repo . owner } /properties/values?repository_query=${ q } ` ) )
888- return this . github . paginate ( options )
877+ async getRepositoriesByProperty ( organizationName , propertyFilter ) {
878+ if ( ! organizationName || ! propertyFilter ) {
879+ throw new Error ( 'Organization name and property filter are required' )
880+ }
881+
882+ const [ name ] = Object . keys ( propertyFilter )
883+ const value = propertyFilter [ name ]
884+
885+ try {
886+ const query = `props.${ name } .${ value } `
887+ const encodedQuery = encodeURIComponent ( query )
888+
889+ return this . github . paginate (
890+ this . github . repos . getCustomPropertiesValues ,
891+ {
892+ org : organizationName ,
893+ repository_query : encodedQuery ,
894+ per_page : 100
895+ }
896+ )
897+ } catch ( error ) {
898+ throw new Error ( `Failed to filter repositories for property ${ name } : ${ error . message } ` )
899+ }
900+ }
901+
902+ async getSubOrgRepositories ( subOrgProperties ) {
903+ const organizationName = this . repo . owner
904+ try {
905+ const repositories = await Promise . all (
906+ subOrgProperties . map ( property =>
907+ this . getRepositoriesByProperty ( organizationName , property )
908+ )
909+ )
910+
911+ // Deduplicate repositories based on repository_name
912+ const uniqueRepos = repositories
913+ . flat ( )
914+ . reduce ( ( unique , repo ) => {
915+ unique . set ( repo . repository_name , repo )
916+ return unique
917+ } , new Map ( ) )
918+
919+ const result = Array . from ( uniqueRepos . values ( ) )
920+
921+ return result
922+ } catch ( error ) {
923+ throw new Error ( `Failed to fetch suborg repositories: ${ error . message } ` )
924+ }
889925 }
890926
891927 isObject ( item ) {
0 commit comments