Skip to content

Commit 9789a0c

Browse files
authored
Merge branch 'main-enterprise' into pull-request-full-context
2 parents 0c52f67 + ff7a656 commit 9789a0c

File tree

5 files changed

+568
-102
lines changed

5 files changed

+568
-102
lines changed

.github/workflows/create-pre-release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ jobs:
5252
- name: Set up Docker Buildx
5353
uses: docker/setup-buildx-action@b5ca514318bd6ebac0fb2aedd5d36ec1b5c232a2
5454
- name: Log in to the Container registry
55-
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567
55+
uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772
5656
with:
5757
registry: ${{ env.REGISTRY }}
5858
username: ${{ github.actor }}

.github/workflows/create-release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
- name: Set up Docker Buildx
3131
uses: docker/setup-buildx-action@b5ca514318bd6ebac0fb2aedd5d36ec1b5c232a2
3232
- name: Log in to the Container registry
33-
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567
33+
uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772
3434
with:
3535
registry: ${{ env.REGISTRY }}
3636
username: ${{ github.actor }}

.github/workflows/rc-release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ jobs:
6060
- run: echo ${{ github.actor }}
6161

6262
- name: Log in to the Container registry
63-
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567
63+
uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772
6464
with:
6565
registry: ${{ env.REGISTRY }}
6666
username: ${{ github.actor }}

lib/settings.js

