Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ Whether you want to fail on warnings or not.

Default: `false`

### `failOnErrors`

Whether you want to fail on errors or not. Still outputs the results, just forces the action to pass even if errors are detected.

Default: `true`

### `helpURL`

Link to a page explaining your commit message convention.
Expand Down
8 changes: 7 additions & 1 deletion src/action.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { existsSync } from 'fs'
import { resolve } from 'path'
import { getInput, setFailed } from '@actions/core'
import { getInput, setFailed, setOutput } from '@actions/core'
import { context as eventContext, getOctokit } from '@actions/github'
import lint from '@commitlint/lint'
import { format } from '@commitlint/format'
Expand Down Expand Up @@ -145,6 +145,12 @@ const showLintResults = async ([from, to]) => {

if (hasOnlyWarnings(lintedCommits)) {
handleOnlyWarnings(formattedResults)
} else if (formattedResults && getInput('failOnErrors') === 'false') {
// https://github.com/actions/toolkit/tree/master/packages/core#exit-codes
// this would be a good place to implement the setNeutral() when it's eventually implimented.
// for now it can pass with a check mark.
console.log('Passing despite errors ✅')
setOutput(`You have commit messages with errors\n\n${formattedResults}`)
} else if (formattedResults) {
setFailedAction(formattedResults)
} else {
Expand Down
39 changes: 39 additions & 0 deletions src/action.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,49 @@ describe('Commit Linter action', () => {

await runAction()

console.log()
td.verify(core.setFailed(contains('wrong message 1')))
td.verify(core.setFailed(contains('wrong message 2')))
})

it('should pass for push range with wrong messages with failOnErrors set to false', async () => {
td.when(core.getInput('failOnErrors')).thenReturn('false')
cwd = await git.bootstrap('fixtures/conventional')
await gitEmptyCommit(cwd, 'message from before push')
await gitEmptyCommit(cwd, 'wrong message 1')
await gitEmptyCommit(cwd, 'wrong message 2')
const [before, , to] = await getCommitHashes(cwd)
await createPushEventPayload(cwd, { before, to })
updatePushEnvVars(cwd, to)
td.replace(process, 'cwd', () => cwd)
td.replace(console, 'log')

await runAction()

td.verify(core.setFailed(), { times: 0, ignoreExtraArgs: true })
td.verify(console.log(contains('Passing despite errors ✅')))
td.verify(core.setOutput(contains('wrong message 1')))
td.verify(core.setOutput(contains('wrong message 2')))
})

it('should pass for push range with correct messages with failOnErrors set to false', async () => {
td.when(core.getInput('failOnErrors')).thenReturn('false')
cwd = await git.bootstrap('fixtures/conventional')
await gitEmptyCommit(cwd, 'message from before push')
await gitEmptyCommit(cwd, 'chore: correct message 1')
await gitEmptyCommit(cwd, 'chore: correct message 2')
const [before, , to] = await getCommitHashes(cwd)
await createPushEventPayload(cwd, { before, to })
updatePushEnvVars(cwd, to)
td.replace(process, 'cwd', () => cwd)
td.replace(console, 'log')

await runAction()

td.verify(core.setFailed(), { times: 0, ignoreExtraArgs: true })
td.verify(console.log('Lint free! 🎉'))
})

it('should pass for push range with correct messages', async () => {
cwd = await git.bootstrap('fixtures/conventional')
await gitEmptyCommit(cwd, 'message from before push')
Expand Down