@@ -169,10 +169,10 @@ class Settings {
169169
170170 // remove duplicate rows in this.results
171171 this . results = this . results . filter ( ( thing , index , self ) => {
172- return index === self . findIndex ( ( t ) => {
173- return t . type === thing . type && t . repo === thing . repo && t . plugin === thing . plugin
172+ return index === self . findIndex ( ( t ) => {
173+ return t . type === thing . type && t . repo === thing . repo && t . plugin === thing . plugin
174+ } )
174175 } )
175- } )
176176
177177 let error = false
178178 // Different logic
@@ -299,12 +299,13 @@ ${this.results.reduce((x, y) => {
299299 }
300300 }
301301
302- async updateRepos ( repo ) {
302+ async updateRepos ( repo ) {
303303 this . subOrgConfigs = this . subOrgConfigs || await this . getSubOrgConfigs ( )
304- // Create a fresh copy of the base repository config
305- let repoConfig = this . config . repository ? Object . assign ( { } , this . config . repository ) : { }
304+ // Keeping this as is instead of doing an object assign as that would cause `Cannot read properties of undefined (reading 'startsWith')` error
305+ // Copilot code review would recoommend using object assign but that would cause the error
306+ let repoConfig = this . config . repository
306307 if ( repoConfig ) {
307- repoConfig = Object . assign ( { } , repoConfig , { name : repo . repo , org : repo . owner } )
308+ repoConfig = Object . assign ( repoConfig , { name : repo . repo , org : repo . owner } )
308309 }
309310
310311 const subOrgConfig = this . getSubOrgConfig ( repo . repo )
@@ -318,9 +319,9 @@ ${this.results.reduce((x, y) => {
318319 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 ) } ` )
319320
320321 if ( subOrgConfig ) {
321- let suborgRepoConfig = subOrgConfig . repository ? Object . assign ( { } , subOrgConfig . repository ) : { }
322+ let suborgRepoConfig = subOrgConfig . repository
322323 if ( suborgRepoConfig ) {
323- suborgRepoConfig = Object . assign ( { } , suborgRepoConfig , { name : repo . repo , org : repo . owner } )
324+ suborgRepoConfig = Object . assign ( suborgRepoConfig , { name : repo . repo , org : repo . owner } )
324325 repoConfig = this . mergeDeep . mergeDeep ( { } , repoConfig , suborgRepoConfig )
325326 }
326327 }
@@ -331,45 +332,42 @@ ${this.results.reduce((x, y) => {
331332 if ( overrideRepoConfig ) {
332333 repoConfig = this . mergeDeep . mergeDeep ( { } , repoConfig , overrideRepoConfig )
333334 }
334- const { shouldContinue, nopCommands } = await new Archive ( this . nop , this . github , repo , repoConfig , this . log ) . sync ( )
335- if ( nopCommands ) this . appendToResults ( nopCommands )
336- if ( shouldContinue ) {
337- if ( repoConfig ) {
338- try {
339- this . log . debug ( `found a matching repoconfig for this repo ${ JSON . stringify ( repoConfig ) } ` )
340- const childPlugins = this . childPluginsList ( repo )
341- const RepoPlugin = Settings . PLUGINS . repository
342- return new RepoPlugin ( this . nop , this . github , repo , repoConfig , this . installation_id , this . log , this . errors ) . sync ( ) . then ( res => {
343- this . appendToResults ( res )
344- return Promise . all (
345- childPlugins . map ( ( [ Plugin , config ] ) => {
346- return new Plugin ( this . nop , this . github , repo , config , this . log , this . errors ) . sync ( )
347- } ) )
348- } ) . then ( res => {
349- this . appendToResults ( res )
350- } )
351- } catch ( e ) {
352- if ( this . nop ) {
353- const nopcommand = new NopCommand ( this . constructor . name , this . repo , null , `${ e } ` , 'ERROR' )
354- this . log . error ( `NOPCOMMAND ${ JSON . stringify ( nopcommand ) } ` )
355- this . appendToResults ( [ nopcommand ] )
356- // throw e
357- } else {
358- throw e
359- }
360- }
361- } else {
362- this . log . debug ( `Didnt find any a matching repoconfig for this repo ${ JSON . stringify ( repo ) } in ${ JSON . stringify ( this . repoConfigs ) } ` )
335+ if ( repoConfig ) {
336+ try {
337+ this . log . debug ( `found a matching repoconfig for this repo ${ JSON . stringify ( repoConfig ) } ` )
363338 const childPlugins = this . childPluginsList ( repo )
364- return Promise . all ( childPlugins . map ( ( [ Plugin , config ] ) => {
365- return new Plugin ( this . nop , this . github , repo , config , this . log , this . errors ) . sync ( ) . then ( res => {
366- this . appendToResults ( res )
367- } )
368- } ) )
339+ const RepoPlugin = Settings . PLUGINS . repository
340+ return new RepoPlugin ( this . nop , this . github , repo , repoConfig , this . installation_id , this . log , this . errors ) . sync ( ) . then ( res => {
341+ this . appendToResults ( res )
342+ return Promise . all (
343+ childPlugins . map ( ( [ Plugin , config ] ) => {
344+ return new Plugin ( this . nop , this . github , repo , config , this . log , this . errors ) . sync ( )
345+ } ) )
346+ } ) . then ( res => {
347+ this . appendToResults ( res )
348+ } )
349+ } catch ( e ) {
350+ if ( this . nop ) {
351+ const nopcommand = new NopCommand ( this . constructor . name , this . repo , null , `${ e } ` , 'ERROR' )
352+ this . log . error ( `NOPCOMMAND ${ JSON . stringify ( nopcommand ) } ` )
353+ this . appendToResults ( [ nopcommand ] )
354+ // throw e
355+ } else {
356+ throw e
357+ }
369358 }
359+ } else {
360+ this . log . debug ( `Didnt find any a matching repoconfig for this repo ${ JSON . stringify ( repo ) } in ${ JSON . stringify ( this . repoConfigs ) } ` )
361+ const childPlugins = this . childPluginsList ( repo )
362+ return Promise . all ( childPlugins . map ( ( [ Plugin , config ] ) => {
363+ return new Plugin ( this . nop , this . github , repo , config , this . log , this . errors ) . sync ( ) . then ( res => {
364+ this . appendToResults ( res )
365+ } )
366+ } ) )
370367 }
371368 }
372369
370+
373371 async updateAll ( ) {
374372 // this.subOrgConfigs = this.subOrgConfigs || await this.getSubOrgConfigs(this.github, this.repo, this.log)
375373 // this.repoConfigs = this.repoConfigs || await this.getRepoConfigs(this.github, this.repo, this.log)
@@ -490,47 +488,17 @@ ${this.results.reduce((x, y) => {
490488
491489 async eachRepositoryRepos ( github , log ) {
492490 log . debug ( 'Fetching repositories' )
493-
494- const processedRepos = new Set ( )
495- const results = [ ]
496-
497- // Process existing repositories
498- const existingRepoResults = await github . paginate ( 'GET /installation/repositories' )
499- . then ( repositories => {
500- return Promise . all ( repositories . map ( repository => {
501- if ( this . isRestricted ( repository . name ) ) {
502- return null
503- }
504- const { owner, name } = repository
505- processedRepos . add ( `${ owner . login } /${ name } ` )
506- return this . updateRepos ( { owner : owner . login , repo : name } )
507- } ) )
508- } )
509-
510- // Process missing repositories
511- const repoInConfigs = Object . values ( this . repoConfigs )
512- . filter ( config => config . repository ?. name )
513- . map ( config => {
514- return {
515- name : config . repository . name ,
516- owner : config . repository . organization || this . repo . owner
491+ return github . paginate ( 'GET /installation/repositories' ) . then ( repositories => {
492+ return Promise . all ( repositories . map ( repository => {
493+ if ( this . isRestricted ( repository . name ) ) {
494+ return null
517495 }
518- } )
519- const missingRepoResults = await Promise . all (
520- repoInConfigs
521- . filter ( repo => ! this . isRestricted ( repo . name ) )
522- . filter ( repo => ! processedRepos . has ( `${ repo . owner } /${ repo . name } ` ) )
523- . map ( repo => {
524- processedRepos . add ( `${ repo . owner } /${ repo . name } ` )
525- return this . updateRepos ( { owner : repo . owner , repo : repo . name } )
526- } )
527- )
528-
529- results
530- . concat ( existingRepoResults || [ ] , missingRepoResults || [ ] )
531- . filter ( result => result !== null )
532496
533- return results
497+ const { owner, name } = repository
498+ return this . updateRepos ( { owner : owner . login , repo : name } )
499+ } )
500+ )
501+ } )
534502 }
535503
536504 /**
@@ -793,7 +761,7 @@ ${this.results.reduce((x, y) => {
793761 }
794762 ) ) {
795763 delete subOrgConfigs [ key ]
796- }
764+ }
797765 }
798766 }
799767 return subOrgConfigs
@@ -897,6 +865,7 @@ ${this.results.reduce((x, y) => {
897865 throw new Error ( `Failed to filter repositories for property ${ name } : ${ error . message } ` )
898866 }
899867 }
868+
900869
901870 async getSubOrgRepositories ( subOrgProperties ) {
902871 const organizationName = this . repo . owner
@@ -943,6 +912,7 @@ function prettify (obj) {
943912 return JSON . stringify ( obj , null , 2 ) . replaceAll ( '\n' , '<br>' ) . replaceAll ( ' ' , ' ' )
944913}
945914
915+ Settings . FILE_NAME = path . posix . join ( CONFIG_PATH , env . SETTINGS_FILE_PATH )
946916Settings . FILE_PATH = path . posix . join ( CONFIG_PATH , env . SETTINGS_FILE_PATH )
947917Settings . SUB_ORG_PATTERN = new Glob ( `${ CONFIG_PATH } /suborgs/*.yml` )
948918Settings . REPO_PATTERN = new Glob ( `${ CONFIG_PATH } /repos/*.yml` )
0 commit comments