@@ -683,10 +683,9 @@ ${this.results.reduce((x, y) => {
683
683
*/
684
684
async getSubOrgConfigs ( ) {
685
685
try {
686
- if ( this . subOrgConfigMap ) {
687
- this . log . debug ( `SubOrg config was changed and the associated overridePaths is = ${ JSON . stringify ( this . subOrgConfigMap ) } ` )
688
- }
689
- const overridePaths = this . subOrgConfigMap || await this . getSubOrgConfigMap ( )
686
+ // Get all suborg configs even though we might be here becuase of a suborg config change
687
+ // we will filter them out if request is due to a suborg config change
688
+ const overridePaths = await this . getSubOrgConfigMap ( )
690
689
const subOrgConfigs = { }
691
690
692
691
for ( const override of overridePaths ) {
@@ -698,7 +697,7 @@ ${this.results.reduce((x, y) => {
698
697
subOrgConfigs [ override . name ] = data
699
698
if ( data . suborgrepos ) {
700
699
data . suborgrepos . forEach ( repository => {
701
- this . storeSubOrgConfig ( subOrgConfigs , override . path , repository , data )
700
+ this . storeSubOrgConfigIfNoConflicts ( subOrgConfigs , override . path , repository , data )
702
701
703
702
// In case support for multiple suborg configs for the same repo is required, merge the configs.
704
703
//
@@ -720,7 +719,7 @@ ${this.results.reduce((x, y) => {
720
719
await Promise . all ( promises ) . then ( res => {
721
720
res . forEach ( r => {
722
721
r . forEach ( e => {
723
- this . storeSubOrgConfig ( subOrgConfigs , override . path , e . name , data )
722
+ this . storeSubOrgConfigIfNoConflicts ( subOrgConfigs , override . path , e . name , data )
724
723
} )
725
724
} )
726
725
} )
@@ -732,12 +731,26 @@ ${this.results.reduce((x, y) => {
732
731
await Promise . all ( promises ) . then ( res => {
733
732
res . forEach ( r => {
734
733
r . forEach ( e => {
735
- this . storeSubOrgConfig ( subOrgConfigs , override . path , e . repository_name , data )
734
+ this . storeSubOrgConfigIfNoConflicts ( subOrgConfigs , override . path , e . repository_name , data )
736
735
} )
737
736
} )
738
737
} )
739
738
}
740
739
}
740
+
741
+ // If this was result of a suborg config change, only return the repos that are part of the suborg config
742
+ if ( this . subOrgConfigMap ) {
743
+ this . log . debug ( `SubOrg config was changed and the associated overridePaths is = ${ JSON . stringify ( this . subOrgConfigMap ) } ` )
744
+ // enumerate the properties of the subOrgConfigs object and delete the ones that are not part of the suborg
745
+ for ( const [ key , value ] of Object . entries ( subOrgConfigs ) ) {
746
+ if ( ! this . subOrgConfigMap . some ( ( overridePath ) => {
747
+ return overridePath . path === value . source
748
+ }
749
+ ) ) {
750
+ delete subOrgConfigs [ key ]
751
+ }
752
+ }
753
+ }
741
754
return subOrgConfigs
742
755
} catch ( e ) {
743
756
if ( this . nop ) {
@@ -751,7 +764,7 @@ ${this.results.reduce((x, y) => {
751
764
}
752
765
}
753
766
754
- storeSubOrgConfig ( subOrgConfigs , overridePath , repoName , data ) {
767
+ storeSubOrgConfigIfNoConflicts ( subOrgConfigs , overridePath , repoName , data ) {
755
768
const existingConfigForRepo = subOrgConfigs [ repoName ]
756
769
if ( existingConfigForRepo && existingConfigForRepo . source !== overridePath ) {
757
770
throw new Error ( `Multiple suborg configs for ${ repoName } in ${ overridePath } and ${ existingConfigForRepo ?. source } ` )
0 commit comments