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
This commit is contained in:
Paul Gschwendtner 2021-06-02 18:33:10 +02:00 committed by Andrew Kushnir
parent bc5a8f4d37
commit d3531a7d41
3 changed files with 20 additions and 2 deletions

View File

@ -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);
});
});
});

View File

@ -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. */

View File

@ -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;