Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 36 additions & 9 deletions lib/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -488,17 +488,44 @@ ${this.results.reduce((x, y) => {

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 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 })
}))
})

const { owner, name } = repository
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 })
})
)

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

/**
Expand Down