From 0911cae00990e44bafab30af5357ed057b5cf964 Mon Sep 17 00:00:00 2001 From: Wagner Santos Date: Thu, 20 Aug 2020 08:33:43 -0300 Subject: [PATCH] fix: action shows error ouput when not all commits have warnings Fixes #43 --- src/action.js | 5 ++--- src/action.test.js | 13 +++++++++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/action.js b/src/action.js index 8ab4c0c..f1a299f 100644 --- a/src/action.js +++ b/src/action.js @@ -104,9 +104,8 @@ const formatErrors = lintedCommits => const hasOnlyWarnings = lintedCommits => lintedCommits.length && - lintedCommits.every( - ({ lintResult }) => lintResult.valid && lintResult.warnings.length, - ) + lintedCommits.every(({ lintResult }) => lintResult.valid) && + lintedCommits.some(({ lintResult }) => lintResult.warnings.length) const setFailed = formattedResults => { core.setFailed(`You have commit messages with errors\n\n${formattedResults}`) diff --git a/src/action.test.js b/src/action.test.js index a83e036..22d9237 100644 --- a/src/action.test.js +++ b/src/action.test.js @@ -400,12 +400,14 @@ describe('Commit Linter action', () => { beforeEach(async () => { cwd = await git.bootstrap('fixtures/conventional') + await gitEmptyCommit(cwd, 'chore: previous commit') + await gitEmptyCommit(cwd, 'chore: correct message with no warnings') await gitEmptyCommit( cwd, 'chore: correct message\nsome context without leading blank line', ) - const [to] = await getCommitHashes(cwd) - await createPushEventPayload(cwd, { to }) + const [before, from, to] = await getCommitHashes(cwd) + await createPushEventPayload(cwd, { before, to }) updatePushEnvVars(cwd, to) td.replace(process, 'cwd', () => cwd) td.replace(console, 'log') @@ -419,6 +421,13 @@ describe('Commit Linter action', () => { errors: [], warnings: ['body must have leading blank line'], }, + { + hash: from, + message: 'chore: correct message with no warnings', + valid: true, + errors: [], + warnings: [], + }, ] })