feat(dev-infra): prevent pr merges of features or breaking changes on rc (#41660)

Prevent pull requests targeting `target: rc` from merging PRs with breaking
changes or features from being merged.

PR Close #41660
This commit is contained in:
Joey Perrott 2021-04-16 08:40:54 -07:00 committed by Andrew Kushnir
parent 62e3f3279d
commit 83d6a96163
2 changed files with 12 additions and 12 deletions

View File

@ -3614,23 +3614,23 @@ function assertChangesAllowForTargetLabel(commits, label, config) {
var exemptedScopes = config.targetLabelExemptScopes || []; var exemptedScopes = config.targetLabelExemptScopes || [];
/** List of commits which are subject to content requirements for the target label. */ /** List of commits which are subject to content requirements for the target label. */
commits = commits.filter(function (commit) { return !exemptedScopes.includes(commit.scope); }); 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) { switch (label.pattern) {
case 'target: major': case 'target: major':
break; break;
case 'target: minor': case 'target: minor':
// Check if any commits in the pull request contains a breaking change. if (hasBreakingChanges) {
if (commits.some(function (commit) { return commit.breakingChanges.length !== 0; })) {
throw PullRequestFailure.hasBreakingChanges(label); throw PullRequestFailure.hasBreakingChanges(label);
} }
break; break;
case 'target: rc':
case 'target: patch': case 'target: patch':
case 'target: lts': case 'target: lts':
// Check if any commits in the pull request contains a breaking change. if (hasBreakingChanges) {
if (commits.some(function (commit) { return commit.breakingChanges.length !== 0; })) {
throw PullRequestFailure.hasBreakingChanges(label); throw PullRequestFailure.hasBreakingChanges(label);
} }
// Check if any commits in the pull request contains a commit type of "feat". if (hasFeatureCommits) {
if (commits.some(function (commit) { return commit.type === 'feat'; })) {
throw PullRequestFailure.hasFeatureCommits(label); throw PullRequestFailure.hasFeatureCommits(label);
} }
break; break;

View File

@ -200,23 +200,23 @@ function assertChangesAllowForTargetLabel(
const exemptedScopes = config.targetLabelExemptScopes || []; const exemptedScopes = config.targetLabelExemptScopes || [];
/** List of commits which are subject to content requirements for the target label. */ /** List of commits which are subject to content requirements for the target label. */
commits = commits.filter(commit => !exemptedScopes.includes(commit.scope)); 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) { switch (label.pattern) {
case 'target: major': case 'target: major':
break; break;
case 'target: minor': case 'target: minor':
// Check if any commits in the pull request contains a breaking change. if (hasBreakingChanges) {
if (commits.some(commit => commit.breakingChanges.length !== 0)) {
throw PullRequestFailure.hasBreakingChanges(label); throw PullRequestFailure.hasBreakingChanges(label);
} }
break; break;
case 'target: rc':
case 'target: patch': case 'target: patch':
case 'target: lts': case 'target: lts':
// Check if any commits in the pull request contains a breaking change. if (hasBreakingChanges) {
if (commits.some(commit => commit.breakingChanges.length !== 0)) {
throw PullRequestFailure.hasBreakingChanges(label); throw PullRequestFailure.hasBreakingChanges(label);
} }
// Check if any commits in the pull request contains a commit type of "feat". if (hasFeatureCommits) {
if (commits.some(commit => commit.type === 'feat')) {
throw PullRequestFailure.hasFeatureCommits(label); throw PullRequestFailure.hasFeatureCommits(label);
} }
break; break;