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