From 5e579c4dc92320095759f865c69a29c8d27c0899 Mon Sep 17 00:00:00 2001 From: Joey Perrott Date: Tue, 14 Apr 2020 15:25:05 -0700 Subject: [PATCH] fix(dev-infra): properly handle multiline regex of commit body (#36632) Previously, the commit message body regex only matched the first line of the body. This change corrects the regex to match the entire line. PR Close #36632 --- dev-infra/commit-message/validate.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/dev-infra/commit-message/validate.ts b/dev-infra/commit-message/validate.ts index 7088b9081c..453254dbf9 100644 --- a/dev-infra/commit-message/validate.ts +++ b/dev-infra/commit-message/validate.ts @@ -20,7 +20,7 @@ const SQUASH_PREFIX_RE = /^squash! /i; const REVERT_PREFIX_RE = /^revert:? /i; const TYPE_SCOPE_RE = /^(\w+)(?:\(([^)]+)\))?\:\s(.+)$/; const COMMIT_HEADER_RE = /^(.*)/i; -const COMMIT_BODY_RE = /^.*\n\n(.*)/i; +const COMMIT_BODY_RE = /^.*\n\n([\s\S]*)$/; /** Parse a full commit message into its composite parts. */ export function parseCommitMessage(commitMsg: string) { @@ -79,6 +79,9 @@ export function validateCommitMessage( const config = getAngularDevConfig<'commitMessage', CommitMessageConfig>().commitMessage; const commit = parseCommitMessage(commitMsg); + //////////////////////////////////// + // Checking revert, squash, fixup // + //////////////////////////////////// if (commit.isRevert) { return true; } @@ -102,6 +105,9 @@ export function validateCommitMessage( return true; } + //////////////////////////// + // Checking commit header // + //////////////////////////// if (commit.header.length > config.maxLineLength) { error(`The commit message header is longer than ${config.maxLineLength} characters`); return false; @@ -122,6 +128,16 @@ export function validateCommitMessage( return false; } + ////////////////////////// + // Checking commit body // + ////////////////////////// + + // Commit bodies are not checked for fixups and squashes as they will be squashed into + // another commit in the history anyway. + if (commit.isFixup || commit.isSquash) { + return true; + } + if (commit.bodyWithoutLinking.trim().length < config.minBodyLength) { error(`The commit message body does not meet the minimum length of ${ config.minBodyLength} characters`);