@@ -763,16 +763,10 @@ ${this.results.reduce((x, y) => {
763763 } )
764764 }
765765 if ( data . suborgproperties ) {
766- const promises = data . suborgproperties . map ( ( customProperty ) => {
767- return this . getReposForCustomProperty ( customProperty )
768- } )
769- await Promise . all ( promises ) . then ( res => {
770- res . forEach ( r => {
771- r . forEach ( e => {
772- this . storeSubOrgConfigIfNoConflicts ( subOrgConfigs , override . path , e . repository_name , data )
773- } )
774- } )
775- } )
766+ const subOrgRepositories = await this . getSubOrgRepositories ( data . suborgproperties )
767+ subOrgRepositories . forEach ( repo =>
768+ this . storeSubOrgConfigIfNoConflicts ( subOrgConfigs , override . path , repo . repository_name , data )
769+ )
776770 }
777771 }
778772
@@ -871,12 +865,54 @@ ${this.results.reduce((x, y) => {
871865 return this . github . paginate ( options )
872866 }
873867
874- async getReposForCustomProperty ( customPropertyTuple ) {
875- const name = Object . keys ( customPropertyTuple ) [ 0 ]
876- let q = `props.${ name } :${ customPropertyTuple [ name ] } `
877- q = encodeURIComponent ( q )
878- const options = this . github . request . endpoint ( ( `/orgs/${ this . repo . owner } /properties/values?repository_query=${ q } ` ) )
879- return this . github . paginate ( options )
868+ async getRepositoriesByProperty ( organizationName , propertyFilter ) {
869+ if ( ! organizationName || ! propertyFilter ) {
870+ throw new Error ( 'Organization name and property filter are required' )
871+ }
872+
873+ const [ name ] = Object . keys ( propertyFilter )
874+ const value = propertyFilter [ name ]
875+
876+ try {
877+ const query = `props.${ name } .${ value } `
878+ const encodedQuery = encodeURIComponent ( query )
879+
880+ return this . github . paginate (
881+ this . github . repos . getCustomPropertiesValues ,
882+ {
883+ org : organizationName ,
884+ repository_query : encodedQuery ,
885+ per_page : 100
886+ }
887+ )
888+ } catch ( error ) {
889+ throw new Error ( `Failed to filter repositories for property ${ name } : ${ error . message } ` )
890+ }
891+ }
892+
893+ async getSubOrgRepositories ( subOrgProperties ) {
894+ const organizationName = this . repo . owner
895+ try {
896+ const repositories = await Promise . all (
897+ subOrgProperties . map ( property =>
898+ this . getRepositoriesByProperty ( organizationName , property )
899+ )
900+ )
901+
902+ // Deduplicate repositories based on repository_name
903+ const uniqueRepos = repositories
904+ . flat ( )
905+ . reduce ( ( unique , repo ) => {
906+ unique . set ( repo . repository_name , repo )
907+ return unique
908+ } , new Map ( ) )
909+
910+ const result = Array . from ( uniqueRepos . values ( ) )
911+
912+ return result
913+ } catch ( error ) {
914+ throw new Error ( `Failed to fetch suborg repositories: ${ error . message } ` )
915+ }
880916 }
881917
882918 isObject ( item ) {
0 commit comments