Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/__tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ test('a failing verdict is logged as one', async () => {
expect(log.info).toHaveBeenCalledWith('Merge check undefined#undefined (unknown trigger): fail')
})

test('a failing verdict logs the rule codes it names, not the messages', async () => {
jest.spyOn(mergeCheck, 'runMergeCheck').mockResolvedValue({
success: false,
message: 'Commit message failed (2 of 4 checks). abc1234 "fix stuff": CC001 ... CC202 ... CC001 ...'
})
const log = logger()
await handler.runWith(event, { client: {}, logger: log })
expect(log.info).toHaveBeenCalledWith('Merge check {repo}#1 (on-code-pushed): fail (CC001, CC202)')
})

test('a check that cannot run fails, saying nothing was validated', async () => {
jest.spyOn(mergeCheck, 'runMergeCheck').mockRejectedValue(new Error('Bitbucket answered 500'))
const log = logger()
Expand Down
9 changes: 8 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,20 @@ async function run (event, { client = new BitbucketClient(), budgetMs = BUDGET_M
logger.error(`Merge check ${what} could not run: ${done.error.stack || done.error.message}`)
return { success: false, message: OUTAGE }
}
logger.info(`Merge check ${what}: ${done.verdict.success ? 'pass' : 'fail'}`)
logger.info(`Merge check ${what}: ${done.verdict.success ? 'pass' : 'fail'}${ruleCodes(done.verdict.message)}`)
return done.verdict
} finally {
clearTimeout(timer)
}
}

// The rule codes a verdict names, for the log: enough to tell why a check
// failed without writing anyone's commit messages into the app's logs.
function ruleCodes (message) {
const codes = [...new Set(String(message).match(/\bCC\d{3}\b/g) || [])]
return codes.length ? ` (${codes.join(', ')})` : ''
}

// Forge calls the handler with (event, context).
exports.run = (event) => run(event)
exports.runWith = run
Expand Down