Skip to content

Commit bacf4cf

Browse files
chore: cleanup eslint and logging functions (#9)
Update eslint, fix all flagged eslint issues Fix logging function calls
1 parent 647aa49 commit bacf4cf

File tree

5 files changed

+43
-48
lines changed

5 files changed

+43
-48
lines changed

.eslintrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"standard"
99
],
1010
"parserOptions": {
11-
"ecmaVersion": 12
11+
"ecmaVersion": 2022
1212
},
1313
"rules": {
1414
"space-before-function-paren": "off",

index.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ const env = require('./lib/env')
1010
let deploymentConfig
1111

1212
module.exports = (robot, { getRouter }, Settings = require('./lib/settings')) => {
13-
let appName = 'safe-settings'
1413
let appSlug = 'safe-settings'
1514
async function syncAllSettings (nop, context, repo = context.repo(), ref) {
1615
const log = robot.log.child({ context: 'index', repository: repo.repo })
@@ -236,7 +235,6 @@ module.exports = (robot, { getRouter }, Settings = require('./lib/settings')) =>
236235
const installation = installations[0]
237236
const github = await robot.auth(installation.id)
238237
const app = await github.apps.getAuthenticated()
239-
appName = app.data.name
240238
appSlug = app.data.slug
241239
log.debug(`Validated the app is configured properly = \n${JSON.stringify(app.data, null, 2)}`)
242240
}
@@ -388,7 +386,7 @@ module.exports = (robot, { getRouter }, Settings = require('./lib/settings')) =>
388386
log.debug(`Repository member edited by Bot: ${sender.login}`)
389387
return
390388
}
391-
log.debug(`Repository member edited by a Human: ${sender.login}'`)
389+
log.debug(`Repository member edited by a Human: ${sender.login}`)
392390
return syncSettings(false, context)
393391
})
394392

@@ -457,7 +455,7 @@ module.exports = (robot, { getRouter }, Settings = require('./lib/settings')) =>
457455
repo: env.ADMIN_REPO,
458456
path: newPath,
459457
name: `${payload.repository.name}.yml`,
460-
content: content,
458+
content,
461459
message: `Repo Renamed and safe-settings renamed the file from ${payload.changes.repository.name.from} to ${payload.repository.name}`,
462460
sha: repofile.data.sha,
463461
headers: {

lib/deploymentConfig.js

Lines changed: 31 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8,46 +8,43 @@ 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+
}
5148
}
5249
DeploymentConfig.FILE_NAME = `${env.CONFIG_PATH}/settings.yml`
5350

lib/plugins/branches.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ module.exports = class Branches extends ErrorStash {
150150
return this.github.repos
151151
.updateBranchProtection(params)
152152
.then((res) =>
153-
this.log(
153+
this.log.info(
154154
`Branch protection applied successfully ${JSON.stringify(
155155
res.url
156156
)}`

lib/plugins/rulesets.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ module.exports = class Rulesets extends Diffable {
2525
org: this.repo.owner,
2626
headers: version
2727
})
28-
this.log(listOptions)
28+
this.log.debug(listOptions)
2929
return this.github.paginate(listOptions)
3030
.then(res => {
3131
const rulesets = res.map(ruleset => {
@@ -50,7 +50,7 @@ module.exports = class Rulesets extends Diffable {
5050
repo: this.repo.repo,
5151
headers: version
5252
})
53-
this.log(listOptions)
53+
this.log.debug(listOptions)
5454
return this.github.paginate(listOptions)
5555
.then(res => {
5656
const rulesets = res
@@ -97,7 +97,7 @@ module.exports = class Rulesets extends Diffable {
9797
}
9898
this.log.debug(`Updating Ruleset with the following values ${JSON.stringify(parms, null, 2)}`)
9999
return this.github.request('PUT /orgs/{org}/rulesets/{id}', parms).then(res => {
100-
this.log(`Ruleset updated successfully ${JSON.stringify(res.url)}`)
100+
this.log.info(`Ruleset updated successfully ${JSON.stringify(res.url)}`)
101101
return res
102102
}).catch(e => {
103103
return this.handleError(e)
@@ -110,7 +110,7 @@ module.exports = class Rulesets extends Diffable {
110110
}
111111
this.log.debug(`Updating Ruleset with the following values ${JSON.stringify(parms, null, 2)}`)
112112
return this.github.request('PUT /repos/{owner}/{repo}/rulesets/{id}', parms).then(res => {
113-
this.log(`Ruleset updated successfully ${JSON.stringify(res.url)}`)
113+
this.log.info(`Ruleset updated successfully ${JSON.stringify(res.url)}`)
114114
return res
115115
}).catch(e => {
116116
return this.handleError(e)
@@ -127,7 +127,7 @@ module.exports = class Rulesets extends Diffable {
127127
}
128128
this.log.debug(`Creating Rulesets with the following values ${JSON.stringify(attrs, null, 2)}`)
129129
return this.github.request('POST /orgs/{org}/rulesets', this.wrapAttrs(attrs)).then(res => {
130-
this.log(`Ruleset created successfully ${JSON.stringify(res.url)}`)
130+
this.log.info(`Ruleset created successfully ${JSON.stringify(res.url)}`)
131131
return res
132132
}).catch(e => {
133133
return this.handleError(e)
@@ -140,7 +140,7 @@ module.exports = class Rulesets extends Diffable {
140140
}
141141
this.log.debug(`Creating Rulesets with the following values ${JSON.stringify(attrs, null, 2)}`)
142142
return this.github.request('POST /repos/{owner}/{repo}/rulesets', this.wrapAttrs(attrs)).then(res => {
143-
this.log(`Ruleset created successfully ${JSON.stringify(res.url)}`)
143+
this.log.info(`Ruleset created successfully ${JSON.stringify(res.url)}`)
144144
return res
145145
}).catch(e => {
146146
return this.handleError(e)
@@ -158,7 +158,7 @@ module.exports = class Rulesets extends Diffable {
158158
}
159159
this.log.debug(`Deleting Ruleset with the following values ${JSON.stringify(parms, null, 2)}`)
160160
return this.github.request('DELETE /orgs/{org}/rulesets/{id}', parms).then(res => {
161-
this.log(`Ruleset deleted successfully ${JSON.stringify(res.url)}`)
161+
this.log.info(`Ruleset deleted successfully ${JSON.stringify(res.url)}`)
162162
return res
163163
}).catch(e => {
164164
return this.handleError(e)
@@ -171,7 +171,7 @@ module.exports = class Rulesets extends Diffable {
171171
}
172172
this.log.debug(`Deleting Ruleset with the following values ${JSON.stringify(parms, null, 2)}`)
173173
return this.github.request('DELETE /repos/{owner}/{repo}/rulesets/{id}', parms).then(res => {
174-
this.log(`Ruleset deleted successfully ${JSON.stringify(res.url)}`)
174+
this.log.info(`Ruleset deleted successfully ${JSON.stringify(res.url)}`)
175175
return res
176176
}).catch(e => {
177177
if (e.status === 404) {

0 commit comments

Comments
 (0)