@@ -26,7 +26,7 @@ class Settings {
26
26
return settings
27
27
}
28
28
29
- static async syncSubOrgs ( nop , context , suborg , repo , config , ref ) {
29
+ static async syncSubOrgs ( nop , context , suborg , repo , config , ref ) {
30
30
const settings = new Settings ( nop , context , repo , config , ref , suborg )
31
31
try {
32
32
await settings . loadConfigs ( )
@@ -38,7 +38,7 @@ class Settings {
38
38
}
39
39
}
40
40
41
- static async sync ( nop , context , repo , config , ref ) {
41
+ static async sync ( nop , context , repo , config , ref ) {
42
42
const settings = new Settings ( nop , context , repo , config , ref )
43
43
try {
44
44
await settings . loadConfigs ( repo )
@@ -53,13 +53,13 @@ class Settings {
53
53
}
54
54
}
55
55
56
- static async handleError ( nop , context , repo , config , ref , nopcommand ) {
56
+ static async handleError ( nop , context , repo , config , ref , nopcommand ) {
57
57
const settings = new Settings ( nop , context , repo , config , ref )
58
58
settings . appendToResults ( [ nopcommand ] )
59
59
await settings . handleResults ( )
60
60
}
61
61
62
- constructor ( nop , context , repo , config , ref , suborg ) {
62
+ constructor ( nop , context , repo , config , ref , suborg ) {
63
63
this . ref = ref
64
64
this . context = context
65
65
this . installation_id = context . payload . installation . id
@@ -98,7 +98,7 @@ class Settings {
98
98
}
99
99
100
100
// Create a check in the Admin repo for safe-settings.
101
- async createCheckRun ( ) {
101
+ async createCheckRun ( ) {
102
102
const startTime = new Date ( )
103
103
let conclusion = 'success'
104
104
let details = `Run on: \`${ new Date ( ) . toISOString ( ) } \``
@@ -144,7 +144,7 @@ class Settings {
144
144
} )
145
145
}
146
146
147
- logError ( msg ) {
147
+ logError ( msg ) {
148
148
this . log . error ( msg )
149
149
this . errors . push ( {
150
150
owner : this . repo . owner ,
@@ -154,7 +154,7 @@ class Settings {
154
154
} )
155
155
}
156
156
157
- async handleResults ( ) {
157
+ async handleResults ( ) {
158
158
const { payload } = this . context
159
159
160
160
// Create a checkrun if not in nop mode
@@ -164,12 +164,12 @@ class Settings {
164
164
return
165
165
}
166
166
167
- //remove duplicate rows in this.results
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
171
- } )
169
+ return index === self . findIndex ( ( t ) => {
170
+ return t . type === thing . type && t . repo === thing . repo && t . plugin === thing . plugin
172
171
} )
172
+ } )
173
173
174
174
let error = false
175
175
// Different logic
@@ -281,12 +281,12 @@ ${this.results.reduce((x, y) => {
281
281
await this . github . checks . update ( params )
282
282
}
283
283
284
- async loadConfigs ( repo ) {
284
+ async loadConfigs ( repo ) {
285
285
this . subOrgConfigs = await this . getSubOrgConfigs ( )
286
286
this . repoConfigs = await this . getRepoConfigs ( repo )
287
287
}
288
288
289
- async updateOrg ( ) {
289
+ async updateOrg ( ) {
290
290
const rulesetsConfig = this . config . rulesets
291
291
if ( rulesetsConfig ) {
292
292
const RulesetsPlugin = Settings . PLUGINS . rulesets
@@ -296,11 +296,12 @@ ${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
- 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 ) : { }
302
303
if ( repoConfig ) {
303
- repoConfig = Object . assign ( repoConfig , { name : repo . repo , org : repo . owner } )
304
+ repoConfig = Object . assign ( { } , repoConfig , { name : repo . repo , org : repo . owner } )
304
305
}
305
306
306
307
const subOrgConfig = this . getSubOrgConfig ( repo . repo )
@@ -314,9 +315,9 @@ ${this.results.reduce((x, y) => {
314
315
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 ) } ` )
315
316
316
317
if ( subOrgConfig ) {
317
- let suborgRepoConfig = subOrgConfig . repository
318
+ let suborgRepoConfig = subOrgConfig . repository ? Object . assign ( { } , subOrgConfig . repository ) : { }
318
319
if ( suborgRepoConfig ) {
319
- suborgRepoConfig = Object . assign ( suborgRepoConfig , { name : repo . repo , org : repo . owner } )
320
+ suborgRepoConfig = Object . assign ( { } , suborgRepoConfig , { name : repo . repo , org : repo . owner } )
320
321
repoConfig = this . mergeDeep . mergeDeep ( { } , repoConfig , suborgRepoConfig )
321
322
}
322
323
}
@@ -327,7 +328,7 @@ ${this.results.reduce((x, y) => {
327
328
if ( overrideRepoConfig ) {
328
329
repoConfig = this . mergeDeep . mergeDeep ( { } , repoConfig , overrideRepoConfig )
329
330
}
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 ( )
331
332
if ( nopCommands ) this . appendToResults ( nopCommands )
332
333
if ( shouldContinue ) {
333
334
if ( repoConfig ) {
@@ -366,15 +367,15 @@ ${this.results.reduce((x, y) => {
366
367
}
367
368
}
368
369
369
- async updateAll ( ) {
370
+ async updateAll ( ) {
370
371
// this.subOrgConfigs = this.subOrgConfigs || await this.getSubOrgConfigs(this.github, this.repo, this.log)
371
372
// this.repoConfigs = this.repoConfigs || await this.getRepoConfigs(this.github, this.repo, this.log)
372
373
return this . eachRepositoryRepos ( this . github , this . log ) . then ( res => {
373
374
this . appendToResults ( res )
374
375
} )
375
376
}
376
377
377
- getSubOrgConfig ( repoName ) {
378
+ getSubOrgConfig ( repoName ) {
378
379
if ( this . subOrgConfigs ) {
379
380
for ( const k of Object . keys ( this . subOrgConfigs ) ) {
380
381
const repoPattern = new Glob ( k )
@@ -387,13 +388,13 @@ ${this.results.reduce((x, y) => {
387
388
}
388
389
389
390
// Remove Org specific configs from the repo config
390
- returnRepoSpecificConfigs ( config ) {
391
+ returnRepoSpecificConfigs ( config ) {
391
392
const newConfig = Object . assign ( { } , config ) // clone
392
393
delete newConfig . rulesets
393
394
return newConfig
394
395
}
395
396
396
- childPluginsList ( repo ) {
397
+ childPluginsList ( repo ) {
397
398
const repoName = repo . repo
398
399
const subOrgOverrideConfig = this . getSubOrgConfig ( repoName )
399
400
this . log . debug ( `suborg config for ${ repoName } is ${ JSON . stringify ( subOrgOverrideConfig ) } ` )
@@ -425,11 +426,11 @@ ${this.results.reduce((x, y) => {
425
426
return childPlugins
426
427
}
427
428
428
- getRepoOverrideConfig ( repoName ) {
429
+ getRepoOverrideConfig ( repoName ) {
429
430
return this . repoConfigs [ `${ repoName } .yml` ] || this . repoConfigs [ `${ repoName } .yaml` ] || { }
430
431
}
431
432
432
- validate ( section , baseConfig , overrideConfig ) {
433
+ validate ( section , baseConfig , overrideConfig ) {
433
434
const configValidator = this . configvalidators [ section ]
434
435
if ( configValidator ) {
435
436
this . log . debug ( `Calling configvalidator for key ${ section } ` )
@@ -448,7 +449,7 @@ ${this.results.reduce((x, y) => {
448
449
}
449
450
}
450
451
451
- isRestricted ( repoName ) {
452
+ isRestricted ( repoName ) {
452
453
const restrictedRepos = this . config . restrictedRepos
453
454
// Skip configuring any restricted repos
454
455
if ( Array . isArray ( restrictedRepos ) ) {
@@ -480,7 +481,7 @@ ${this.results.reduce((x, y) => {
480
481
return false
481
482
}
482
483
483
- includesRepo ( repoName , restrictedRepos ) {
484
+ includesRepo ( repoName , restrictedRepos ) {
484
485
return restrictedRepos . filter ( ( restrictedRepo ) => { return RegExp ( restrictedRepo ) . test ( repoName ) } ) . length > 0
485
486
}
486
487
@@ -535,7 +536,7 @@ ${this.results.reduce((x, y) => {
535
536
* @param params Params to fetch the file with
536
537
* @return The parsed YAML file
537
538
*/
538
- async loadConfigMap ( params ) {
539
+ async loadConfigMap ( params ) {
539
540
try {
540
541
this . log . debug ( ` In loadConfigMap ${ JSON . stringify ( params ) } ` )
541
542
const response = await this . github . repos . getContent ( params ) . catch ( e => {
@@ -582,7 +583,7 @@ ${this.results.reduce((x, y) => {
582
583
* @param params Params to fetch the file with
583
584
* @return The parsed YAML file
584
585
*/
585
- async getRepoConfigMap ( ) {
586
+ async getRepoConfigMap ( ) {
586
587
try {
587
588
this . log . debug ( ` In getRepoConfigMap ${ JSON . stringify ( this . repo ) } ` )
588
589
// GitHub getContent api has a hard limit of returning 1000 entries without
@@ -649,7 +650,7 @@ ${this.results.reduce((x, y) => {
649
650
* @param params Params to fetch the file with
650
651
* @return The parsed YAML file
651
652
*/
652
- async getSubOrgConfigMap ( ) {
653
+ async getSubOrgConfigMap ( ) {
653
654
try {
654
655
this . log . debug ( ` In getSubOrgConfigMap ${ JSON . stringify ( this . repo ) } ` )
655
656
const repo = { owner : this . repo . owner , repo : env . ADMIN_REPO }
@@ -676,7 +677,7 @@ ${this.results.reduce((x, y) => {
676
677
* @param {* } repo repo param
677
678
* @returns repoConfigs object
678
679
*/
679
- async getRepoConfigs ( repo ) {
680
+ async getRepoConfigs ( repo ) {
680
681
try {
681
682
const overridePaths = await this . getRepoConfigMap ( )
682
683
const repoConfigs = { }
@@ -728,7 +729,7 @@ ${this.results.reduce((x, y) => {
728
729
* @param params Params to fetch the file with
729
730
* @return The parsed YAML file
730
731
*/
731
- async getSubOrgConfigs ( ) {
732
+ async getSubOrgConfigs ( ) {
732
733
try {
733
734
// Get all suborg configs even though we might be here becuase of a suborg config change
734
735
// we will filter them out if request is due to a suborg config change
@@ -805,7 +806,7 @@ ${this.results.reduce((x, y) => {
805
806
}
806
807
}
807
808
808
- storeSubOrgConfigIfNoConflicts ( subOrgConfigs , overridePath , repoName , data ) {
809
+ storeSubOrgConfigIfNoConflicts ( subOrgConfigs , overridePath , repoName , data ) {
809
810
const existingConfigForRepo = subOrgConfigs [ repoName ]
810
811
if ( existingConfigForRepo && existingConfigForRepo . source !== overridePath ) {
811
812
throw new Error ( `Multiple suborg configs for ${ repoName } in ${ overridePath } and ${ existingConfigForRepo ?. source } ` )
@@ -819,7 +820,7 @@ ${this.results.reduce((x, y) => {
819
820
* @param params Params to fetch the file with
820
821
* @return The parsed YAML file
821
822
*/
822
- async loadYaml ( filePath ) {
823
+ async loadYaml ( filePath ) {
823
824
try {
824
825
const repo = { owner : this . repo . owner , repo : env . ADMIN_REPO }
825
826
const params = Object . assign ( repo , { path : filePath , ref : this . ref } )
@@ -867,7 +868,7 @@ ${this.results.reduce((x, y) => {
867
868
this . results = this . results . concat ( results )
868
869
}
869
870
870
- async getReposForTeam ( teamslug ) {
871
+ async getReposForTeam ( teamslug ) {
871
872
const options = this . github . rest . teams . listReposInOrg . endpoint . merge ( {
872
873
org : this . repo . owner ,
873
874
team_slug : teamslug ,
@@ -893,7 +894,6 @@ ${this.results.reduce((x, y) => {
893
894
throw new Error ( `Failed to filter repositories for property ${ name } : ${ error . message } ` )
894
895
}
895
896
}
896
-
897
897
898
898
async getSubOrgRepositories ( subOrgProperties ) {
899
899
const organizationName = this . repo . owner
@@ -924,7 +924,7 @@ ${this.results.reduce((x, y) => {
924
924
return ( item && typeof item === 'object' && ! Array . isArray ( item ) )
925
925
}
926
926
927
- isIterable ( obj ) {
927
+ isIterable ( obj ) {
928
928
// checks for null and undefined
929
929
if ( obj == null ) {
930
930
return false
0 commit comments