Skip to content

Commit ee5909a

Browse files
PendaGTPdecyjphr
andauthored
fix: create new repositories during full-sync operation (#710)
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. Co-authored-by: Yadhav Jayaraman <[email protected]>
1 parent 2ce0136 commit ee5909a

File tree

1 file changed

+41
-11
lines changed

1 file changed

+41
-11
lines changed

lib/settings.js

+41-11
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
/**

0 commit comments

Comments
 (0)