Skip to content

Commit 87beedc

Browse files
Decyjphr/pr 683 (#721)
* fix: update eslint ecmaVersion to 13 Linting failed in deploymentConfig.js due to the static fields. Eslint supports this from ecmaVersion 13. * reapply eslint to tests, still supporting jest The full test suite failed because it tried to lint the tests, while the running linter did not do the same. Enabling linting gave errors due to jest having undef stuff, but overriding these files for jest env keeps the linting without these errors. * removed unused vars in index.js Removed to stop having eslint errors. * fix eslint errors, except environments Updated with `npx standard --fix`. Skipping environments.js and environments.test.js as they had a lot of errors, handling those in a separate commit. * fix eslint errors for environments Updated with `npx standard --fix`. * fix eslint casing errors for environments This was done manually as no autofix was available. * Enteprise sourcetype rulesets should not be handled at the org level * Securtiy manager teams should not be handled as other teams --------- Co-authored-by: Torgeir S <[email protected]>
1 parent c1bc922 commit 87beedc

17 files changed

+946
-911
lines changed

.eslintrc.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,16 @@
88
"standard"
99
],
1010
"parserOptions": {
11-
"ecmaVersion": 12
11+
"ecmaVersion": 13
1212
},
1313
"rules": {
1414
},
15-
"ignorePatterns": ["test/**/*.js"]
15+
"overrides": [
16+
{
17+
"files": ["test/**/*.js"],
18+
"env": {
19+
"jest": true
20+
}
21+
}
22+
]
1623
}

index.js

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ const env = require('./lib/env')
99

1010
let deploymentConfig
1111

