fix(dev-infra): allow npm like scopes as commit message scopes (#41430)

In the CLI and Universal, we use the package name as commit message scope. The recent changes that introduced `conventional-commits-parser` in https://github.com/angular/angular/pull/41286 breaks the parsing of such commit scopes and caused commit validations to fail.

Example: https://app.circleci.com/pipelines/github/angular/angular-cli/14420/workflows/85feb5c9-184f-4088-b924-6b9e6c91f062/jobs/238446/parallel-runs/0/steps/0-102

PR Close #41430
This commit is contained in:
Alan Agius 2021-04-02 15:59:52 +02:00 committed by atscott
parent 4ce743dfb8
commit c5e9944c42
3 changed files with 12 additions and 4 deletions

View File

@ -23,6 +23,7 @@ const config: {commitMessage: CommitMessageConfig} = {
'compiler', 'compiler',
'core', 'core',
'packaging', 'packaging',
'@angular-devkit/build-angular',
] ]
} }
}; };
@ -87,6 +88,11 @@ describe('validate-commit-message.js', () => {
[`'weird' is not an allowed type.\n => TYPES: ${TYPES}`]); [`'weird' is not an allowed type.\n => TYPES: ${TYPES}`]);
}); });
it('should pass when scope contains NPM scope', () => {
expectValidationResult(
validateCommitMessage('fix(@angular-devkit/build-angular): something'), true);
});
it('should fail when scope is invalid', () => { it('should fail when scope is invalid', () => {
const errorMessageFor = (scope: string, header: string) => const errorMessageFor = (scope: string, header: string) =>
`'${scope}' is not an allowed scope.\n => SCOPES: ${SCOPES}`; `'${scope}' is not an allowed scope.\n => SCOPES: ${SCOPES}`;

View File

@ -116,9 +116,10 @@ export function validateCommitMessage(
return false; return false;
} }
if (commit.scope && !config.scopes.includes(commit.scope)) { const fullScope = commit.npmScope ? `${commit.npmScope}/${commit.scope}` : commit.scope;
if (fullScope && !config.scopes.includes(fullScope)) {
errors.push( errors.push(
`'${commit.scope}' is not an allowed scope.\n => SCOPES: ${config.scopes.join(', ')}`); `'${fullScope}' is not an allowed scope.\n => SCOPES: ${config.scopes.join(', ')}`);
return false; return false;
} }

View File

@ -1871,8 +1871,9 @@ function validateCommitMessage(commitMsg, options = {}) {
errors.push(`Scopes are required for commits with type '${commit.type}', but no scope was provided.`); errors.push(`Scopes are required for commits with type '${commit.type}', but no scope was provided.`);
return false; return false;
} }
if (commit.scope && !config.scopes.includes(commit.scope)) { const fullScope = commit.npmScope ? `${commit.npmScope}/${commit.scope}` : commit.scope;
errors.push(`'${commit.scope}' is not an allowed scope.\n => SCOPES: ${config.scopes.join(', ')}`); if (fullScope && !config.scopes.includes(fullScope)) {
errors.push(`'${fullScope}' is not an allowed scope.\n => SCOPES: ${config.scopes.join(', ')}`);
return false; return false;
} }
// Commits with the type of `release` do not require a commit body. // Commits with the type of `release` do not require a commit body.