diff --git a/lib/settings.js b/lib/settings.js index 20e71167..c5b48ccd 100644 --- a/lib/settings.js +++ b/lib/settings.js @@ -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) } /**