Lines changed: 53 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,10 @@ class Settings {
169169

170170
// remove duplicate rows in this.results
171171
this.results = this.results.filter((thing, index, self) => {
172-
return index === self.findIndex((t) => {
173-
return t.type === thing.type && t.repo === thing.repo && t.plugin === thing.plugin
172+
return index === self.findIndex((t) => {
173+
return t.type === thing.type && t.repo === thing.repo && t.plugin === thing.plugin
174+
})
174175
})
175-
})
176176

177177
let error = false
178178
// Different logic
@@ -299,12 +299,13 @@ ${this.results.reduce((x, y) => {
299299
}
300300
}
301301

302-
async updateRepos (repo) {
302+
async updateRepos(repo) {
303303
this.subOrgConfigs = this.subOrgConfigs || await this.getSubOrgConfigs()
304-
// Create a fresh copy of the base repository config
305-
let repoConfig = this.config.repository ? Object.assign({}, this.config.repository) : {}
304+
// Keeping this as is instead of doing an object assign as that would cause `Cannot read properties of undefined (reading 'startsWith')` error
305+
// Copilot code review would recoommend using object assign but that would cause the error
306+
let repoConfig = this.config.repository
306307
if (repoConfig) {
307-
repoConfig = Object.assign({}, repoConfig, { name: repo.repo, org: repo.owner })
308+
repoConfig = Object.assign(repoConfig, { name: repo.repo, org: repo.owner })
308309
}
309310

310311
const subOrgConfig = this.getSubOrgConfig(repo.repo)
@@ -318,9 +319,9 @@ ${this.results.reduce((x, y) => {
318319
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)}`)
319320

320321
if (subOrgConfig) {
321-
let suborgRepoConfig = subOrgConfig.repository ? Object.assign({}, subOrgConfig.repository) : {}
322+
let suborgRepoConfig = subOrgConfig.repository
322323
if (suborgRepoConfig) {
323-
suborgRepoConfig = Object.assign({}, suborgRepoConfig, { name: repo.repo, org: repo.owner })
324+
suborgRepoConfig = Object.assign(suborgRepoConfig, { name: repo.repo, org: repo.owner })
324325
repoConfig = this.mergeDeep.mergeDeep({}, repoConfig, suborgRepoConfig)
325326
}
326327
}
@@ -331,45 +332,42 @@ ${this.results.reduce((x, y) => {
331332
if (overrideRepoConfig) {
332333
repoConfig = this.mergeDeep.mergeDeep({}, repoConfig, overrideRepoConfig)
333334
}
334-
const { shouldContinue, nopCommands } = await new Archive(this.nop, this.github, repo, repoConfig, this.log).sync()
335-
if (nopCommands) this.appendToResults(nopCommands)
336-
if (shouldContinue) {
337-
if (repoConfig) {
338-
try {
339-
this.log.debug(`found a matching repoconfig for this repo ${JSON.stringify(repoConfig)}`)
340-
const childPlugins = this.childPluginsList(repo)
341-
const RepoPlugin = Settings.PLUGINS.repository
342-
return new RepoPlugin(this.nop, this.github, repo, repoConfig, this.installation_id, this.log, this.errors).sync().then(res => {
343-
this.appendToResults(res)
344-
return Promise.all(
345-
childPlugins.map(([Plugin, config]) => {
346-
return new Plugin(this.nop, this.github, repo, config, this.log, this.errors).sync()
347-
}))
348-
}).then(res => {
349-
this.appendToResults(res)
350-
})
351-
} catch (e) {
352-
if (this.nop) {
353-
const nopcommand = new NopCommand(this.constructor.name, this.repo, null, `${e}`, 'ERROR')
354-
this.log.error(`NOPCOMMAND ${JSON.stringify(nopcommand)}`)
355-
this.appendToResults([nopcommand])
356-
// throw e
357-
} else {
358-
throw e
359-
}
360-
}
361-
} else {
362-
this.log.debug(`Didnt find any a matching repoconfig for this repo ${JSON.stringify(repo)} in ${JSON.stringify(this.repoConfigs)}`)
335+
if (repoConfig) {
336+
try {
337+
this.log.debug(`found a matching repoconfig for this repo ${JSON.stringify(repoConfig)}`)
363338
const childPlugins = this.childPluginsList(repo)
364-
return Promise.all(childPlugins.map(([Plugin, config]) => {
365-
return new Plugin(this.nop, this.github, repo, config, this.log, this.errors).sync().then(res => {
366-
this.appendToResults(res)
367-
})
368-
}))
339+
const RepoPlugin = Settings.PLUGINS.repository
340+
return new RepoPlugin(this.nop, this.github, repo, repoConfig, this.installation_id, this.log, this.errors).sync().then(res => {
341+
this.appendToResults(res)
342+
return Promise.all(
343+
childPlugins.map(([Plugin, config]) => {
344+
return new Plugin(this.nop, this.github, repo, config, this.log, this.errors).sync()
345+
}))
346+
}).then(res => {
347+
this.appendToResults(res)
348+
})
349+
} catch (e) {
350+
if (this.nop) {
351+
const nopcommand = new NopCommand(this.constructor.name, this.repo, null, `${e}`, 'ERROR')
352+
this.log.error(`NOPCOMMAND ${JSON.stringify(nopcommand)}`)
353+
this.appendToResults([nopcommand])
354+
// throw e
355+
} else {
356+
throw e
357+
}
369358
}
359+
} else {
360+
this.log.debug(`Didnt find any a matching repoconfig for this repo ${JSON.stringify(repo)} in ${JSON.stringify(this.repoConfigs)}`)
361+
const childPlugins = this.childPluginsList(repo)
362+
return Promise.all(childPlugins.map(([Plugin, config]) => {
363+
return new Plugin(this.nop, this.github, repo, config, this.log, this.errors).sync().then(res => {
364+
this.appendToResults(res)
365+
})
366+
}))
370367
}
371368
}
372369

370+
373371
async updateAll () {
374372
// this.subOrgConfigs = this.subOrgConfigs || await this.getSubOrgConfigs(this.github, this.repo, this.log)
375373
// this.repoConfigs = this.repoConfigs || await this.getRepoConfigs(this.github, this.repo, this.log)
@@ -490,47 +488,17 @@ ${this.results.reduce((x, y) => {
490488

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

533-
return results
497+
const { owner, name } = repository
498+
return this.updateRepos({ owner: owner.login, repo: name })
499+
})
500+
)
501+
})
534502
}
535503

536504
/**
@@ -793,7 +761,7 @@ ${this.results.reduce((x, y) => {
793761
}
794762
)) {
795763
delete subOrgConfigs[key]
796-
}
764+
}
797765
}
798766
}
799767
return subOrgConfigs
@@ -897,6 +865,7 @@ ${this.results.reduce((x, y) => {
897865
throw new Error(`Failed to filter repositories for property ${name}: ${error.message}`)
898866
}
899867
}
868+
900869

901870
async getSubOrgRepositories (subOrgProperties) {
902871
const organizationName = this.repo.owner
@@ -943,6 +912,7 @@ function prettify (obj) {
943912
return JSON.stringify(obj, null, 2).replaceAll('\n', '<br>').replaceAll(' ', '&nbsp;')
944913
}
945914

915+
Settings.FILE_NAME = path.posix.join(CONFIG_PATH, env.SETTINGS_FILE_PATH)
946916
Settings.FILE_PATH = path.posix.join(CONFIG_PATH, env.SETTINGS_FILE_PATH)
947917
Settings.SUB_ORG_PATTERN = new Glob(`${CONFIG_PATH}/suborgs/*.yml`)
948918
Settings.REPO_PATTERN = new Glob(`${CONFIG_PATH}/repos/*.yml`)

0 commit comments

Comments
 (0)