diff --git a/lib/settings.js b/lib/settings.js index 35724907..578d83c7 100644 --- a/lib/settings.js +++ b/lib/settings.js @@ -683,10 +683,9 @@ ${this.results.reduce((x, y) => { */ async getSubOrgConfigs() { try { - if (this.subOrgConfigMap) { - this.log.debug(`SubOrg config was changed and the associated overridePaths is = ${JSON.stringify(this.subOrgConfigMap)}`) - } - const overridePaths = this.subOrgConfigMap || await this.getSubOrgConfigMap() + // Get all suborg configs even though we might be here becuase of a suborg config change + // we will filter them out if request is due to a suborg config change + const overridePaths = await this.getSubOrgConfigMap() const subOrgConfigs = {} for (const override of overridePaths) { @@ -698,7 +697,7 @@ ${this.results.reduce((x, y) => { subOrgConfigs[override.name] = data if (data.suborgrepos) { data.suborgrepos.forEach(repository => { - this.storeSubOrgConfig(subOrgConfigs, override.path, repository, data) + this.storeSubOrgConfigIfNoConflicts(subOrgConfigs, override.path, repository, data) // In case support for multiple suborg configs for the same repo is required, merge the configs. // @@ -720,7 +719,7 @@ ${this.results.reduce((x, y) => { await Promise.all(promises).then(res => { res.forEach(r => { r.forEach(e => { - this.storeSubOrgConfig(subOrgConfigs, override.path, e.name, data) + this.storeSubOrgConfigIfNoConflicts(subOrgConfigs, override.path, e.name, data) }) }) }) @@ -732,12 +731,26 @@ ${this.results.reduce((x, y) => { await Promise.all(promises).then(res => { res.forEach(r => { r.forEach(e => { - this.storeSubOrgConfig(subOrgConfigs, override.path, e.repository_name, data) + this.storeSubOrgConfigIfNoConflicts(subOrgConfigs, override.path, e.repository_name, data) }) }) }) } } + + // If this was result of a suborg config change, only return the repos that are part of the suborg config + if (this.subOrgConfigMap) { + this.log.debug(`SubOrg config was changed and the associated overridePaths is = ${JSON.stringify(this.subOrgConfigMap)}`) + // enumerate the properties of the subOrgConfigs object and delete the ones that are not part of the suborg + for (const [key, value] of Object.entries(subOrgConfigs)) { + if (!this.subOrgConfigMap.some((overridePath) => { + return overridePath.path === value.source + } + )) { + delete subOrgConfigs[key] + } + } + } return subOrgConfigs } catch (e) { if (this.nop) { @@ -751,7 +764,7 @@ ${this.results.reduce((x, y) => { } } - storeSubOrgConfig(subOrgConfigs, overridePath, repoName, data) { + storeSubOrgConfigIfNoConflicts(subOrgConfigs, overridePath, repoName, data) { const existingConfigForRepo = subOrgConfigs[repoName] if (existingConfigForRepo && existingConfigForRepo.source !== overridePath) { throw new Error(`Multiple suborg configs for ${repoName} in ${overridePath} and ${existingConfigForRepo?.source}`)