diff --git a/fixtures/custom-help-url/commitlint.config.js b/fixtures/custom-help-url/commitlint.config.js new file mode 100644 index 00000000..f7177c5c --- /dev/null +++ b/fixtures/custom-help-url/commitlint.config.js @@ -0,0 +1,4 @@ +module.exports = { + extends: ['@commitlint/config-conventional'], + helpUrl: 'https://example.org', +} diff --git a/src/action.js b/src/action.js index f9f070cf..4f41a743 100644 --- a/src/action.js +++ b/src/action.js @@ -91,12 +91,12 @@ function getOptsFromConfig(config) { } } -const formatErrors = (lintedCommits) => +const formatErrors = (lintedCommits, { config }) => format( { results: lintedCommits.map((commit) => commit.lintResult) }, { color: true, - helpUrl: getInput('helpURL'), + helpUrl: config.helpUrl || getInput('helpURL'), }, ) @@ -129,7 +129,7 @@ const showLintResults = async ([from, to]) => { hash: commit.hash, })), ) - const formattedResults = formatErrors(lintedCommits) + const formattedResults = formatErrors(lintedCommits, { config }) generateOutputs(lintedCommits) diff --git a/src/action.test.js b/src/action.test.js index 35e34f6d..5b2fc4f4 100644 --- a/src/action.test.js +++ b/src/action.test.js @@ -76,6 +76,13 @@ describe('Commit Linter action', () => { await runAction() td.verify(core.setFailed(contains('You have commit messages with errors'))) + td.verify( + core.setFailed( + contains( + 'https://github.com/conventional-changelog/commitlint/#what-is-commitlint', + ), + ), + ) }) it('should fail for single push with incorrect message', async () => { @@ -577,4 +584,25 @@ describe('Commit Linter action', () => { td.verify(console.log('Lint free! 🎉')) }) }) + + describe('when a different helpUrl is provided in the config', () => { + beforeEach(async () => { + cwd = await git.bootstrap('fixtures/custom-help-url') + await gitEmptyCommit(cwd, 'wrong message') + const [to] = await getCommitHashes(cwd) + await createPushEventPayload(cwd, { to }) + updatePushEnvVars(cwd, to) + td.replace(process, 'cwd', () => cwd) + td.replace(console, 'log') + }) + + it('should show custom URL from helpUrl', async () => { + await runAction() + + td.verify( + core.setFailed(contains('You have commit messages with errors')), + ) + td.verify(core.setFailed(contains(' https://example.org'))) + }) + }) })