@@ -26,7 +26,7 @@ class Settings {
2626 return settings
2727 }
2828
29- static async syncSubOrgs ( nop , context , suborg , repo , config , ref ) {
29+ static async syncSubOrgs ( nop , context , suborg , repo , config , ref ) {
3030 const settings = new Settings ( nop , context , repo , config , ref , suborg )
3131 try {
3232 await settings . loadConfigs ( )
@@ -38,7 +38,7 @@ class Settings {
3838 }
3939 }
4040
41- static async sync ( nop , context , repo , config , ref ) {
41+ static async sync ( nop , context , repo , config , ref ) {
4242 const settings = new Settings ( nop , context , repo , config , ref )
4343 try {
4444 await settings . loadConfigs ( repo )
@@ -53,13 +53,13 @@ class Settings {
5353 }
5454 }
5555
56- static async handleError ( nop , context , repo , config , ref , nopcommand ) {
56+ static async handleError ( nop , context , repo , config , ref , nopcommand ) {
5757 const settings = new Settings ( nop , context , repo , config , ref )
5858 settings . appendToResults ( [ nopcommand ] )
5959 await settings . handleResults ( )
6060 }
6161
62- constructor ( nop , context , repo , config , ref , suborg ) {
62+ constructor ( nop , context , repo , config , ref , suborg ) {
6363 this . ref = ref
6464 this . context = context
6565 this . installation_id = context . payload . installation . id
@@ -98,7 +98,7 @@ class Settings {
9898 }
9999
100100 // Create a check in the Admin repo for safe-settings.
101- async createCheckRun ( ) {
101+ async createCheckRun ( ) {
102102 const startTime = new Date ( )
103103 let conclusion = 'success'
104104 let details = `Run on: \`${ new Date ( ) . toISOString ( ) } \``
@@ -144,7 +144,7 @@ class Settings {
144144 } )
145145 }
146146
147- logError ( msg ) {
147+ logError ( msg ) {
148148 this . log . error ( msg )
149149 this . errors . push ( {
150150 owner : this . repo . owner ,
@@ -154,7 +154,7 @@ class Settings {
154154 } )
155155 }
156156
157- async handleResults ( ) {
157+ async handleResults ( ) {
158158 const { payload } = this . context
159159
160160 // Create a checkrun if not in nop mode
@@ -164,12 +164,12 @@ class Settings {
164164 return
165165 }
166166
167- //remove duplicate rows in this.results
167+ // remove duplicate rows in this.results
168168 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
171- } )
169+ return index === self . findIndex ( ( t ) => {
170+ return t . type === thing . type && t . repo === thing . repo && t . plugin === thing . plugin
172171 } )
172+ } )
173173
174174 let error = false
175175 // Different logic
@@ -281,12 +281,12 @@ ${this.results.reduce((x, y) => {
281281 await this . github . checks . update ( params )
282282 }
283283
284- async loadConfigs ( repo ) {
284+ async loadConfigs ( repo ) {
285285 this . subOrgConfigs = await this . getSubOrgConfigs ( )
286286 this . repoConfigs = await this . getRepoConfigs ( repo )
287287 }
288288
289- async updateOrg ( ) {
289+ async updateOrg ( ) {
290290 const rulesetsConfig = this . config . rulesets
291291 if ( rulesetsConfig ) {
292292 const RulesetsPlugin = Settings . PLUGINS . rulesets
@@ -296,11 +296,12 @@ ${this.results.reduce((x, y) => {
296296 }
297297 }
298298
299- async updateRepos ( repo ) {
299+ async updateRepos ( repo ) {
300300 this . subOrgConfigs = this . subOrgConfigs || await this . getSubOrgConfigs ( )
301- let repoConfig = this . config . repository
301+ // Create a fresh copy of the base repository config
302+ let repoConfig = this . config . repository ? Object . assign ( { } , this . config . repository ) : { }
302303 if ( repoConfig ) {
303- repoConfig = Object . assign ( repoConfig , { name : repo . repo , org : repo . owner } )
304+ repoConfig = Object . assign ( { } , repoConfig , { name : repo . repo , org : repo . owner } )
304305 }
305306
306307 const subOrgConfig = this . getSubOrgConfig ( repo . repo )
@@ -314,9 +315,9 @@ ${this.results.reduce((x, y) => {
314315 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 ) } ` )
315316
316317 if ( subOrgConfig ) {
317- let suborgRepoConfig = subOrgConfig . repository
318+ let suborgRepoConfig = subOrgConfig . repository ? Object . assign ( { } , subOrgConfig . repository ) : { }
318319 if ( suborgRepoConfig ) {
319- suborgRepoConfig = Object . assign ( suborgRepoConfig , { name : repo . repo , org : repo . owner } )
320+ suborgRepoConfig = Object . assign ( { } , suborgRepoConfig , { name : repo . repo , org : repo . owner } )
320321 repoConfig = this . mergeDeep . mergeDeep ( { } , repoConfig , suborgRepoConfig )
321322 }
322323 }
@@ -327,7 +328,7 @@ ${this.results.reduce((x, y) => {
327328 if ( overrideRepoConfig ) {
328329 repoConfig = this . mergeDeep . mergeDeep ( { } , repoConfig , overrideRepoConfig )
329330 }
330- const { shouldContinue, nopCommands} = await new Archive ( this . nop , this . github , repo , repoConfig , this . log ) . sync ( )
331+ const { shouldContinue, nopCommands } = await new Archive ( this . nop , this . github , repo , repoConfig , this . log ) . sync ( )
331332 if ( nopCommands ) this . appendToResults ( nopCommands )
332333 if ( shouldContinue ) {
333334 if ( repoConfig ) {
@@ -366,15 +367,15 @@ ${this.results.reduce((x, y) => {
366367 }
367368 }
368369
369- async updateAll ( ) {
370+ async updateAll ( ) {
370371 // this.subOrgConfigs = this.subOrgConfigs || await this.getSubOrgConfigs(this.github, this.repo, this.log)
371372 // this.repoConfigs = this.repoConfigs || await this.getRepoConfigs(this.github, this.repo, this.log)
372373 return this . eachRepositoryRepos ( this . github , this . log ) . then ( res => {
373374 this . appendToResults ( res )
374375 } )
375376 }
376377
377- getSubOrgConfig ( repoName ) {
378+ getSubOrgConfig ( repoName ) {
378379 if ( this . subOrgConfigs ) {
379380 for ( const k of Object . keys ( this . subOrgConfigs ) ) {
380381 const repoPattern = new Glob ( k )
@@ -387,13 +388,13 @@ ${this.results.reduce((x, y) => {
387388 }
388389
389390 // Remove Org specific configs from the repo config
390- returnRepoSpecificConfigs ( config ) {
391+ returnRepoSpecificConfigs ( config ) {
391392 const newConfig = Object . assign ( { } , config ) // clone
392393 delete newConfig . rulesets
393394 return newConfig
394395 }
395396
396- childPluginsList ( repo ) {
397+ childPluginsList ( repo ) {
397398 const repoName = repo . repo
398399 const subOrgOverrideConfig = this . getSubOrgConfig ( repoName )
399400 this . log . debug ( `suborg config for ${ repoName } is ${ JSON . stringify ( subOrgOverrideConfig ) } ` )
@@ -425,11 +426,11 @@ ${this.results.reduce((x, y) => {
425426 return childPlugins
426427 }
427428
428- getRepoOverrideConfig ( repoName ) {
429+ getRepoOverrideConfig ( repoName ) {
429430 return this . repoConfigs [ `${ repoName } .yml` ] || this . repoConfigs [ `${ repoName } .yaml` ] || { }
430431 }
431432
432- validate ( section , baseConfig , overrideConfig ) {
433+ validate ( section , baseConfig , overrideConfig ) {
433434 const configValidator = this . configvalidators [ section ]
434435 if ( configValidator ) {
435436 this . log . debug ( `Calling configvalidator for key ${ section } ` )
@@ -448,7 +449,7 @@ ${this.results.reduce((x, y) => {
448449 }
449450 }
450451
451- isRestricted ( repoName ) {
452+ isRestricted ( repoName ) {
452453 const restrictedRepos = this . config . restrictedRepos
453454 // Skip configuring any restricted repos
454455 if ( Array . isArray ( restrictedRepos ) ) {
@@ -480,7 +481,7 @@ ${this.results.reduce((x, y) => {
480481 return false
481482 }
482483
483- includesRepo ( repoName , restrictedRepos ) {
484+ includesRepo ( repoName , restrictedRepos ) {
484485 return restrictedRepos . filter ( ( restrictedRepo ) => { return RegExp ( restrictedRepo ) . test ( repoName ) } ) . length > 0
485486 }
486487
@@ -535,7 +536,7 @@ ${this.results.reduce((x, y) => {
535536 * @param params Params to fetch the file with
536537 * @return The parsed YAML file
537538 */
538- async loadConfigMap ( params ) {
539+ async loadConfigMap ( params ) {
539540 try {
540541 this . log . debug ( ` In loadConfigMap ${ JSON . stringify ( params ) } ` )
541542 const response = await this . github . repos . getContent ( params ) . catch ( e => {
@@ -582,7 +583,7 @@ ${this.results.reduce((x, y) => {
582583 * @param params Params to fetch the file with
583584 * @return The parsed YAML file
584585 */
585- async getRepoConfigMap ( ) {
586+ async getRepoConfigMap ( ) {
586587 try {
587588 this . log . debug ( ` In getRepoConfigMap ${ JSON . stringify ( this . repo ) } ` )
588589 // GitHub getContent api has a hard limit of returning 1000 entries without
@@ -649,7 +650,7 @@ ${this.results.reduce((x, y) => {
649650 * @param params Params to fetch the file with
650651 * @return The parsed YAML file
651652 */
652- async getSubOrgConfigMap ( ) {
653+ async getSubOrgConfigMap ( ) {
653654 try {
654655 this . log . debug ( ` In getSubOrgConfigMap ${ JSON . stringify ( this . repo ) } ` )
655656 const repo = { owner : this . repo . owner , repo : env . ADMIN_REPO }
@@ -676,7 +677,7 @@ ${this.results.reduce((x, y) => {
676677 * @param {* } repo repo param
677678 * @returns repoConfigs object
678679 */
679- async getRepoConfigs ( repo ) {
680+ async getRepoConfigs ( repo ) {
680681 try {
681682 const overridePaths = await this . getRepoConfigMap ( )
682683 const repoConfigs = { }
@@ -728,7 +729,7 @@ ${this.results.reduce((x, y) => {
728729 * @param params Params to fetch the file with
729730 * @return The parsed YAML file
730731 */
731- async getSubOrgConfigs ( ) {
732+ async getSubOrgConfigs ( ) {
732733 try {
733734 // Get all suborg configs even though we might be here becuase of a suborg config change
734735 // we will filter them out if request is due to a suborg config change
@@ -805,7 +806,7 @@ ${this.results.reduce((x, y) => {
805806 }
806807 }
807808
808- storeSubOrgConfigIfNoConflicts ( subOrgConfigs , overridePath , repoName , data ) {
809+ storeSubOrgConfigIfNoConflicts ( subOrgConfigs , overridePath , repoName , data ) {
809810 const existingConfigForRepo = subOrgConfigs [ repoName ]
810811 if ( existingConfigForRepo && existingConfigForRepo . source !== overridePath ) {
811812 throw new Error ( `Multiple suborg configs for ${ repoName } in ${ overridePath } and ${ existingConfigForRepo ?. source } ` )
@@ -819,7 +820,7 @@ ${this.results.reduce((x, y) => {
819820 * @param params Params to fetch the file with
820821 * @return The parsed YAML file
821822 */
822- async loadYaml ( filePath ) {
823+ async loadYaml ( filePath ) {
823824 try {
824825 const repo = { owner : this . repo . owner , repo : env . ADMIN_REPO }
825826 const params = Object . assign ( repo , { path : filePath , ref : this . ref } )
@@ -867,7 +868,7 @@ ${this.results.reduce((x, y) => {
867868 this . results = this . results . concat ( results )
868869 }
869870
870- async getReposForTeam ( teamslug ) {
871+ async getReposForTeam ( teamslug ) {
871872 const options = this . github . rest . teams . listReposInOrg . endpoint . merge ( {
872873 org : this . repo . owner ,
873874 team_slug : teamslug ,
@@ -893,7 +894,6 @@ ${this.results.reduce((x, y) => {
893894 throw new Error ( `Failed to filter repositories for property ${ name } : ${ error . message } ` )
894895 }
895896 }
896-
897897
898898 async getSubOrgRepositories ( subOrgProperties ) {
899899 const organizationName = this . repo . owner
@@ -924,7 +924,7 @@ ${this.results.reduce((x, y) => {
924924 return ( item && typeof item === 'object' && ! Array . isArray ( item ) )
925925 }
926926
927- isIterable ( obj ) {
927+ isIterable ( obj ) {
928928 // checks for null and undefined
929929 if ( obj == null ) {
930930 return false
0 commit comments