@@ -166,10 +166,10 @@ class Settings {
166
166
167
167
// remove duplicate rows in this.results
168
168
this . results = this . results . filter ( ( thing , index , self ) => {
169
- return index === self . findIndex ( ( t ) => {
170
- return t . type === thing . type && t . repo === thing . repo && t . plugin === thing . plugin
169
+ return index === self . findIndex ( ( t ) => {
170
+ return t . type === thing . type && t . repo === thing . repo && t . plugin === thing . plugin
171
+ } )
171
172
} )
172
- } )
173
173
174
174
let error = false
175
175
// Different logic
@@ -296,12 +296,13 @@ ${this.results.reduce((x, y) => {
296
296
}
297
297
}
298
298
299
- async updateRepos ( repo ) {
299
+ async updateRepos ( repo ) {
300
300
this . subOrgConfigs = this . subOrgConfigs || await this . getSubOrgConfigs ( )
301
- // Create a fresh copy of the base repository config
302
- let repoConfig = this . config . repository ? Object . assign ( { } , this . config . repository ) : { }
301
+ // Keeping this as is instead of doing an object assign as that would cause `Cannot read properties of undefined (reading 'startsWith')` error
302
+ // Copilot code review would recoommend using object assign but that would cause the error
303
+ let repoConfig = this . config . repository
303
304
if ( repoConfig ) {
304
- repoConfig = Object . assign ( { } , repoConfig , { name : repo . repo , org : repo . owner } )
305
+ repoConfig = Object . assign ( repoConfig , { name : repo . repo , org : repo . owner } )
305
306
}
306
307
307
308
const subOrgConfig = this . getSubOrgConfig ( repo . repo )
@@ -315,9 +316,9 @@ ${this.results.reduce((x, y) => {
315
316
this . log . debug ( `Process normally... Not a SubOrg config change or SubOrg config was changed and this repo is part of it. ${ JSON . stringify ( repo ) } suborg config ${ JSON . stringify ( this . subOrgConfigMap ) } ` )
316
317
317
318
if ( subOrgConfig ) {
318
- let suborgRepoConfig = subOrgConfig . repository ? Object . assign ( { } , subOrgConfig . repository ) : { }
319
+ let suborgRepoConfig = subOrgConfig . repository
319
320
if ( suborgRepoConfig ) {
320
- suborgRepoConfig = Object . assign ( { } , suborgRepoConfig , { name : repo . repo , org : repo . owner } )
321
+ suborgRepoConfig = Object . assign ( suborgRepoConfig , { name : repo . repo , org : repo . owner } )
321
322
repoConfig = this . mergeDeep . mergeDeep ( { } , repoConfig , suborgRepoConfig )
322
323
}
323
324
}
@@ -328,45 +329,42 @@ ${this.results.reduce((x, y) => {
328
329
if ( overrideRepoConfig ) {
329
330
repoConfig = this . mergeDeep . mergeDeep ( { } , repoConfig , overrideRepoConfig )
330
331
}
331
- const { shouldContinue, nopCommands } = await new Archive ( this . nop , this . github , repo , repoConfig , this . log ) . sync ( )
332
- if ( nopCommands ) this . appendToResults ( nopCommands )
333
- if ( shouldContinue ) {
334
- if ( repoConfig ) {
335
- try {
336
- this . log . debug ( `found a matching repoconfig for this repo ${ JSON . stringify ( repoConfig ) } ` )
337
- const childPlugins = this . childPluginsList ( repo )
338
- const RepoPlugin = Settings . PLUGINS . repository
339
- return new RepoPlugin ( this . nop , this . github , repo , repoConfig , this . installation_id , this . log , this . errors ) . sync ( ) . then ( res => {
340
- this . appendToResults ( res )
341
- return Promise . all (
342
- childPlugins . map ( ( [ Plugin , config ] ) => {
343
- return new Plugin ( this . nop , this . github , repo , config , this . log , this . errors ) . sync ( )
344
- } ) )
345
- } ) . then ( res => {
346
- this . appendToResults ( res )
347
- } )
348
- } catch ( e ) {
349
- if ( this . nop ) {
350
- const nopcommand = new NopCommand ( this . constructor . name , this . repo , null , `${ e } ` , 'ERROR' )
351
- this . log . error ( `NOPCOMMAND ${ JSON . stringify ( nopcommand ) } ` )
352
- this . appendToResults ( [ nopcommand ] )
353
- // throw e
354
- } else {
355
- throw e
356
- }
357
- }
358
- } else {
359
- this . log . debug ( `Didnt find any a matching repoconfig for this repo ${ JSON . stringify ( repo ) } in ${ JSON . stringify ( this . repoConfigs ) } ` )
332
+ if ( repoConfig ) {
333
+ try {
334
+ this . log . debug ( `found a matching repoconfig for this repo ${ JSON . stringify ( repoConfig ) } ` )
360
335
const childPlugins = this . childPluginsList ( repo )
361
- return Promise . all ( childPlugins . map ( ( [ Plugin , config ] ) => {
362
- return new Plugin ( this . nop , this . github , repo , config , this . log , this . errors ) . sync ( ) . then ( res => {
363
- this . appendToResults ( res )
364
- } )
365
- } ) )
336
+ const RepoPlugin = Settings . PLUGINS . repository
337
+ return new RepoPlugin ( this . nop , this . github , repo , repoConfig , this . installation_id , this . log , this . errors ) . sync ( ) . then ( res => {
338
+ this . appendToResults ( res )
339
+ return Promise . all (
340
+ childPlugins . map ( ( [ Plugin , config ] ) => {
341
+ return new Plugin ( this . nop , this . github , repo , config , this . log , this . errors ) . sync ( )
342
+ } ) )
343
+ } ) . then ( res => {
344
+ this . appendToResults ( res )
345
+ } )
346
+ } catch ( e ) {
347
+ if ( this . nop ) {
348
+ const nopcommand = new NopCommand ( this . constructor . name , this . repo , null , `${ e } ` , 'ERROR' )
349
+ this . log . error ( `NOPCOMMAND ${ JSON . stringify ( nopcommand ) } ` )
350
+ this . appendToResults ( [ nopcommand ] )
351
+ // throw e
352
+ } else {
353
+ throw e
354
+ }
366
355
}
356
+ } else {
357
+ this . log . debug ( `Didnt find any a matching repoconfig for this repo ${ JSON . stringify ( repo ) } in ${ JSON . stringify ( this . repoConfigs ) } ` )
358
+ const childPlugins = this . childPluginsList ( repo )
359
+ return Promise . all ( childPlugins . map ( ( [ Plugin , config ] ) => {
360
+ return new Plugin ( this . nop , this . github , repo , config , this . log , this . errors ) . sync ( ) . then ( res => {
361
+ this . appendToResults ( res )
362
+ } )
363
+ } ) )
367
364
}
368
365
}
369
366
367
+
370
368
async updateAll ( ) {
371
369
// this.subOrgConfigs = this.subOrgConfigs || await this.getSubOrgConfigs(this.github, this.repo, this.log)
372
370
// this.repoConfigs = this.repoConfigs || await this.getRepoConfigs(this.github, this.repo, this.log)
@@ -487,47 +485,17 @@ ${this.results.reduce((x, y) => {
487
485
488
486
async eachRepositoryRepos ( github , log ) {
489
487
log . debug ( 'Fetching repositories' )
490
-
491
- const processedRepos = new Set ( )
492
- const results = [ ]
493
-
494
- // Process existing repositories
495
- const existingRepoResults = await github . paginate ( 'GET /installation/repositories' )
496
- . then ( repositories => {
497
- return Promise . all ( repositories . map ( repository => {
498
- if ( this . isRestricted ( repository . name ) ) {
499
- return null
500
- }
501
- const { owner, name } = repository
502
- processedRepos . add ( `${ owner . login } /${ name } ` )
503
- return this . updateRepos ( { owner : owner . login , repo : name } )
504
- } ) )
505
- } )
506
-
507
- // Process missing repositories
508
- const repoInConfigs = Object . values ( this . repoConfigs )
509
- . filter ( config => config . repository ?. name )
510
- . map ( config => {
511
- return {
512
- name : config . repository . name ,
513
- owner : config . repository . organization || this . repo . owner
488
+ return github . paginate ( 'GET /installation/repositories' ) . then ( repositories => {
489
+ return Promise . all ( repositories . map ( repository => {
490
+ if ( this . isRestricted ( repository . name ) ) {
491
+ return null
514
492
}
515
- } )
516
- const missingRepoResults = await Promise . all (
517
- repoInConfigs
518
- . filter ( repo => ! this . isRestricted ( repo . name ) )
519
- . filter ( repo => ! processedRepos . has ( `${ repo . owner } /${ repo . name } ` ) )
520
- . map ( repo => {
521
- processedRepos . add ( `${ repo . owner } /${ repo . name } ` )
522
- return this . updateRepos ( { owner : repo . owner , repo : repo . name } )
523
- } )
524
- )
525
-
526
- results
527
- . concat ( existingRepoResults || [ ] , missingRepoResults || [ ] )
528
- . filter ( result => result !== null )
529
493
530
- return results
494
+ const { owner, name } = repository
495
+ return this . updateRepos ( { owner : owner . login , repo : name } )
496
+ } )
497
+ )
498
+ } )
531
499
}
532
500
533
501
/**
@@ -790,7 +758,7 @@ ${this.results.reduce((x, y) => {
790
758
}
791
759
) ) {
792
760
delete subOrgConfigs [ key ]
793
- }
761
+ }
794
762
}
795
763
}
796
764
return subOrgConfigs
@@ -894,6 +862,7 @@ ${this.results.reduce((x, y) => {
894
862
throw new Error ( `Failed to filter repositories for property ${ name } : ${ error . message } ` )
895
863
}
896
864
}
865
+
897
866
898
867
async getSubOrgRepositories ( subOrgProperties ) {
899
868
const organizationName = this . repo . owner
@@ -940,6 +909,7 @@ function prettify (obj) {
940
909
return JSON . stringify ( obj , null , 2 ) . replaceAll ( '\n' , '<br>' ) . replaceAll ( ' ' , ' ' )
941
910
}
942
911
912
+ Settings . FILE_NAME = path . posix . join ( CONFIG_PATH , env . SETTINGS_FILE_PATH )
943
913
Settings . FILE_PATH = path . posix . join ( CONFIG_PATH , env . SETTINGS_FILE_PATH )
944
914
Settings . SUB_ORG_PATTERN = new Glob ( `${ CONFIG_PATH } /suborgs/*.yml` )
945
915
Settings . REPO_PATTERN = new Glob ( `${ CONFIG_PATH } /repos/*.yml` )
0 commit comments