From d3531a7d415f2e90278edfceadafae6a819d08a2 Mon Sep 17 00:00:00 2001 From: Paul Gschwendtner Date: Wed, 2 Jun 2021 18:33:10 +0200 Subject: [PATCH] fix(dev-infra): breaking change and deprecation notes incorrectly picked up (#42436) If a commit message currently mentions the breaking change or deprecation note keywords, the commit message parse logic accidentally picks up the note. This could then accidentally prevent the commit from being merged (e.g. if the commit targets the patch branch but mentioned the `BREAKING CHANGE: ` marker). This commit switches the commit message notes pattern to only capture notes at the beginning of a line (also allowing accidental whitespace). This matches with the format we describe in our contribution guide, as well as with our commit message validation logic that also assumes notes at the beginning of a line. PR Close #42436 --- dev-infra/commit-message/parse.spec.ts | 18 ++++++++++++++++++ dev-infra/commit-message/parse.ts | 2 +- dev-infra/ng-dev.js | 2 +- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/dev-infra/commit-message/parse.spec.ts b/dev-infra/commit-message/parse.spec.ts index 4fa8b623cd..e7f6924fa6 100644 --- a/dev-infra/commit-message/parse.spec.ts +++ b/dev-infra/commit-message/parse.spec.ts @@ -135,6 +135,15 @@ describe('commit message parsing:', () => { expect(parsedMessage.breakingChanges[0].text).toBe(`${summary}\n\n${description}`); expect(parsedMessage.breakingChanges.length).toBe(1); }); + + it('only when keyword is at the beginning of a line', () => { + const message = buildCommitMessage({ + body: 'This changes how the `BREAKING CHANGE: ` commit message note\n' + + 'keyword is detected for the changelog.', + }); + const parsedMessage = parseCommitMessage(message); + expect(parsedMessage.breakingChanges.length).toBe(0); + }); }); describe('parses deprecation notes', () => { @@ -168,5 +177,14 @@ describe('commit message parsing:', () => { expect(parsedMessage.deprecations[0].text).toBe(`${summary}\n\n${description}`); expect(parsedMessage.deprecations.length).toBe(1); }); + + it('only when keyword is at the beginning of a line', () => { + const message = buildCommitMessage({ + body: 'This changes how the `DEPRECATED: ` commit message note\n' + + 'keyword is detected for the changelog.', + }); + const parsedMessage = parseCommitMessage(message); + expect(parsedMessage.deprecations.length).toBe(0); + }); }); }); diff --git a/dev-infra/commit-message/parse.ts b/dev-infra/commit-message/parse.ts index 1892121a0e..0cebcc8913 100644 --- a/dev-infra/commit-message/parse.ts +++ b/dev-infra/commit-message/parse.ts @@ -111,7 +111,7 @@ const parseOptions: Options&{notesPattern: (keywords: string) => RegExp} = { headerPattern, headerCorrespondence, noteKeywords: [NoteSections.BREAKING_CHANGE, NoteSections.DEPRECATED], - notesPattern: (keywords: string) => new RegExp(`(${keywords}): ?(.*)`), + notesPattern: (keywords: string) => new RegExp(`^\s*(${keywords}): ?(.*)`), }; /** Parse a commit message into its composite parts. */ diff --git a/dev-infra/ng-dev.js b/dev-infra/ng-dev.js index 0d27dd2800..dc1c8e5ddf 100755 --- a/dev-infra/ng-dev.js +++ b/dev-infra/ng-dev.js @@ -1843,7 +1843,7 @@ const parseOptions = { headerPattern, headerCorrespondence, noteKeywords: [NoteSections.BREAKING_CHANGE, NoteSections.DEPRECATED], - notesPattern: (keywords) => new RegExp(`(${keywords}): ?(.*)`), + notesPattern: (keywords) => new RegExp(`^\s*(${keywords}): ?(.*)`), }; /** Parse a commit message into its composite parts. */ const parseCommitMessage = parseInternal;