From 51b09244ffc033527a2c41c8432e81860a4decc1 Mon Sep 17 00:00:00 2001 From: Andrew Kushnir Date: Mon, 20 Apr 2020 16:50:25 -0700 Subject: [PATCH] fix(dev-infra): extract commit headers before checking commit message validity (#36733) This commit fixes an issue where adding `fixup` commits was triggering a lint error. The problem was caused by the fact that we used the entire message body while checking whether `fixup` commit has a corresponding "parent" commit in a range. This issue was found after enforcing a check that exits the process if there is an invalid commit message found (https://github.com/angular/angular/commit/4341743b4a6d7e23c6f944aa9e34166b701369a1). PR Close #36733 --- dev-infra/commit-message/validate-range.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/dev-infra/commit-message/validate-range.ts b/dev-infra/commit-message/validate-range.ts index e79c5df41a..1633aac443 100644 --- a/dev-infra/commit-message/validate-range.ts +++ b/dev-infra/commit-message/validate-range.ts @@ -11,6 +11,9 @@ import {parseCommitMessage, validateCommitMessage, ValidateCommitMessageOptions} // Whether the provided commit is a fixup commit. const isNonFixup = (m: string) => !parseCommitMessage(m).isFixup; +// Extracts commit header (first line of commit message). +const extractCommitHeader = (m: string) => parseCommitMessage(m).header; + /** Validate all commits in a provided git commit range. */ export function validateCommitRange(range: string) { // A random value is used as a string to allow for a definite split point in the git log result. @@ -35,7 +38,9 @@ export function validateCommitRange(range: string) { const allCommitsInRangeValid = commits.every((m, i) => { const options: ValidateCommitMessageOptions = { disallowSquash: true, - nonFixupCommitHeaders: isNonFixup(m) ? undefined : commits.slice(0, i).filter(isNonFixup) + nonFixupCommitHeaders: isNonFixup(m) ? + undefined : + commits.slice(0, i).filter(isNonFixup).map(extractCommitHeader) }; return validateCommitMessage(m, options); });