2020-03-10 13:29:44 -04:00
|
|
|
/**
|
|
|
|
* @license
|
2020-05-19 15:08:49 -04:00
|
|
|
* Copyright Google LLC All Rights Reserved.
|
2020-03-10 13:29:44 -04:00
|
|
|
*
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
*/
|
2020-05-08 17:51:29 -04:00
|
|
|
|
|
|
|
import {assertNoErrors, getConfig, NgDevConfig} from '../utils/config';
|
|
|
|
|
2020-09-14 16:21:31 -04:00
|
|
|
/** Configuration for commit-message comands. */
|
2020-03-10 13:29:44 -04:00
|
|
|
export interface CommitMessageConfig {
|
|
|
|
maxLineLength: number;
|
|
|
|
minBodyLength: number;
|
2020-06-25 20:39:55 -04:00
|
|
|
minBodyLengthTypeExcludes?: string[];
|
2020-03-10 13:29:44 -04:00
|
|
|
scopes: string[];
|
2020-03-20 15:24:12 -04:00
|
|
|
}
|
2020-05-08 17:51:29 -04:00
|
|
|
|
|
|
|
/** Retrieve and validate the config as `CommitMessageConfig`. */
|
|
|
|
export function getCommitMessageConfig() {
|
|
|
|
// List of errors encountered validating the config.
|
|
|
|
const errors: string[] = [];
|
2020-06-25 20:39:55 -04:00
|
|
|
// The non-validated config object.
|
2020-05-08 17:51:29 -04:00
|
|
|
const config: Partial<NgDevConfig<{commitMessage: CommitMessageConfig}>> = getConfig();
|
|
|
|
|
|
|
|
if (config.commitMessage === undefined) {
|
|
|
|
errors.push(`No configuration defined for "commitMessage"`);
|
|
|
|
}
|
|
|
|
|
|
|
|
assertNoErrors(errors);
|
|
|
|
return config as Required<typeof config>;
|
|
|
|
}
|
2020-08-12 12:36:59 -04:00
|
|
|
|
2021-03-24 19:17:15 -04:00
|
|
|
/** Scope requirement level to be set for each commit type. */
|
2020-08-12 12:36:59 -04:00
|
|
|
export enum ScopeRequirement {
|
|
|
|
Required,
|
|
|
|
Optional,
|
|
|
|
Forbidden,
|
|
|
|
}
|
|
|
|
|
|
|
|
/** A commit type */
|
|
|
|
export interface CommitType {
|
2020-07-29 17:19:15 -04:00
|
|
|
description: string;
|
|
|
|
name: string;
|
2020-08-12 12:36:59 -04:00
|
|
|
scope: ScopeRequirement;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** The valid commit types for Angular commit messages. */
|
|
|
|
export const COMMIT_TYPES: {[key: string]: CommitType} = {
|
|
|
|
build: {
|
2020-07-29 17:19:15 -04:00
|
|
|
name: 'build',
|
|
|
|
description: 'Changes to local repository build system and tooling',
|
2020-09-08 15:53:21 -04:00
|
|
|
scope: ScopeRequirement.Optional,
|
2020-08-12 12:36:59 -04:00
|
|
|
},
|
|
|
|
ci: {
|
2020-07-29 17:19:15 -04:00
|
|
|
name: 'ci',
|
|
|
|
description: 'Changes to CI configuration and CI specific tooling',
|
2020-08-12 12:36:59 -04:00
|
|
|
scope: ScopeRequirement.Forbidden,
|
|
|
|
},
|
|
|
|
docs: {
|
2020-07-29 17:19:15 -04:00
|
|
|
name: 'docs',
|
|
|
|
description: 'Changes which exclusively affects documentation.',
|
2020-08-12 12:36:59 -04:00
|
|
|
scope: ScopeRequirement.Optional,
|
|
|
|
},
|
|
|
|
feat: {
|
2020-07-29 17:19:15 -04:00
|
|
|
name: 'feat',
|
|
|
|
description: 'Creates a new feature',
|
2020-08-12 12:36:59 -04:00
|
|
|
scope: ScopeRequirement.Required,
|
|
|
|
},
|
|
|
|
fix: {
|
2020-07-29 17:19:15 -04:00
|
|
|
name: 'fix',
|
|
|
|
description: 'Fixes a previously discovered failure/bug',
|
2020-08-12 12:36:59 -04:00
|
|
|
scope: ScopeRequirement.Required,
|
|
|
|
},
|
|
|
|
perf: {
|
2020-07-29 17:19:15 -04:00
|
|
|
name: 'perf',
|
|
|
|
description: 'Improves performance without any change in functionality or API',
|
2020-08-12 12:36:59 -04:00
|
|
|
scope: ScopeRequirement.Required,
|
|
|
|
},
|
|
|
|
refactor: {
|
2020-07-29 17:19:15 -04:00
|
|
|
name: 'refactor',
|
|
|
|
description: 'Refactor without any change in functionality or API (includes style changes)',
|
2020-08-12 12:36:59 -04:00
|
|
|
scope: ScopeRequirement.Required,
|
|
|
|
},
|
|
|
|
release: {
|
2020-07-29 17:19:15 -04:00
|
|
|
name: 'release',
|
|
|
|
description: 'A release point in the repository',
|
2020-08-12 12:36:59 -04:00
|
|
|
scope: ScopeRequirement.Forbidden,
|
|
|
|
},
|
|
|
|
test: {
|
2020-07-29 17:19:15 -04:00
|
|
|
name: 'test',
|
|
|
|
description: 'Improvements or corrections made to the project\'s test suite',
|
2020-08-12 12:36:59 -04:00
|
|
|
scope: ScopeRequirement.Required,
|
|
|
|
},
|
|
|
|
};
|