Skip to content

Commit 818f894

Browse files
authored
Merge branch 'main-enterprise' into dependabot/npm_and_yarn/eslint-plugin-import-2.31.0
2 parents a0be26d + 4c553a9 commit 818f894

File tree

5 files changed

+49
-18
lines changed

5 files changed

+49
-18
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ You can pass environment variables; the easiest way to do it is via a `.env` fil
382382
383383
## How to use
384384
385-
1. Create an `admin` repo (or an alternative of your choosing) within your organization. Remember to set `CONFIG_REPO` if you choose something other than `admin`. See [Environment variables](#environment-variables) for more details.
385+
1. Create an `admin` repo (or an alternative of your choosing) within your organization. Remember to set `ADMIN_REPO` if you choose something other than `admin`. See [Environment variables](#environment-variables) for more details.
386386
387387
2. Add the settings for the `org`, `suborgs`, and `repos`. Sample files can be found [here](docs/sample-settings).
388388

lib/plugins/environments.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ module.exports = class Environments extends Diffable {
167167
for (const variable of attrs.variables) {
168168
const existingVariable = existingVariables.find((_var) => _var.name === variable.name)
169169
if (existingVariable) {
170-
existingVariables = existingVariables.filter(_var => _var.name !== variable.name)
170+
existingVariables = existingVariables.filter(_var => _var.name === variable.name)
171171
if (existingVariable.value !== variable.value) {
172172
await this.github.request('PATCH /repos/:org/:repo/environments/:environment_name/variables/:variable_name', {
173173
org: this.repo.owner,

lib/settings.js

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ ${this.results.reduce((x, y) => {
364364
async updateAll() {
365365
// this.subOrgConfigs = this.subOrgConfigs || await this.getSubOrgConfigs(this.github, this.repo, this.log)
366366
// this.repoConfigs = this.repoConfigs || await this.getRepoConfigs(this.github, this.repo, this.log)
367-
return this.eachRepositoryRepos(this.github, this.config.restrictedRepos, this.log).then(res => {
367+
return this.eachRepositoryRepos(this.github, this.log).then(res => {
368368
this.appendToResults(res)
369369
})
370370
}
@@ -475,19 +475,49 @@ ${this.results.reduce((x, y) => {
475475
return restrictedRepos.filter((restrictedRepo) => { return RegExp(restrictedRepo).test(repoName) }).length > 0
476476
}
477477

478-
async eachRepositoryRepos(github, restrictedRepos, log) {
478+
async eachRepositoryRepos (github, log) {
479479
log.debug('Fetching repositories')
480-
return github.paginate('GET /installation/repositories').then(repositories => {
481-
return Promise.all(repositories.map(repository => {
482-
if (this.isRestricted(repository.name)) {
483-
return null
484-
}
485480

486-
const { owner, name } = repository
487-
return this.updateRepos({ owner: owner.login, repo: name })
481+
const processedRepos = new Set()
482+
const results = []
483+
484+
// Process existing repositories
485+
const existingRepoResults = await github.paginate('GET /installation/repositories')
486+
.then(repositories => {
487+
return Promise.all(repositories.map(repository => {
488+
if (this.isRestricted(repository.name)) {
489+
return null
490+
}
491+
const { owner, name } = repository
492+
processedRepos.add(`${owner.login}/${name}`)
493+
return this.updateRepos({ owner: owner.login, repo: name })
494+
}))
488495
})
489-
)
490-
})
496+
497+
// Process missing repositories
498+
const repoInConfigs = Object.values(this.repoConfigs)
499+
.filter(config => config.repository?.name)
500+
.map(config => {
501+
return {
502+
name: config.repository.name,
503+
owner: config.repository.organization || this.repo.owner
504+
}
505+
})
506+
const missingRepoResults = await Promise.all(
507+
repoInConfigs
508+
.filter(repo => !this.isRestricted(repo.name))
509+
.filter(repo => !processedRepos.has(`${repo.owner}/${repo.name}`))
510+
.map(repo => {
511+
processedRepos.add(`${repo.owner}/${repo.name}`)
512+
return this.updateRepos({ owner: repo.owner, repo: repo.name })
513+
})
514+
)
515+
516+
results
517+
.concat(existingRepoResults || [], missingRepoResults || [])
518+
.filter(result => result !== null)
519+
520+
return results
491521
}
492522

493523
/**

package-lock.json

Lines changed: 5 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"jest-junit": "^16.0.0",
5050
"jest-when": "^3.5.2",
5151
"lockfile-lint": "^4.12.1",
52-
"nock": "^13.5.4",
52+
"nock": "^13.5.6",
5353
"nodemon": "^3.1.9",
5454
"npm-run-all": "^4.1.5",
5555
"smee-client": "^1.2.2",

0 commit comments

Comments
 (0)