8000 fix(dev-infra): detect multiple target labels as invalid by josephperrott · Pull Request #40156 · angular/angular · GitHub
[go: up one dir, main page]

Skip to content

fix(dev-infra): detect multiple target labels as invalid #40156

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix(dev-infra): detect multiple target labels as invalid
When multiple target labels are applied to a PR, it should be considered
invalid as our tooling does not support a single PR targetting multiple
trains/versions.
  • Loading branch information
josephperrott committed Dec 16, 2020
commit 26ff23a71c1fb6eb44f3a2d71fc1deed978b638c
16 changes: 11 additions & 5 deletions dev-infra/ng-dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -2782,21 +2782,21 @@ var InvalidTargetLabelError = /** @class */ (function () {
/** Gets the target label from the specified pull request labels. */
function getTargetLabelFromPullRequest(config, labels) {
var e_1, _a;
/** List of discovered target labels for the PR. */
var matches = [];
var _loop_1 = function (label) {
var match = config.labels.find(function (_a) {
var pattern = _a.pattern;
return matchesPattern(label, pattern);
});
if (match !== undefined) {
return { value: match };
matches.push(match);
}
};
try {
for (var labels_1 = tslib.__values(labels), labels_1_1 = labels_1.next(); !labels_1_1.done; labels_1_1 = labels_1.next()) {
var label = labels_1_1.value;
var state_1 = _loop_1(label);
if (typeof state_1 === "object")
return state_1.value;
_loop_1(label);
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
Expand All @@ -2806,7 +2806,13 @@ function getTargetLabelFromPullRequest(config, labels) {
}
finally { if (e_1) throw e_1.error; }
}
return null;
if (matches.length === 0) {
return null;
}
if (matches.length === 1) {
return matches[0];
}
throw new InvalidTargetLabelError("Unable to determine the target for the PR as it has multiple target labels.");
}
/**
* Gets the branches from the specified target label.
Expand Down
13 changes: 11 additions & 2 deletions dev-infra/pr/merge/target-label.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,22 @@ export class InvalidTargetLabelError {
/** Gets the target label from the specified pull request labels. */
export function getTargetLabelFromPullRequest(
config: Pick<MergeConfig, 'labels'>, labels: string[]): TargetLabel|null {
/** List of discovered target labels for the PR. */
const matches = [];
for (const label of labels) {
const match = config.labels.find(({pattern}) => matchesPattern(label, pattern));
if (match !== undefined) {
return match;
matches.push(match);
}
}
return null;
if (matches.length === 0) {
return null;
}
if (matches.length === 1) {
return matches[0];
}
throw new InvalidTargetLabelError(
`Unable to determine the target for the PR as it has multiple target labels.`);
}

/**
Expand Down
0