Skip to content
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
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(
Comment thread
josephperrott marked this conversation as resolved.
`Unable to determine the target for the PR as it has multiple target labels.`);
}

/**
Expand Down