in ng-dev/pr/common/validation/validations.ts [26:71]
export function assertChangesAllowForTargetLabel(
commits: Commit[],
label: TargetLabel,
config: PullRequestConfig,
releaseTrains: ActiveReleaseTrains,
) {
/**
* List of commit scopes which are exempted from target label content requirements. i.e. no `feat`
* scopes in patch branches, no breaking changes in minor or patch changes.
*/
const exemptedScopes = config.targetLabelExemptScopes || [];
/** List of commits which are subject to content requirements for the target label. */
commits = commits.filter((commit) => !exemptedScopes.includes(commit.scope));
const hasBreakingChanges = commits.some((commit) => commit.breakingChanges.length !== 0);
const hasDeprecations = commits.some((commit) => commit.deprecations.length !== 0);
const hasFeatureCommits = commits.some((commit) => commit.type === 'feat');
switch (label.name) {
case TargetLabelName.MAJOR:
break;
case TargetLabelName.MINOR:
if (hasBreakingChanges) {
throw PullRequestFailure.hasBreakingChanges(label);
}
break;
case TargetLabelName.RELEASE_CANDIDATE:
case TargetLabelName.LONG_TERM_SUPPORT:
case TargetLabelName.PATCH:
if (hasBreakingChanges) {
throw PullRequestFailure.hasBreakingChanges(label);
}
if (hasFeatureCommits) {
throw PullRequestFailure.hasFeatureCommits(label);
}
// Deprecations should not be merged into RC, patch or LTS branches.
// https://semver.org/#spec-item-7. Deprecations should be part of
// minor releases, or major releases according to SemVer.
if (hasDeprecations && !releaseTrains.isFeatureFreeze()) {
throw PullRequestFailure.hasDeprecations(label);
}
break;
default:
warn(red('WARNING: Unable to confirm all commits in the pull request are eligible to be'));
warn(red(`merged into the target branch: ${label.name}`));
break;
}
}