Skip to content

Commit d041bb5

Browse files
committed
🔊 Update logging
1 parent 1dd15fc commit d041bb5

4 files changed

Lines changed: 24 additions & 22 deletions

File tree

‎index.js‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,18 @@ module.exports = async (app) => {
7070
let config
7171
try {
7272
config = await getConfig(context, app.CONFIG_FILENAME)
73-
} catch (error) {
74-
if (error && error.code >= 500) {
75-
app.log.warn({ error }, `[${context.payload.repository.full_name}] Repo access failed with server error ${error.code}`)
73+
} catch (e) {
74+
if (e && e.code >= 500) {
75+
app.log.warn(e, `[${context.payload.repository.full_name}] Repo access failed with server error ${e.code}`)
7676
} else {
77-
app.log.warn({ error }, `[${context.payload.repository.full_name}] Repo is blocked, unscheduled`)
77+
app.log.debug(e, `[${context.payload.repository.full_name}] Repo is blocked, unscheduled`)
7878
scheduler.stop(context.payload.repository)
7979
}
8080
return null
8181
}
8282

8383
if (!config) {
84-
app.log.warn(`[${context.payload.repository.full_name}] Unable to get config, unscheduled`)
84+
app.log.debug(`[${context.payload.repository.full_name}] Unable to get config, unscheduled`)
8585
scheduler.stop(context.payload.repository)
8686
return null
8787
}

‎lib/pull.js‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module.exports = class Pull {
99
const { error, value } = schema.validate(config)
1010

1111
if (error) {
12-
this.logger.warn({ err: new Error(error), owner, repo }, 'Invalid config')
12+
this.logger.warn({ e: new Error(error), owner, repo }, 'Invalid config')
1313
throw new Error('Invalid config')
1414
}
1515
this.config = Object.assign({}, value, { owner, repo, repoPath: `${owner}/${repo}` })
@@ -60,8 +60,8 @@ module.exports = class Pull {
6060
await this.hardResetCommit(incomingPR.base.ref, incomingPR.head.sha)
6161
this.logger.info(`[${this.config.repoPath}]#${prNumber} Hard reset successful`)
6262
return true
63-
} catch (error) {
64-
this.logger.warn({ error }, `[${this.config.repoPath}]#${prNumber} Hard reset failed`)
63+
} catch (e) {
64+
this.logger.warn({ e }, `[${this.config.repoPath}]#${prNumber} Hard reset failed`)
6565
}
6666
} else {
6767
const mergable = incomingPR.mergeable_state === 'clean' ||
@@ -88,18 +88,18 @@ module.exports = class Pull {
8888
base
8989
})
9090
return comparison.data.total_commits > 0
91-
} catch (ex) {
92-
if (ex.message.match(/this diff is taking too long to generate/i)) {
91+
} catch (e) {
92+
if (e.message.match(/this diff is taking too long to generate/i)) {
9393
return true
94-
} else if (ex.message.match(/not found/i)) {
94+
} else if (e.message.match(/not found/i)) {
9595
this.logger.debug(`[${this.config.repoPath}] ${this.config.owner}:${base}...${upstream} Not found`)
9696
return false
97-
} else if (ex.message.match(/no common ancestor/i)) {
97+
} else if (e.message.match(/no common ancestor/i)) {
9898
this.logger.debug(`[${this.config.repoPath}] ${this.config.owner}:${base}...${upstream} No common ancestor`)
9999
return false
100100
} else {
101101
this.logger.warn({
102-
err: ex,
102+
err: e,
103103
owner: this.config.owner,
104104
repo: this.config.repo,
105105
head: upstream
@@ -153,8 +153,8 @@ module.exports = class Pull {
153153
await this.addReviewers(prNumber, reviewers)
154154

155155
this.logger.debug(`[${this.config.repoPath}]#${prNumber} Updated pull request`)
156-
} catch (error) {
157-
this.logger.warn(error, `[${this.config.repoPath}] Create PR from ${upstream} failed`)
156+
} catch (e) {
157+
this.logger.warn(e, `[${this.config.repoPath}] Create PR from ${upstream} failed`)
158158
}
159159
}
160160

‎lib/router.js‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ module.exports = app => {
121121
.then((config) => {
122122
const { error, value } = schema.validate(config)
123123
if (error) throw error
124-
console.log(value)
125124
const reqs = value.rules.map(r => new Promise((resolve, reject) => {
126125
getJSON(`https://api.github.com/repos/${req.params.owner}/${req.params.repo}/compare/${r.base}...${r.upstream}?client_id=${process.env.CLIENT_ID || ''}&client_secret=${process.env.CLIENT_SECRET || ''}`)
127126
.then(githubRes => resolve())
@@ -133,12 +132,15 @@ module.exports = app => {
133132
.catch(e => res.status(400).end(`Cannot compare ${e.message}`))
134133
})
135134
.catch(e => {
136-
console.log(e.message)
135+
let output = { statusCode: 400, body: `.github/${app.CONFIG_FILENAME} file has failed validation` }
137136
if (e.message.indexOf('API rate limit exceeded') > -1) {
138-
res.status(400).end(`Github API rate limit exceeded`)
139-
} else {
140-
res.status(400).end(`.github/${app.CONFIG_FILENAME} file was either not found or failed validation`)
137+
output.body = `Github API rate limit exceeded`
138+
} else if (e.message.indexOf('404') > -1) {
139+
output.statusCode = 404
140+
output.body = `File not found`
141141
}
142+
app.log.debug(e, `[${req.params.owner}/${req.params.repo}] [.github/${app.CONFIG_FILENAME}] ${output.message}`)
143+
res.status(output.statusCode).end(output.body)
142144
})
143145
})
144146
}

‎test/pull.test.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ describe('pull - routineCheck', () => {
7777
try {
7878
new Pull(github, { owner: 'wei', repo: 'fork', logger: app.log }) // eslint-disable-line
7979
throw Error('Should throw error and go to catch')
80-
} catch (err) {
81-
expect(err.message).toEqual('Invalid config')
80+
} catch (e) {
81+
expect(e.message).toEqual('Invalid config')
8282
}
8383
})
8484

0 commit comments

Comments
 (0)