f0766a4474
Previously, each Angular repository had its own strategy/configuration for merging pull requests and cherry-picking. We worked out a new strategy for labeling/branching/versioning that should be the canonical strategy for all actively maintained projects in the Angular organization. This PR provides a `ng-dev` merge configuration that implements the labeling/branching/merging as per the approved proposal. See the following document for the proposal this commit is based on for the merge script labeling/branching: https://docs.google.com/document/d/197kVillDwx-RZtSVOBtPb4BBIAw0E9RT3q3v6DZkykU The merge tool label configuration can be conveniently accesed within each `.ng-dev` configuration, and can also be extended if there are special labels on individual projects. This is one of the reasons why the labels are not directly built into the merge script. The script should remain unopinionated and flexible. The configuration is conceptually powerful enough to achieve the procedures as outlined in the versioning/branching/labeling proposal. PR Close #38223
51 lines
1.6 KiB
TypeScript
51 lines
1.6 KiB
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';
|
|
|
|
/**
|
|
* Unique error that can be thrown in the merge configuration if an
|
|
* invalid branch is targeted.
|
|
*/
|
|
export class InvalidTargetBranchError {
|
|
constructor(public failureMessage: string) {}
|
|
}
|
|
|
|
/**
|
|
* Unique error that can be thrown in the merge configuration if an
|
|
* invalid label has been applied to a pull request.
|
|
*/
|
|
export class InvalidTargetLabelError {
|
|
constructor(public failureMessage: string) {}
|
|
}
|
|
|
|
/** Gets the target label from the specified pull request labels. */
|
|
export function getTargetLabelFromPullRequest(
|
|
config: Pick<MergeConfig, 'labels'>, 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.
|
|
*
|
|
* @throws {InvalidTargetLabelError} Invalid label has been applied to pull request.
|
|
* @throws {InvalidTargetBranchError} Invalid Github target branch has been selected.
|
|
*/
|
|
export async function getBranchesFromTargetLabel(
|
|
label: TargetLabel, githubTargetBranch: string): Promise<string[]> {
|
|
return typeof label.branches === 'function' ? await label.branches(githubTargetBranch) :
|
|
await label.branches;
|
|
}
|