Skip to content

Commit 4159742

Browse files
committed
fix: create new repositories during full-sync operation
The full-sync script now properly creates new repositories defined in the configuration instead of only updating existing ones. This fixes the different behavior between webhook-based sync and full-sync runs.
1 parent a21c657 commit 4159742

File tree

1 file changed

+42
-11
lines changed

1 file changed

+42
-11
lines changed

lib/settings.js

+42-11
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ ${this.results.reduce((x, y) => {
357357
async updateAll () {
358358
// this.subOrgConfigs = this.subOrgConfigs || await this.getSubOrgConfigs(this.github, this.repo, this.log)
359359
// this.repoConfigs = this.repoConfigs || await this.getRepoConfigs(this.github, this.repo, this.log)
360-
return this.eachRepositoryRepos(this.github, this.config.restrictedRepos, this.log).then(res => {
360+
return this.eachRepositoryRepos(this.github, this.log).then(res => {
361361
this.appendToResults(res)
362362
})
363363
}
@@ -468,19 +468,50 @@ ${this.results.reduce((x, y) => {
468468
return restrictedRepos.filter((restrictedRepo) => { return RegExp(restrictedRepo).test(repoName) }).length > 0
469469
}
470470

471-
async eachRepositoryRepos (github, restrictedRepos, log) {
471+
async eachRepositoryRepos (github, log) {
472472
log.debug('Fetching repositories')
473-
return github.paginate('GET /installation/repositories').then(repositories => {
474-
return Promise.all(repositories.map(repository => {
475-
if (this.isRestricted(repository.name)) {
476-
return null
477-
}
478473

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

486517
/**

0 commit comments

Comments
 (0)