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
This commit is contained in:
Joey Perrott 2020-04-14 15:25:05 -07:00 committed by Andrew Kushnir
parent f0ec4ae941
commit 5e579c4dc9
1 changed files with 17 additions and 1 deletions

View File

@ -20,7 +20,7 @@ const SQUASH_PREFIX_RE = /^squash! /i;
const REVERT_PREFIX_RE = /^revert:? /i; const REVERT_PREFIX_RE = /^revert:? /i;
const TYPE_SCOPE_RE = /^(\w+)(?:\(([^)]+)\))?\:\s(.+)$/; const TYPE_SCOPE_RE = /^(\w+)(?:\(([^)]+)\))?\:\s(.+)$/;
const COMMIT_HEADER_RE = /^(.*)/i; 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. */ /** Parse a full commit message into its composite parts. */
export function parseCommitMessage(commitMsg: string) { export function parseCommitMessage(commitMsg: string) {
@ -79,6 +79,9 @@ export function validateCommitMessage(
const config = getAngularDevConfig<'commitMessage', CommitMessageConfig>().commitMessage; const config = getAngularDevConfig<'commitMessage', CommitMessageConfig>().commitMessage;
const commit = parseCommitMessage(commitMsg); const commit = parseCommitMessage(commitMsg);
////////////////////////////////////
// Checking revert, squash, fixup //
////////////////////////////////////
if (commit.isRevert) { if (commit.isRevert) {
return true; return true;
} }
@ -102,6 +105,9 @@ export function validateCommitMessage(
return true; return true;
} }
////////////////////////////
// Checking commit header //
////////////////////////////
if (commit.header.length > config.maxLineLength) { if (commit.header.length > config.maxLineLength) {
error(`The commit message header is longer than ${config.maxLineLength} characters`); error(`The commit message header is longer than ${config.maxLineLength} characters`);
return false; return false;
@ -122,6 +128,16 @@ export function validateCommitMessage(
return false; 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) { if (commit.bodyWithoutLinking.trim().length < config.minBodyLength) {
error(`The commit message body does not meet the minimum length of ${ error(`The commit message body does not meet the minimum length of ${
config.minBodyLength} characters`); config.minBodyLength} characters`);