From a038b419f7f1d2073977ec1e6fe59ffcbba38931 Mon Sep 17 00:00:00 2001 From: Jan Melena Date: Sat, 11 Dec 2021 05:57:52 +0100 Subject: [PATCH] fix(cz-commitlint): combine commit body with issuesBody/breakingBody when body has an empty string (#2915) Co-authored-by: Jan Melena --- @commitlint/cz-commitlint/src/SectionBody.test.ts | 9 +++++++++ @commitlint/cz-commitlint/src/SectionBody.ts | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/@commitlint/cz-commitlint/src/SectionBody.test.ts b/@commitlint/cz-commitlint/src/SectionBody.test.ts index 12e4acc6e5..161b548989 100644 --- a/@commitlint/cz-commitlint/src/SectionBody.test.ts +++ b/@commitlint/cz-commitlint/src/SectionBody.test.ts @@ -74,4 +74,13 @@ describe('combineCommitMessage', () => { }); expect(commitMessage).toBe('This is issue body message.'); }); + + test('should use issueBody when body message is empty string but commit has issue note', () => { + setRules({}); + const commitMessage = combineCommitMessage({ + body: '', + issuesBody: 'This is issue body message.', + }); + expect(commitMessage).toBe('This is issue body message.'); + }); }); diff --git a/@commitlint/cz-commitlint/src/SectionBody.ts b/@commitlint/cz-commitlint/src/SectionBody.ts index de528b8858..1ea38bf6c0 100644 --- a/@commitlint/cz-commitlint/src/SectionBody.ts +++ b/@commitlint/cz-commitlint/src/SectionBody.ts @@ -19,7 +19,7 @@ export function combineCommitMessage(answers: Answers): string { const leadingBlankFn = getLeadingBlankFn(getRule('body', 'leading-blank')); const {body, breakingBody, issuesBody} = answers; - const commitBody = body ?? breakingBody ?? issuesBody ?? '-'; + const commitBody = body || breakingBody || issuesBody || '-'; if (commitBody) { return leadingBlankFn(