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