angular-cn/dev-infra/pr/merge/target-label.ts
Paul Gschwendtner 318e9372c9 feat(dev-infra): move merge script over from components repo (#37138)
Moves the merge script from the components repository over
to the shared dev-infra package. The merge script has been
orginally built for all Angular repositories, but we just
kept it in the components repo temporarily to test it.

Since everything went well on the components side, we now
move the script over and integrate it into the dev-infra package.

PR Close #37138
2020-05-18 11:50:07 -07:00

29 lines
948 B
TypeScript

/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {MergeConfig, TargetLabel} from './config';
import {matchesPattern} from './string-pattern';
/** Gets the target label from the specified pull request labels. */
export function getTargetLabelFromPullRequest(config: MergeConfig, labels: string[]): TargetLabel|
null {
for (const label of labels) {
const match = config.labels.find(({pattern}) => matchesPattern(label, pattern));
if (match !== undefined) {
return match;
}
}
return null;
}
/** Gets the branches from the specified target label. */
export function getBranchesFromTargetLabel(
label: TargetLabel, githubTargetBranch: string): string[] {
return typeof label.branches === 'function' ? label.branches(githubTargetBranch) : label.branches;
}