@@ -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