Skip to content

Commit

Permalink
detect conflict even when a single suborg config is changed
Browse files Browse the repository at this point in the history
  • Loading branch information
decyjphr committed Aug 29, 2024
1 parent f534c6e commit 04434a2
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions lib/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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.
//
Expand All @@ -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)
})
})
})
Expand All @@ -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) {
Expand All @@ -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}`)
Expand Down

0 comments on commit 04434a2

Please sign in to comment.