Skip to content

Commit 8239721

Browse files
committed
undo Archive changes
1 parent 6168667 commit 8239721

File tree

1 file changed

+51
-83
lines changed

1 file changed

+51
-83
lines changed

lib/settings.js

Lines changed: 51 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,10 @@ class Settings {
166166

167167
// remove duplicate rows in this.results
168168
this.results = this.results.filter((thing, index, self) => {
169-
return index === self.findIndex((t) => {
170-
return t.type === thing.type && t.repo === thing.repo && t.plugin === thing.plugin
169+
return index === self.findIndex((t) => {
170+
return t.type === thing.type && t.repo === thing.repo && t.plugin === thing.plugin
171+
})
171172
})
172-
})
173173

174174
let error = false
175175
// Different logic
@@ -296,12 +296,11 @@ ${this.results.reduce((x, y) => {
296296
}
297297
}
298298

299-
async updateRepos (repo) {
299+
async updateRepos(repo) {
300300
this.subOrgConfigs = this.subOrgConfigs || await this.getSubOrgConfigs()
301-
// Create a fresh copy of the base repository config
302-
let repoConfig = this.config.repository ? Object.assign({}, this.config.repository) : {}
301+
let repoConfig = this.config.repository
303302
if (repoConfig) {
304-
repoConfig = Object.assign({}, repoConfig, { name: repo.repo, org: repo.owner })
303+
repoConfig = Object.assign(repoConfig, { name: repo.repo, org: repo.owner })
305304
}
306305

307306
const subOrgConfig = this.getSubOrgConfig(repo.repo)
@@ -315,9 +314,9 @@ ${this.results.reduce((x, y) => {
315314
this.log.debug(`Process normally... Not a SubOrg config change or SubOrg config was changed and this repo is part of it. ${JSON.stringify(repo)} suborg config ${JSON.stringify(this.subOrgConfigMap)}`)
316315

317316
if (subOrgConfig) {
318-
let suborgRepoConfig = subOrgConfig.repository ? Object.assign({}, subOrgConfig.repository) : {}
317+
let suborgRepoConfig = subOrgConfig.repository
319318
if (suborgRepoConfig) {
320-
suborgRepoConfig = Object.assign({}, suborgRepoConfig, { name: repo.repo, org: repo.owner })
319+
suborgRepoConfig = Object.assign(suborgRepoConfig, { name: repo.repo, org: repo.owner })
321320
repoConfig = this.mergeDeep.mergeDeep({}, repoConfig, suborgRepoConfig)
322321
}
323322
}
@@ -328,45 +327,42 @@ ${this.results.reduce((x, y) => {
328327
if (overrideRepoConfig) {
329328
repoConfig = this.mergeDeep.mergeDeep({}, repoConfig, overrideRepoConfig)
330329
}
331-
const { shouldContinue, nopCommands } = await new Archive(this.nop, this.github, repo, repoConfig, this.log).sync()
332-
if (nopCommands) this.appendToResults(nopCommands)
333-
if (shouldContinue) {
334-
if (repoConfig) {
335-
try {
336-
this.log.debug(`found a matching repoconfig for this repo ${JSON.stringify(repoConfig)}`)
337-
const childPlugins = this.childPluginsList(repo)
338-
const RepoPlugin = Settings.PLUGINS.repository
339-
return new RepoPlugin(this.nop, this.github, repo, repoConfig, this.installation_id, this.log, this.errors).sync().then(res => {
340-
this.appendToResults(res)
341-
return Promise.all(
342-
childPlugins.map(([Plugin, config]) => {
343-
return new Plugin(this.nop, this.github, repo, config, this.log, this.errors).sync()
344-
}))
345-
}).then(res => {
346-
this.appendToResults(res)
347-
})
348-
} catch (e) {
349-
if (this.nop) {
350-
const nopcommand = new NopCommand(this.constructor.name, this.repo, null, `${e}`, 'ERROR')
351-
this.log.error(`NOPCOMMAND ${JSON.stringify(nopcommand)}`)
352-
this.appendToResults([nopcommand])
353-
// throw e
354-
} else {
355-
throw e
356-
}
357-
}
358-
} else {
359-
this.log.debug(`Didnt find any a matching repoconfig for this repo ${JSON.stringify(repo)} in ${JSON.stringify(this.repoConfigs)}`)
330+
if (repoConfig) {
331+
try {
332+
this.log.debug(`found a matching repoconfig for this repo ${JSON.stringify(repoConfig)}`)
360333
const childPlugins = this.childPluginsList(repo)
361-
return Promise.all(childPlugins.map(([Plugin, config]) => {
362-
return new Plugin(this.nop, this.github, repo, config, this.log, this.errors).sync().then(res => {
363-
this.appendToResults(res)
364-
})
365-
}))
334+
const RepoPlugin = Settings.PLUGINS.repository
335+
return new RepoPlugin(this.nop, this.github, repo, repoConfig, this.installation_id, this.log, this.errors).sync().then(res => {
336+
this.appendToResults(res)
337+
return Promise.all(
338+
childPlugins.map(([Plugin, config]) => {
339+
return new Plugin(this.nop, this.github, repo, config, this.log, this.errors).sync()
340+
}))
341+
}).then(res => {
342+
this.appendToResults(res)
343+
})
344+
} catch (e) {
345+
if (this.nop) {
346+
const nopcommand = new NopCommand(this.constructor.name, this.repo, null, `${e}`, 'ERROR')
347+
this.log.error(`NOPCOMMAND ${JSON.stringify(nopcommand)}`)
348+
this.appendToResults([nopcommand])
349+
// throw e
350+
} else {
351+
throw e
352+
}
366353
}
354+
} else {
355+
this.log.debug(`Didnt find any a matching repoconfig for this repo ${JSON.stringify(repo)} in ${JSON.stringify(this.repoConfigs)}`)
356+
const childPlugins = this.childPluginsList(repo)
357+
return Promise.all(childPlugins.map(([Plugin, config]) => {
358+
return new Plugin(this.nop, this.github, repo, config, this.log, this.errors).sync().then(res => {
359+
this.appendToResults(res)
360+
})
361+
}))
367362
}
368363
}
369364

365+
370366
async updateAll () {
371367
// this.subOrgConfigs = this.subOrgConfigs || await this.getSubOrgConfigs(this.github, this.repo, this.log)
372368
// this.repoConfigs = this.repoConfigs || await this.getRepoConfigs(this.github, this.repo, this.log)
@@ -487,47 +483,17 @@ ${this.results.reduce((x, y) => {
487483

488484
async eachRepositoryRepos (github, log) {
489485
log.debug('Fetching repositories')
490-
491-
const processedRepos = new Set()
492-
const results = []
493-
494-
// Process existing repositories
495-
const existingRepoResults = await github.paginate('GET /installation/repositories')
496-
.then(repositories => {
497-
return Promise.all(repositories.map(repository => {
498-
if (this.isRestricted(repository.name)) {
499-
return null
500-
}
501-
const { owner, name } = repository
502-
processedRepos.add(`${owner.login}/${name}`)
503-
return this.updateRepos({ owner: owner.login, repo: name })
504-
}))
505-
})
506-
507-
// Process missing repositories
508-
const repoInConfigs = Object.values(this.repoConfigs)
509-
.filter(config => config.repository?.name)
510-
.map(config => {
511-
return {
512-
name: config.repository.name,
513-
owner: config.repository.organization || this.repo.owner
486+
return github.paginate('GET /installation/repositories').then(repositories => {
487+
return Promise.all(repositories.map(repository => {
488+
if (this.isRestricted(repository.name)) {
489+
return null
514490
}
515-
})
516-
const missingRepoResults = await Promise.all(
517-
repoInConfigs
518-
.filter(repo => !this.isRestricted(repo.name))
519-
.filter(repo => !processedRepos.has(`${repo.owner}/${repo.name}`))
520-
.map(repo => {
521-
processedRepos.add(`${repo.owner}/${repo.name}`)
522-
return this.updateRepos({ owner: repo.owner, repo: repo.name })
523-
})
524-
)
525-
526-
results
527-
.concat(existingRepoResults || [], missingRepoResults || [])
528-
.filter(result => result !== null)
529491

530-
return results
492+
const { owner, name } = repository
493+
return this.updateRepos({ owner: owner.login, repo: name })
494+
})
495+
)
496+
})
531497
}
532498

533499
/**
@@ -790,7 +756,7 @@ ${this.results.reduce((x, y) => {
790756
}
791757
)) {
792758
delete subOrgConfigs[key]
793-
}
759+
}
794760
}
795761
}
796762
return subOrgConfigs
@@ -894,6 +860,7 @@ ${this.results.reduce((x, y) => {
894860
throw new Error(`Failed to filter repositories for property ${name}: ${error.message}`)
895861
}
896862
}
863+
897864

898865
async getSubOrgRepositories (subOrgProperties) {
899866
const organizationName = this.repo.owner
@@ -940,6 +907,7 @@ function prettify (obj) {
940907
return JSON.stringify(obj, null, 2).replaceAll('\n', '<br>').replaceAll(' ', '&nbsp;')
941908
}
942909

910+
Settings.FILE_NAME = path.posix.join(CONFIG_PATH, env.SETTINGS_FILE_PATH)
943911
Settings.FILE_PATH = path.posix.join(CONFIG_PATH, env.SETTINGS_FILE_PATH)
944912
Settings.SUB_ORG_PATTERN = new Glob(`${CONFIG_PATH}/suborgs/*.yml`)
945913
Settings.REPO_PATTERN = new Glob(`${CONFIG_PATH}/repos/*.yml`)

0 commit comments

Comments
 (0)