feat(dev-infra): validate deprecation notes in commit messages (#42436)
Currently the commit message validation tool from `ng-dev` validates the `BREAKING CHANGE:` commit message notes. This commit adds a similar check for `DEPRECATED:` commit message notes. Additionally, the check for breaking changes is reworked slightly to be more tolerant (i.e. if there is only a single line break after the summary; this is acceptable as per the parser and commonly done in the COMP repo). The checks have been updated to capture wrong keywords that are commonly used instead of the correct one. e.g. if a commit message uses `DEPRECATIONS:` instead of `DEPRECATED:`, the validation will fail. This prevents changelog generation issues where breaking change notes, or deprecations are missing. This happened in the COMP repo where the `DEPRECATED:` keyword was used incorrectly. See: https://github.com/angular/components/commit/99391e79391d20c6ef2f95a3ea4fd6901dcb631d PR Close #42436
This commit is contained in:
committed by
Andrew Kushnir
parent
c0b2eeb54c
commit
bc5a8f4d37
@@ -26,16 +26,29 @@ export interface ValidateCommitMessageResult {
|
||||
|
||||
/** Regex matching a URL for an entire commit body line. */
|
||||
const COMMIT_BODY_URL_LINE_RE = /^https?:\/\/.*$/;
|
||||
|
||||
/**
|
||||
* Regex matching a breaking change.
|
||||
* Regular expression matching potential misuse of the `BREAKING CHANGE:` marker in a
|
||||
* commit message. Commit messages containing one of the following snippets will fail:
|
||||
*
|
||||
* - Starts with BREAKING CHANGE
|
||||
* - Followed by a colon
|
||||
* - Followed by a single space or two consecutive new lines
|
||||
*
|
||||
* NB: Anything after `BREAKING CHANGE` is optional to facilitate the validation.
|
||||
* - `BREAKING CHANGE <some-content>` | Here we assume the colon is missing by accident.
|
||||
* - `BREAKING-CHANGE: <some-content>` | The wrong keyword is used here.
|
||||
* - `BREAKING CHANGES: <some-content>` | The wrong keyword is used here.
|
||||
* - `BREAKING-CHANGES: <some-content>` | The wrong keyword is used here.
|
||||
*/
|
||||
const COMMIT_BODY_BREAKING_CHANGE_RE = /^BREAKING CHANGE(:( |\n{2}))?/m;
|
||||
const INCORRECT_BREAKING_CHANGE_BODY_RE =
|
||||
/^(BREAKING CHANGE[^:]|BREAKING-CHANGE|BREAKING[ -]CHANGES)/m;
|
||||
|
||||
/**
|
||||
* Regular expression matching potential misuse of the `DEPRECATED:` marker in a commit
|
||||
* message. Commit messages containing one of the following snippets will fail:
|
||||
*
|
||||
* - `DEPRECATED <some-content>` | Here we assume the colon is missing by accident.
|
||||
* - `DEPRECATIONS: <some-content>` | The wrong keyword is used here.
|
||||
* - `DEPRECATE: <some-content>` | The wrong keyword is used here.
|
||||
* - `DEPRECATES: <some-content>` | The wrong keyword is used here.
|
||||
*/
|
||||
const INCORRECT_DEPRECATION_BODY_RE = /^(DEPRECATED[^:]|DEPRECATIONS|DEPRECATE:|DEPRECATES)/m;
|
||||
|
||||
/** Validate a commit message against using the local repo's config. */
|
||||
export function validateCommitMessage(
|
||||
@@ -161,14 +174,14 @@ export function validateCommitMessage(
|
||||
// Breaking change
|
||||
// Check if the commit message contains a valid break change description.
|
||||
// https://github.com/angular/angular/blob/88fbc066775ab1a2f6a8c75f933375b46d8fa9a4/CONTRIBUTING.md#commit-message-footer
|
||||
const hasBreakingChange = COMMIT_BODY_BREAKING_CHANGE_RE.exec(commit.fullText);
|
||||
if (hasBreakingChange !== null) {
|
||||
const [, breakingChangeDescription] = hasBreakingChange;
|
||||
if (!breakingChangeDescription) {
|
||||
// Not followed by :, space or two consecutive new lines,
|
||||
errors.push(`The commit message body contains an invalid breaking change description.`);
|
||||
return false;
|
||||
}
|
||||
if (INCORRECT_BREAKING_CHANGE_BODY_RE.test(commit.fullText)) {
|
||||
errors.push(`The commit message body contains an invalid breaking change note.`);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (INCORRECT_DEPRECATION_BODY_RE.test(commit.fullText)) {
|
||||
errors.push(`The commit message body contains an invalid deprecation note.`);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user