forked from github/safe-settings
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings.js
704 lines (648 loc) · 24.1 KB
/
settings.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
const path = require('path')
const eta = require('eta')
const Glob = require('./glob')
const NopCommand = require('./nopcommand')
const MergeDeep = require('./mergeDeep')
const env = require('./env')
const CONFIG_PATH = env.CONFIG_PATH
class Settings {
static async syncAll (nop, context, repo, config, ref) {
const settings = new Settings(nop, context, repo, config, ref)
await settings.loadConfigs()
// settings.repoConfigs = await settings.getRepoConfigs()
await settings.updateAll()
await settings.handleResults()
}
static async syncSubOrgs (nop, context, suborg, repo, config, ref) {
const settings = new Settings(nop, context, repo, config, ref, suborg)
await settings.loadConfigs()
await settings.updateAll()
await settings.handleResults()
}
static async sync (nop, context, repo, config, ref) {
const settings = new Settings(nop, context, repo, config, ref)
await settings.loadConfigs(repo)
if (settings.isRestricted(repo.repo)) {
return
}
await settings.updateRepos(repo)
await settings.handleResults()
}
static async handleError (nop, context, repo, config, ref, nopcommand) {
const settings = new Settings(nop, context, repo, config, ref)
settings.appendToResults([nopcommand])
await settings.handleResults()
}
constructor (nop, context, repo, config, ref, suborg) {
this.ref = ref
this.context = context
this.installation_id = context.payload.installation.id
this.github = context.octokit
this.repo = repo
this.config = config
this.nop = nop
this.suborgChange = !!suborg
// If suborg config has been updated, do not load the entire suborg config, and only process repos restricted to it.
if (suborg) {
this.subOrgConfigMap = [suborg]
}
this.log = context.log
this.results = []
this.configvalidators = {}
this.overridevalidators = {}
const overridevalidators = config.overridevalidators
if (this.isIterable(overridevalidators)) {
for (const validator of overridevalidators) {
// eslint-disable-next-line no-new-func
const f = new Function('baseconfig', 'overrideconfig', validator.script)
this.overridevalidators[validator.plugin] = { canOverride: f, error: validator.error }
}
}
const configvalidators = config.configvalidators
if (this.isIterable(configvalidators)) {
for (const validator of configvalidators) {
// eslint-disable-next-line no-new-func
const f = new Function('baseconfig', validator.script)
this.configvalidators[validator.plugin] = { isValid: f, error: validator.error }
}
}
this.mergeDeep = new MergeDeep(this.log, [], this.configvalidators, this.overridevalidators)
}
async handleResults () {
const { payload } = this.context
if (!this.nop) {
this.log.debug('Not run in nop')
return
}
let error = false
// Different logic
const stats = {
// noOfReposProcessed: new Map(),
reposProcessed: {},
changes: {},
errors: {}
}
/*
Result fields
res.type
res.plugin
res.repo
res.endpoint
res.body
res.action
*/
this.results.forEach(res => {
if (res) {
stats.reposProcessed[res.repo] = true
if (res.type === 'ERROR') {
error = true
if (!stats.errors[res.repo]) {
stats.errors[res.repo] = []
}
stats.errors[res.repo].push(res.action)
} else {
if (!stats.changes[res.plugin]) {
stats.changes[res.plugin] = {}
}
if (!stats.changes[res.plugin][res.repo]) {
stats.changes[res.plugin][res.repo] = []
}
stats.changes[res.plugin][res.repo].push(`${res.action}`)
}
}
})
const template = eta.loadFile(path.join(__dirname, 'summary.tmpl'))
const commentmessage = await eta.render(template, stats)
if (env.ENABLE_PR_COMMENT === 'true') {
const commentmessage2 = `
#### :robot: Safe-Settings Validator summary
${this.results.reduce((x, y) => {
if (!y) {
return x
}
if (y.endpoint) {
return `${x}
<hr>
✅ ${y.plugin} plugin will perform \`${y.action}\` using this API ${y.endpoint}
<details>
<summary>
The payload is:
</summary>
${JSON.stringify(y.body, null, 4)}
</details>`
} else {
if (y.type === 'ERROR') {
error = true
return `${x}
<hr>
❌ Plugin:${y.plugin} , Action:${y.action}`
} else {
return `${x}
<hr>
ℹ️ Plugin:${y.plugin} , Repo:${y.repo} , Action:${y.action}`
}
}
}, '')}
`
const pullRequest = payload.check_run.check_suite.pull_requests[0]
await this.github.issues.createComment({
owner: payload.repository.owner.login,
repo: payload.repository.name,
issue_number: pullRequest.number,
body: commentmessage2
})
}
const params = {
owner: payload.repository.owner.login,
repo: payload.repository.name,
check_run_id: payload.check_run.id,
status: 'completed',
conclusion: error ? 'failure' : 'success',
completed_at: new Date().toISOString(),
output: {
title: error ? 'Finished with error' : 'Finished with success',
summary: commentmessage
}
}
this.log.debug(`Completing check run ${JSON.stringify(params)}`)
await this.github.checks.update(params)
}
async loadConfigs (repo) {
this.subOrgConfigs = await this.getSubOrgConfigs()
this.repoConfigs = await this.getRepoConfigs(repo)
}
async updateRepos (repo) {
this.subOrgConfigs = this.subOrgConfigs || await this.getSubOrgConfigs()
let repoConfig = this.config.repository
if (repoConfig) {
repoConfig = Object.assign(repoConfig, { name: repo.repo, org: repo.owner })
}
const subOrgConfig = this.getSubOrgConfig(repo.repo)
// If suborg config has been updated then only restrict to the repos for that suborg
if (this.subOrgConfigMap && !subOrgConfig) {
this.log.debug(`Skipping... SubOrg config changed but this repo is not part of it. ${JSON.stringify(repo)} suborg config ${JSON.stringify(this.subOrgConfigMap)}`)
return
}
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)}`)
if (subOrgConfig) {
let suborgRepoConfig = subOrgConfig.repository
if (suborgRepoConfig) {
suborgRepoConfig = Object.assign(suborgRepoConfig, { name: repo.repo, org: repo.owner })
repoConfig = this.mergeDeep.mergeDeep({}, repoConfig, suborgRepoConfig)
}
}
// Overlay repo config
// RepoConfigs should be preloaded but checking anyway
const overrideRepoConfig = this.repoConfigs[`${repo.repo}.yml`]?.repository
if (overrideRepoConfig) {
repoConfig = this.mergeDeep.mergeDeep({}, repoConfig, overrideRepoConfig)
}
if (repoConfig) {
try {
this.log.debug(`found a matching repoconfig for this repo ${JSON.stringify(repoConfig)}`)
const childPlugins = this.childPluginsList(repo)
const RepoPlugin = Settings.PLUGINS.repository
return new RepoPlugin(this.nop, this.github, repo, repoConfig, this.installation_id, this.log).sync().then(res => {
this.appendToResults(res)
return Promise.all(
childPlugins.map(([Plugin, config]) => {
return new Plugin(this.nop, this.github, repo, config, this.log).sync()
}))
}).then(res => {
this.appendToResults(res)
})
} catch (e) {
if (this.nop) {
const nopcommand = new NopCommand(this.constructor.name, this.repo, null, e, 'ERROR')
this.log.error(`NOPCOMMAND ${JSON.stringify(nopcommand)}`)
this.appendToResults([nopcommand])
// throw e
} else {
throw e
}
}
} else {
this.log.debug(`Didnt find any a matching repoconfig for this repo ${JSON.stringify(repo)} in ${JSON.stringify(this.repoConfigs)}`)
const childPlugins = this.childPluginsList(repo)
return Promise.all(childPlugins.map(([Plugin, config]) => {
return new Plugin(this.nop, this.github, repo, config, this.log).sync().then(res => {
this.appendToResults(res)
})
}))
}
}
async updateAll () {
// this.subOrgConfigs = this.subOrgConfigs || await this.getSubOrgConfigs(this.github, this.repo, this.log)
// this.repoConfigs = this.repoConfigs || await this.getRepoConfigs(this.github, this.repo, this.log)
return this.eachRepositoryRepos(this.github, this.config.restrictedRepos, this.log).then(res => {
this.appendToResults(res)
})
}
getSubOrgConfig (repoName) {
for (const k of Object.keys(this.subOrgConfigs)) {
const repoPattern = new Glob(k)
if (repoName.search(repoPattern) >= 0) {
return this.subOrgConfigs[k]
}
}
return undefined
}
childPluginsList (repo) {
const repoName = repo.repo
const subOrgOverrideConfig = this.getSubOrgConfig(repoName)
this.log.debug(`suborg config for ${repoName} is ${JSON.stringify(subOrgOverrideConfig)}`)
const repoOverrideConfig = this.repoConfigs[`${repoName}.yml`] || {}
const overrideConfig = this.mergeDeep.mergeDeep({}, this.config, subOrgOverrideConfig, repoOverrideConfig)
this.log.debug(`consolidated config is ${JSON.stringify(overrideConfig)}`)
const childPlugins = []
for (const [section, config] of Object.entries(overrideConfig)) {
const baseConfig = this.config[section]
if (Array.isArray(baseConfig) && Array.isArray(config)) {
for (const baseEntry of baseConfig) {
const newEntry = config.find(e => e.name === baseEntry.name)
this.validate(section, baseEntry, newEntry)
}
} else {
this.validate(section, baseConfig, config)
}
if (section !== 'repositories' && section !== 'repository') {
// Ignore any config that is not a plugin
if (section in Settings.PLUGINS) {
this.log.debug(`Found section ${section} in the config. Creating plugin...`)
const Plugin = Settings.PLUGINS[section]
childPlugins.push([Plugin, config])
}
}
}
return childPlugins
}
validate (section, baseConfig, overrideConfig) {
const configValidator = this.configvalidators[section]
if (configValidator) {
this.log.debug(`Calling configvalidator for key ${section} `)
if (!configValidator.isValid(overrideConfig)) {
this.log.error(`Error in calling configvalidator for key ${section} ${configValidator.error}`)
throw new Error(configValidator.error)
}
}
const overridevalidator = this.overridevalidators[section]
if (overridevalidator) {
this.log.debug(`Calling overridevalidator for key ${section} `)
if (!overridevalidator.canOverride(baseConfig, overrideConfig)) {
this.log.error(`Error in calling overridevalidator for key ${section} ${overridevalidator.error}`)
throw new Error(overridevalidator.error)
}
}
}
isRestricted (repoName) {
const restrictedRepos = this.config.restrictedRepos
// Skip configuring any restricted repos
if (Array.isArray(restrictedRepos)) {
// For backward compatibility support the old format
if (restrictedRepos.includes(repoName)) {
this.log.debug(`Skipping retricted repo ${repoName}`)
return true
} else {
this.log.debug(`${repoName} not in restricted repos ${restrictedRepos}`)
return false
}
} else if (Array.isArray(restrictedRepos.include)) {
if (this.includesRepo(repoName, restrictedRepos.include)) {
this.log.debug(`Allowing ${repoName} in restrictedRepos.include [${restrictedRepos.include}]`)
return false
} else {
this.log.debug(`Skipping repo ${repoName} not in restrictedRepos.include`)
return true
}
} else if (Array.isArray(restrictedRepos.exclude)) {
if (this.includesRepo(repoName, restrictedRepos.exclude)) {
this.log.debug(`Skipping excluded repo ${repoName} in restrictedRepos.exclude`)
return true
} else {
this.log.debug(`Allowing ${repoName} not in restrictedRepos.exclude [${restrictedRepos.exclude}]`)
return false
}
}
return false
}
includesRepo (repoName, restrictedRepos) {
return restrictedRepos.filter((restrictedRepo) => { return RegExp(restrictedRepo).test(repoName) }).length > 0
}
async eachRepositoryRepos (github, restrictedRepos, log) {
log.debug('Fetching repositories')
return github.paginate('GET /installation/repositories').then(repositories => {
return Promise.all(repositories.map(repository => {
if (this.isRestricted(repository.name)) {
return null
}
const { owner, name } = repository
return this.updateRepos({ owner: owner.login, repo: name })
})
)
})
}
/**
* Loads a file from GitHub
*
* @param params Params to fetch the file with
* @return The parsed YAML file
*/
async loadConfigMap (params) {
try {
this.log.debug(` In loadConfigMap ${JSON.stringify(params)}`)
const response = await this.github.repos.getContent(params).catch(e => {
this.log.debug(`Error getting settings ${JSON.stringify(params)} ${e}`)
})
if (!response) {
return []
}
// Ignore in case path is a folder
// - https://developer.github.com/v3/repos/contents/#response-if-content-is-a-directory
if (Array.isArray(response.data)) {
// const overrides = new Map()
const overrides = response.data.map(d => { return { name: d.name, path: d.path } })
// response.data.forEach(d => overrides.set(d.name, d.path))
return overrides
}
// we don't handle symlinks or submodule
// - https://developer.github.com/v3/repos/contents/#response-if-content-is-a-symlink
// - https://developer.github.com/v3/repos/contents/#response-if-content-is-a-submodule
if (typeof response.data.content !== 'string') {
return
}
const yaml = require('js-yaml')
return yaml.load(Buffer.from(response.data.content, 'base64').toString()) || {}
} catch (e) {
if (e.status === 404) {
return null
}
if (this.nop) {
const nopcommand = new NopCommand('settings', this.repo, null, e, 'ERROR')
this.log.error(`NOPCOMMAND ${JSON.stringify(nopcommand)}`)
this.appendToResults([nopcommand])
// throw e
} else {
throw e
}
}
}
/**
* Loads a file from GitHub
*
* @param params Params to fetch the file with
* @return The parsed YAML file
*/
async getRepoConfigMap () {
try {
this.log.debug(` In getRepoConfigMap ${JSON.stringify(this.repo)}`)
// GitHub getContent api has a hard limit of returning 1000 entries without
// any pagination. They suggest to use Tree api.
// https://docs.github.com/en/rest/repos/contents?apiVersion=2022-11-28#get-repository-content
// get .github/repos directory sha to use in the getTree api
const repo = { owner: this.repo.owner, repo: env.ADMIN_REPO }
const params = Object.assign(repo, { path: path.posix.join(CONFIG_PATH), ref: this.ref })
const githubDirectoryContentResponse = await this.github.repos.getContent(params).catch(e => {
this.log.debug(`Error getting settings ${JSON.stringify(params)} ${e}`)
})
if (!githubDirectoryContentResponse) {
throw new Error('Error reading .github directory')
}
const githubDirContent = githubDirectoryContentResponse.data
const repoDirInfo = githubDirContent.filter(dir => dir.name === 'repos')[0]
if (!repoDirInfo) {
this.log.debug('No repos directory in the admin/.github')
return []
}
// read the repo contents using tree
this.log.debug(`repos directory info ${JSON.stringify(repoDirInfo)}`)
// const endpoint = `/repos/${this.repo.owner}/${repo.repo}/git/trees/${repoDirInfo.sha}`
// this.log.debug(`endpoint: ${endpoint}`)
const treeParams = Object.assign(repo, { tree_sha: repoDirInfo.sha, recursive: 0 })
const response = await this.github.git.getTree(treeParams).catch(e => {
this.log.debug(`Error getting settings ${JSON.stringify(this.github.git.getTree.endpoint(treeParams))} ${e}`)
})
if (!response || !response.data) {
this.log.debug('repos directory exist but reading the tree failed')
throw new Error('exception while reading the repos directory')
}
// throw error if truncated is true.
if (response.data.truncated) {
this.log.debug('not all repo files in directory are read')
throw new Error('not all repo files in directory are read')
}
const treeInfo = response.data.tree
// we emulated the existing loadConfigMap function as is by returning the
// the same overrides list. This way the overall changes are minimal
const overrides = treeInfo.map(d => { return { name: d.path, path: path.posix.join(CONFIG_PATH, 'repos', d.path) } })
this.log.debug('Total overrides found in getRepoConfigMap are ' + overrides.length)
return overrides
} catch (e) {
if (this.nop) {
const nopcommand = new NopCommand('getRepoConfigMap', this.repo, null, e, 'ERROR')
this.log.error(`NOPCOMMAND ${JSON.stringify(nopcommand)}`)
this.appendToResults([nopcommand])
// throw e
} else {
throw e
}
}
}
/**
* Loads a file from GitHub
*
* @param params Params to fetch the file with
* @return The parsed YAML file
*/
async getSubOrgConfigMap () {
try {
this.log.debug(` In getSubOrgConfigMap ${JSON.stringify(this.repo)}`)
const repo = { owner: this.repo.owner, repo: env.ADMIN_REPO }
const params = Object.assign(repo, { path: path.posix.join(CONFIG_PATH, 'suborgs'), ref: this.ref })
const response = await this.loadConfigMap(params)
return response
} catch (e) {
if (this.nop) {
const nopcommand = new NopCommand('getSubOrgConfigMap', this.repo, null, e, 'ERROR')
this.log.error(`NOPCOMMAND ${JSON.stringify(nopcommand)}`)
this.appendToResults([nopcommand])
// throw e
} else {
throw e
}
}
}
/**
* If repo param is null load configs for all repos
* If repo param is null and suborg change, load configs for suborg repos only
* If repo partam is not null, load the config for a specific repo
* @param {*} repo repo param
* @returns repoConfigs object
*/
async getRepoConfigs (repo) {
try {
const overridePaths = await this.getRepoConfigMap()
const repoConfigs = {}
for (const override of overridePaths) {
// Don't load if already loaded
if (repoConfigs[override.name]) {
continue
}
// If repo is passed get only its config
// else load all the config
if (repo) {
if (override.name === `${repo.repo}.yml`) {
const data = await this.loadYaml(override.path)
this.log.debug(`data = ${JSON.stringify(data)}`)
repoConfigs[override.name] = data
}
} else if (this.suborgChange) {
// If suborg change, only load repos that are part of the suborg
if (this.getSubOrgConfig(override.name.split('.')[0])) {
const data = await this.loadYaml(override.path)
this.log.debug(`data = ${JSON.stringify(data)}`)
repoConfigs[override.name] = data
}
} else {
const data = await this.loadYaml(override.path)
this.log.debug(`data = ${JSON.stringify(data)}`)
repoConfigs[override.name] = data
}
}
this.log.debug(`repo configs = ${JSON.stringify(repoConfigs)}`)
return repoConfigs
} catch (e) {
if (this.nop) {
this.log.error(e)
const nopcommand = new NopCommand('getRepoConfigs', this.repo, null, e, 'ERROR')
this.log.error(`NOPCOMMAND ${JSON.stringify(nopcommand)}`)
this.appendToResults([nopcommand])
// throw e
} else {
throw e
}
}
}
/**
* Loads a file from GitHub
*
* @param params Params to fetch the file with
* @return The parsed YAML file
*/
async getSubOrgConfigs () {
try {
if (this.subOrgConfigMap) {
this.log.debug(`SubOrg config was changed and the associated overridePaths is = ${JSON.stringify(this.subOrgConfigMap)}`)
}
const overridePaths = this.subOrgConfigMap || await this.getSubOrgConfigMap()
const subOrgConfigs = {}
for (const override of overridePaths) {
const data = await this.loadYaml(override.path)
this.log.debug(`data = ${JSON.stringify(data)}`)
if (!data) { return subOrgConfigs }
subOrgConfigs[override.name] = data
if (data.suborgrepos) {
data.suborgrepos.forEach(repository => {
subOrgConfigs[repository] = data
})
}
if (data.suborgteams) {
const promises = data.suborgteams.map((teamslug) => {
return this.getReposForTeam(teamslug)
})
await Promise.all(promises).then(res => {
res.forEach(r => {
r.forEach(e => {
subOrgConfigs[e.name] = data
})
})
})
}
}
return subOrgConfigs
} catch (e) {
if (this.nop) {
const nopcommand = new NopCommand('getSubOrgConfigs', this.repo, null, e, 'ERROR')
this.log.error(`NOPCOMMAND ${JSON.stringify(nopcommand)}`)
this.appendToResults([nopcommand])
// throw e
} else {
throw e
}
}
}
/**
* Loads a file from GitHub
*
* @param params Params to fetch the file with
* @return The parsed YAML file
*/
async loadYaml (filePath) {
try {
const repo = { owner: this.repo.owner, repo: env.ADMIN_REPO }
const params = Object.assign(repo, { path: filePath, ref: this.ref })
const response = await this.github.repos.getContent(params).catch(e => {
this.log.error(`Error getting settings ${e}`)
})
// Ignore in case path is a folder
// - https://developer.github.com/v3/repos/contents/#response-if-content-is-a-directory
if (Array.isArray(response.data)) {
return null
}
// we don't handle symlinks or submodule
// - https://developer.github.com/v3/repos/contents/#response-if-content-is-a-symlink
// - https://developer.github.com/v3/repos/contents/#response-if-content-is-a-submodule
if (typeof response.data.content !== 'string') {
return
}
const yaml = require('js-yaml')
return yaml.load(Buffer.from(response.data.content, 'base64').toString()) || {}
} catch (e) {
if (e.status === 404) {
return null
}
if (this.nop) {
const nopcommand = new NopCommand(filePath, this.repo, null, e, 'ERROR')
this.log.error(`NOPCOMMAND ${JSON.stringify(nopcommand)}`)
this.appendToResults([nopcommand])
// throw e
} else {
throw e
}
}
}
appendToResults (res) {
if (this.nop) {
this.results = this.results.concat(res.flat(3))
}
}
async getReposForTeam (teamslug) {
const options = this.github.rest.teams.listReposInOrg.endpoint.merge({
org: this.repo.owner,
team_slug: teamslug,
per_page: 100
})
return this.github.paginate(options)
}
isObject (item) {
return (item && typeof item === 'object' && !Array.isArray(item))
}
isIterable (obj) {
// checks for null and undefined
if (obj == null) {
return false
}
return typeof obj[Symbol.iterator] === 'function'
}
}
Settings.FILE_NAME = '.github/' + env.SETTINGS_FILE_PATH
Settings.PLUGINS = {
repository: require('./plugins/repository'),
labels: require('./plugins/labels'),
collaborators: require('./plugins/collaborators'),
teams: require('./plugins/teams'),
milestones: require('./plugins/milestones'),
branches: require('./plugins/branches'),
autolinks: require('./plugins/autolinks'),
validator: require('./plugins/validator')
}
module.exports = Settings