@@ -683,10 +683,9 @@ ${this.results.reduce((x, y) => {
683683 */
684684 async getSubOrgConfigs ( ) {
685685 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 ( )
690689 const subOrgConfigs = { }
691690
692691 for ( const override of overridePaths ) {
@@ -698,7 +697,7 @@ ${this.results.reduce((x, y) => {
698697 subOrgConfigs [ override . name ] = data
699698 if ( data . suborgrepos ) {
700699 data . suborgrepos . forEach ( repository => {
701- this . storeSubOrgConfig ( subOrgConfigs , override . path , repository , data )
700+ this . storeSubOrgConfigIfNoConflicts ( subOrgConfigs , override . path , repository , data )
702701
703702 // In case support for multiple suborg configs for the same repo is required, merge the configs.
704703 //
@@ -720,7 +719,7 @@ ${this.results.reduce((x, y) => {
720719 await Promise . all ( promises ) . then ( res => {
721720 res . forEach ( r => {
722721 r . forEach ( e => {
723- this . storeSubOrgConfig ( subOrgConfigs , override . path , e . name , data )
722+ this . storeSubOrgConfigIfNoConflicts ( subOrgConfigs , override . path , e . name , data )
724723 } )
725724 } )
726725 } )
@@ -732,12 +731,26 @@ ${this.results.reduce((x, y) => {
732731 await Promise . all ( promises ) . then ( res => {
733732 res . forEach ( r => {
734733 r . forEach ( e => {
735- this . storeSubOrgConfig ( subOrgConfigs , override . path , e . repository_name , data )
734+ this . storeSubOrgConfigIfNoConflicts ( subOrgConfigs , override . path , e . repository_name , data )
736735 } )
737736 } )
738737 } )
739738 }
740739 }
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+ }
741754 return subOrgConfigs
742755 } catch ( e ) {
743756 if ( this . nop ) {
@@ -751,7 +764,7 @@ ${this.results.reduce((x, y) => {
751764 }
752765 }
753766
754- storeSubOrgConfig ( subOrgConfigs , overridePath , repoName , data ) {
767+ storeSubOrgConfigIfNoConflicts ( subOrgConfigs , overridePath , repoName , data ) {
755768 const existingConfigForRepo = subOrgConfigs [ repoName ]
756769 if ( existingConfigForRepo && existingConfigForRepo . source !== overridePath ) {
757770 throw new Error ( `Multiple suborg configs for ${ repoName } in ${ overridePath } and ${ existingConfigForRepo ?. source } ` )
0 commit comments