diff --git a/dev-infra/ng-dev.js b/dev-infra/ng-dev.js index 3e13d97362..9bc6e766b5 100755 --- a/dev-infra/ng-dev.js +++ b/dev-infra/ng-dev.js @@ -3614,23 +3614,23 @@ function assertChangesAllowForTargetLabel(commits, label, config) { var exemptedScopes = config.targetLabelExemptScopes || []; /** List of commits which are subject to content requirements for the target label. */ commits = commits.filter(function (commit) { return !exemptedScopes.includes(commit.scope); }); + var hasBreakingChanges = commits.some(function (commit) { return commit.breakingChanges.length !== 0; }); + var hasFeatureCommits = commits.some(function (commit) { return commit.type === 'feat'; }); switch (label.pattern) { case 'target: major': break; case 'target: minor': - // Check if any commits in the pull request contains a breaking change. - if (commits.some(function (commit) { return commit.breakingChanges.length !== 0; })) { + if (hasBreakingChanges) { throw PullRequestFailure.hasBreakingChanges(label); } break; + case 'target: rc': case 'target: patch': case 'target: lts': - // Check if any commits in the pull request contains a breaking change. - if (commits.some(function (commit) { return commit.breakingChanges.length !== 0; })) { + if (hasBreakingChanges) { throw PullRequestFailure.hasBreakingChanges(label); } - // Check if any commits in the pull request contains a commit type of "feat". - if (commits.some(function (commit) { return commit.type === 'feat'; })) { + if (hasFeatureCommits) { throw PullRequestFailure.hasFeatureCommits(label); } break; diff --git a/dev-infra/pr/merge/pull-request.ts b/dev-infra/pr/merge/pull-request.ts index b7986269eb..1b2e8fa12d 100644 --- a/dev-infra/pr/merge/pull-request.ts +++ b/dev-infra/pr/merge/pull-request.ts @@ -200,23 +200,23 @@ function assertChangesAllowForTargetLabel( 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 hasFeatureCommits = commits.some(commit => commit.type === 'feat'); switch (label.pattern) { case 'target: major': break; case 'target: minor': - // Check if any commits in the pull request contains a breaking change. - if (commits.some(commit => commit.breakingChanges.length !== 0)) { + if (hasBreakingChanges) { throw PullRequestFailure.hasBreakingChanges(label); } break; + case 'target: rc': case 'target: patch': case 'target: lts': - // Check if any commits in the pull request contains a breaking change. - if (commits.some(commit => commit.breakingChanges.length !== 0)) { + if (hasBreakingChanges) { throw PullRequestFailure.hasBreakingChanges(label); } - // Check if any commits in the pull request contains a commit type of "feat". - if (commits.some(commit => commit.type === 'feat')) { + if (hasFeatureCommits) { throw PullRequestFailure.hasFeatureCommits(label); } break;