Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: create new repositories during full-sync operation #710

Open
wants to merge 1 commit into
base: main-enterprise
Choose a base branch
from
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
53 changes: 42 additions & 11 deletions lib/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,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 @@ -468,19 +468,50 @@ ${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 => {
return !processedRepos.has(`${repo.owner}/${repo.name}`) || this.isRestricted(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
Loading