Skip to content

Commit

Permalink
Merge branch 'main-enterprise' into dependabot/npm_and_yarn/nock-13.5.6
Browse files Browse the repository at this point in the history
  • Loading branch information
decyjphr authored Jan 8, 2025
2 parents 982b1a6 + 063800c commit 3ea752e
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ You can pass environment variables; the easiest way to do it is via a `.env` fil
## How to use
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.
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.
2. Add the settings for the `org`, `suborgs`, and `repos`. Sample files can be found [here](docs/sample-settings).
Expand Down
2 changes: 1 addition & 1 deletion lib/plugins/environments.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ module.exports = class Environments extends Diffable {
for (const variable of attrs.variables) {
const existingVariable = existingVariables.find((_var) => _var.name === variable.name)
if (existingVariable) {
existingVariables = existingVariables.filter(_var => _var.name !== variable.name)
existingVariables = existingVariables.filter(_var => _var.name === variable.name)
if (existingVariable.value !== variable.value) {
await this.github.request('PATCH /repos/:org/:repo/environments/:environment_name/variables/:variable_name', {
org: this.repo.owner,
Expand Down
52 changes: 41 additions & 11 deletions lib/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ ${this.results.reduce((x, y) => {
async updateAll() {
// this.subOrgConfigs = this.subOrgConfigs || await this.getSubOrgConfigs(this.github, this.repo, this.log)
// this.repoConfigs = this.repoConfigs || await this.getRepoConfigs(this.github, this.repo, this.log)
return this.eachRepositoryRepos(this.github, this.config.restrictedRepos, this.log).then(res => {
return this.eachRepositoryRepos(this.github, this.log).then(res => {
this.appendToResults(res)
})
}
Expand Down Expand Up @@ -475,19 +475,49 @@ ${this.results.reduce((x, y) => {
return restrictedRepos.filter((restrictedRepo) => { return RegExp(restrictedRepo).test(repoName) }).length > 0
}

async eachRepositoryRepos(github, restrictedRepos, log) {
async eachRepositoryRepos (github, log) {
log.debug('Fetching repositories')
return github.paginate('GET /installation/repositories').then(repositories => {
return Promise.all(repositories.map(repository => {
if (this.isRestricted(repository.name)) {
return null
}

const { owner, name } = repository
return this.updateRepos({ owner: owner.login, repo: name })
const processedRepos = new Set()
const results = []

// Process existing repositories
const existingRepoResults = await github.paginate('GET /installation/repositories')
.then(repositories => {
return Promise.all(repositories.map(repository => {
if (this.isRestricted(repository.name)) {
return null
}
const { owner, name } = repository
processedRepos.add(`${owner.login}/${name}`)
return this.updateRepos({ owner: owner.login, repo: name })
}))
})
)
})

// Process missing repositories
const repoInConfigs = Object.values(this.repoConfigs)
.filter(config => config.repository?.name)
.map(config => {
return {
name: config.repository.name,
owner: config.repository.organization || this.repo.owner
}
})
const missingRepoResults = await Promise.all(
repoInConfigs
.filter(repo => !this.isRestricted(repo.name))
.filter(repo => !processedRepos.has(`${repo.owner}/${repo.name}`))
.map(repo => {
processedRepos.add(`${repo.owner}/${repo.name}`)
return this.updateRepos({ owner: repo.owner, repo: repo.name })
})
)

results
.concat(existingRepoResults || [], missingRepoResults || [])
.filter(result => result !== null)

return results
}

/**
Expand Down

0 comments on commit 3ea752e

Please sign in to comment.