12-
1312
module.exports = (robot, { getRouter }, Settings = require('./lib/settings')) => {
14-
let appName = 'safe-settings'
1513
let appSlug = 'safe-settings'
1614
async function syncAllSettings (nop, context, repo = context.repo(), ref) {
1715
try {
@@ -101,7 +99,7 @@ module.exports = (robot, { getRouter }, Settings = require('./lib/settings')) =>
10199
const config = Object.assign({}, deploymentConfig, runtimeConfig)
102100
const renameConfig = Object.assign({}, config, rename)
103101
robot.log.debug(`config for ref ${ref} is ${JSON.stringify(config)}`)
104-
return Settings.sync(nop, context, repo, renameConfig, ref )
102+
return Settings.sync(nop, context, repo, renameConfig, ref)
105103
} catch (e) {
106104
if (nop) {
107105
let filename = env.SETTINGS_FILE_PATH
@@ -217,7 +215,7 @@ module.exports = (robot, { getRouter }, Settings = require('./lib/settings')) =>
217215
robot.log.debug(JSON.stringify(res, null))
218216
}
219217

220-
async function info() {
218+
async function info () {
221219
const github = await robot.auth()
222220
const installations = await github.paginate(
223221
github.apps.listInstallations.endpoint.merge({ per_page: 100 })
@@ -227,13 +225,11 @@ module.exports = (robot, { getRouter }, Settings = require('./lib/settings')) =>
227225
const installation = installations[0]
228226
const github = await robot.auth(installation.id)
229227
const app = await github.apps.getAuthenticated()
230-
appName = app.data.name
231228
appSlug = app.data.slug
232229
robot.log.debug(`Validated the app is configured properly = \n${JSON.stringify(app.data, null, 2)}`)
233230
}
234231
}
235232

236-
237233
async function syncInstallation () {
238234
robot.log.trace('Fetching installations')
239235
const github = await robot.auth()
@@ -395,8 +391,8 @@ module.exports = (robot, { getRouter }, Settings = require('./lib/settings')) =>
395391
})
396392

397393
robot.on('repository.renamed', async context => {
398-
if (env.BLOCK_REPO_RENAME_BY_HUMAN!== 'true') {
399-
robot.log.debug(`"env.BLOCK_REPO_RENAME_BY_HUMAN" is 'false' by default. Repo rename is not managed by Safe-settings. Continue with the default behavior.`)
394+
if (env.BLOCK_REPO_RENAME_BY_HUMAN !== 'true') {
395+
robot.log.debug('"env.BLOCK_REPO_RENAME_BY_HUMAN" is \'false\' by default. Repo rename is not managed by Safe-settings. Continue with the default behavior.')
400396
return
401397
}
402398
const { payload } = context
@@ -414,7 +410,7 @@ module.exports = (robot, { getRouter }, Settings = require('./lib/settings')) =>
414410
const newPath = `.github/repos/${payload.repository.name}.yml`
415411
robot.log.debug(oldPath)
416412
try {
417-
const repofile = await context.octokit.request('GET /repos/{owner}/{repo}/contents/{path}', {
413+
const repofile = await context.octokit.request('GET /repos/{owner}/{repo}/contents/{path}', {
418414
owner: payload.repository.owner.login,
419415
repo: env.ADMIN_REPO,
420416
path: oldPath,
@@ -439,12 +435,12 @@ module.exports = (robot, { getRouter }, Settings = require('./lib/settings')) =>
439435
} catch (error) {
440436
if (error.status === 404) {
441437
// if the a config file does not exist, create one from the old one
442-
const update = await context.octokit.request('PUT /repos/{owner}/{repo}/contents/{path}', {
438+
await context.octokit.request('PUT /repos/{owner}/{repo}/contents/{path}', {
443439
owner: payload.repository.owner.login,
444440
repo: env.ADMIN_REPO,
445441
path: newPath,
446-
name: `${payload.repository.name}.yml`,
447-
content: content,
442+
name: `${payload.repository.name}.yml`,
443+
content,
448444
message: `Repo Renamed and safe-settings renamed the file from ${payload.changes.repository.name.from} to ${payload.repository.name}`,
449445
sha: repofile.data.sha,
450446
headers: {
@@ -455,26 +451,23 @@ module.exports = (robot, { getRouter }, Settings = require('./lib/settings')) =>
455451
} else {
456452
robot.log.error(error)
457453
}
458-
}
459-
454+
}
460455
} catch (error) {
461456
if (error.status === 404) {
462-
//nop
463-
} else {
457+
// nop
458+
} else {
464459
robot.log.error(error)
465460
}
466-
}
467-
return
461+
}
468462
} else {
469463
robot.log.debug('Repository Edited by a Human')
470464
// Create a repository config to reset the name back to the previous name
471-
const rename = {repository: { name: payload.changes.repository.name.from, oldname: payload.repository.name}}
472-
const repo = {repo: payload.changes.repository.name.from, owner: payload.repository.owner.login}
465+
const rename = { repository: { name: payload.changes.repository.name.from, oldname: payload.repository.name } }
466+
const repo = { repo: payload.changes.repository.name.from, owner: payload.repository.owner.login }
473467
return renameSync(false, context, repo, rename)
474468
}
475469
})
476470

477-
478471
robot.on('check_suite.requested', async context => {
479472
const { payload } = context
480473
const { repository } = payload
@@ -663,7 +656,7 @@ module.exports = (robot, { getRouter }, Settings = require('./lib/settings')) =>
663656
syncInstallation()
664657
})
665658
}
666-
659+
667660
// Get info about the app
668661
info()
669662

lib/commentmessage.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ module.exports = `* Run on: \` <%= new Date() %> \`
2828
<% }) %>
2929
3030
<% }) %>
31-
<% } %>`
31+
<% } %>`

lib/deploymentConfig.js

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8,46 +8,47 @@ const env = require('./env')
88
* The settings are loaded from the deployment-settings.yml file during initialization and stored as static properties.
99
*/
1010
class DeploymentConfig {
11-
//static config
12-
static configvalidators = {}
13-
static overridevalidators = {}
11+
// static config
12+
static configvalidators = {}
13+
static overridevalidators = {}
1414

15-
static {
16-
const deploymentConfigPath = process.env.DEPLOYMENT_CONFIG_FILE ? process.env.DEPLOYMENT_CONFIG_FILE : 'deployment-settings.yml'
17-
if (fs.existsSync(deploymentConfigPath)) {
18-
this.config = yaml.load(fs.readFileSync(deploymentConfigPath))
19-
} else {
20-
this.config = { restrictedRepos: ['admin', '.github', 'safe-settings'] }
21-
}
22-
23-
const overridevalidators = this.config.overridevalidators
24-
if (this.isIterable(overridevalidators)) {
25-
for (const validator of overridevalidators) {
26-
// eslint-disable-next-line no-new-func
27-
const f = new Function('baseconfig', 'overrideconfig', 'githubContext', validator.script)
28-
this.overridevalidators[validator.plugin] = { canOverride: f, error: validator.error }
29-
}
30-
}
31-
const configvalidators = this.config.configvalidators
32-
if (this.isIterable(configvalidators)) {
33-
for (const validator of configvalidators) {
34-
// eslint-disable-next-line no-new-func
35-
const f = new Function('baseconfig', 'githubContext', validator.script)
36-
this.configvalidators[validator.plugin] = { isValid: f, error: validator.error }
37-
}
38-
}
15+
static {
16+
const deploymentConfigPath = process.env.DEPLOYMENT_CONFIG_FILE ? process.env.DEPLOYMENT_CONFIG_FILE : 'deployment-settings.yml'
17+
if (fs.existsSync(deploymentConfigPath)) {
18+
this.config = yaml.load(fs.readFileSync(deploymentConfigPath))
19+
} else {
20+
this.config = { restrictedRepos: ['admin', '.github', 'safe-settings'] }
3921
}
4022

41-
static isIterable (obj) {
42-
// checks for null and undefined
43-
if (obj == null) {
44-
return false
45-
}
46-
return typeof obj[Symbol.iterator] === 'function'
23+
const overridevalidators = this.config.overridevalidators
24+
if (this.isIterable(overridevalidators)) {
25+
for (const validator of overridevalidators) {
26+
// eslint-disable-next-line no-new-func
27+
const f = new Function('baseconfig', 'overrideconfig', 'githubContext', validator.script)
28+
this.overridevalidators[validator.plugin] = { canOverride: f, error: validator.error }
29+
}
30+
}
31+
const configvalidators = this.config.configvalidators
32+
if (this.isIterable(configvalidators)) {
33+
for (const validator of configvalidators) {
34+
// eslint-disable-next-line no-new-func
35+
const f = new Function('baseconfig', 'githubContext', validator.script)
36+
this.configvalidators[validator.plugin] = { isValid: f, error: validator.error }
4737
}
38+
}
39+
}
4840

49-
constructor (nop, context, repo, config, ref, suborg) {
41+
static isIterable (obj) {
42+
// checks for null and undefined
43+
if (obj == null) {
44+
return false
5045
}
46+
return typeof obj[Symbol.iterator] === 'function'
47+
}
48+
49+
// eslint-disable-next-line no-useless-constructor
50+
constructor (nop, context, repo, config, ref, suborg) {
51+
}
5152
}
5253
DeploymentConfig.FILE_NAME = `${env.CONFIG_PATH}/settings.yml`
5354

lib/error.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ module.exports = `Run on: \`<%= new Date().toISOString() %>\`
99
<% }) -%>
1010
1111
12-
`
12+
`

0 commit comments

Comments
 (0)