@@ -357,7 +357,7 @@ ${this.results.reduce((x, y) => {
357
357
async updateAll ( ) {
358
358
// this.subOrgConfigs = this.subOrgConfigs || await this.getSubOrgConfigs(this.github, this.repo, this.log)
359
359
// 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 => {
361
361
this . appendToResults ( res )
362
362
} )
363
363
}
@@ -468,19 +468,49 @@ ${this.results.reduce((x, y) => {
468
468
return restrictedRepos . filter ( ( restrictedRepo ) => { return RegExp ( restrictedRepo ) . test ( repoName ) } ) . length > 0
469
469
}
470
470
471
- async eachRepositoryRepos ( github , restrictedRepos , log ) {
471
+ async eachRepositoryRepos ( github , log ) {
472
472
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
- }
478
473
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
+ } ) )
481
488
} )
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
484
514
}
485
515
486
516
/**
@@ -799,14 +829,13 @@ ${this.results.reduce((x, y) => {
799
829
}
800
830
801
831
async getReposForCustomProperty ( customPropertyTuple ) {
802
- const name = Object . keys ( customPropertyTuple ) [ 0 ]
832
+ const name = Object . keys ( customPropertyTuple ) [ 0 ]
803
833
let q = `props.${ name } :${ customPropertyTuple [ name ] } `
804
834
q = encodeURIComponent ( q )
805
835
const options = this . github . request . endpoint ( ( `/orgs/${ this . repo . owner } /properties/values?repository_query=${ q } ` ) )
806
836
return this . github . paginate ( options )
807
837
}
808
838
809
-
810
839
isObject ( item ) {
811
840
return ( item && typeof item === 'object' && ! Array . isArray ( item ) )
812
841
}
@@ -820,7 +849,7 @@ ${this.results.reduce((x, y) => {
820
849
}
821
850
}
822
851
823
- function prettify ( obj ) {
852
+ function prettify ( obj ) {
824
853
if ( obj === null || obj === undefined ) {
825
854
return ''
826
855
}
0 commit comments