@@ -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,49 @@ ${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 => ! this . isRestricted ( repo . name ) )
502+ . filter ( repo => ! processedRepos . has ( `${ repo . owner } /${ repo . name } ` ) )
503+ . map ( repo => {
504+ processedRepos . add ( `${ repo . owner } /${ repo . name } ` )
505+ return this . updateRepos ( { owner : repo . owner , repo : repo . name } )
506+ } )
507+ )
508+
509+ results
510+ . concat ( existingRepoResults || [ ] , missingRepoResults || [ ] )
511+ . filter ( result => result !== null )
512+
513+ return results
484514 }
485515
486516 /**
@@ -799,14 +829,13 @@ ${this.results.reduce((x, y) => {
799829 }
800830
801831 async getReposForCustomProperty ( customPropertyTuple ) {
802- const name = Object . keys ( customPropertyTuple ) [ 0 ]
832+ const name = Object . keys ( customPropertyTuple ) [ 0 ]
803833 let q = `props.${ name } :${ customPropertyTuple [ name ] } `
804834 q = encodeURIComponent ( q )
805835 const options = this . github . request . endpoint ( ( `/orgs/${ this . repo . owner } /properties/values?repository_query=${ q } ` ) )
806836 return this . github . paginate ( options )
807837 }
808838
809-
810839 isObject ( item ) {
811840 return ( item && typeof item === 'object' && ! Array . isArray ( item ) )
812841 }
@@ -820,7 +849,7 @@ ${this.results.reduce((x, y) => {
820849 }
821850}
822851
823- function prettify ( obj ) {
852+ function prettify ( obj ) {
824853 if ( obj === null || obj === undefined ) {
825854 return ''
826855 }
0 commit comments