feat(dev-infra): tooling to check out pending PR (#38474)

Creates a tool within ng-dev to checkout a pending PR from the upstream repository.  This automates
an action that many developers on the Angular team need to do periodically in the process of testing
and reviewing incoming PRs.

Example usage:
  ng-dev pr checkout <pr-number>

PR Close #38474
This commit is contained in:
Joey Perrott
2020-08-14 16:49:07 -07:00
committed by Andrew Scott
parent aaa1d8e2fe
commit 63ba74fe4e
11 changed files with 261 additions and 56 deletions

View File

@ -0,0 +1,13 @@
load("@npm_bazel_typescript//:index.bzl", "ts_library")
ts_library(
name = "checkout",
srcs = glob(["*.ts"]),
module_name = "@angular/dev-infra-private/pr/checkout",
visibility = ["//dev-infra:__subpackages__"],
deps = [
"//dev-infra/pr/common",
"//dev-infra/utils",
"@npm//@types/yargs",
],
)

View File

@ -0,0 +1,50 @@
/**
* @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 {Arguments, Argv, CommandModule} from 'yargs';
import {error} from '../../utils/console';
import {checkOutPullRequestLocally} from '../common/checkout-pr';
export interface CheckoutOptions {
prNumber: number;
'github-token'?: string;
}
/** URL to the Github page where personal access tokens can be generated. */
export const GITHUB_TOKEN_GENERATE_URL = `https://github.com/settings/tokens`;
/** Builds the checkout pull request command. */
function builder(yargs: Argv) {
return yargs.positional('prNumber', {type: 'number', demandOption: true}).option('github-token', {
type: 'string',
description: 'Github token. If not set, token is retrieved from the environment variables.'
});
}
/** Handles the checkout pull request command. */
async function handler({prNumber, 'github-token': token}: Arguments<CheckoutOptions>) {
const githubToken = token || process.env.GITHUB_TOKEN || process.env.TOKEN;
if (!githubToken) {
error('No Github token set. Please set the `GITHUB_TOKEN` environment variable.');
error('Alternatively, pass the `--github-token` command line flag.');
error(`You can generate a token here: ${GITHUB_TOKEN_GENERATE_URL}`);
process.exitCode = 1;
return;
}
const prCheckoutOptions = {allowIfMaintainerCannotModify: true, branchName: `pr-${prNumber}`};
await checkOutPullRequestLocally(prNumber, githubToken, prCheckoutOptions);
}
/** yargs command module for checking out a PR */
export const CheckoutCommandModule: CommandModule<{}, CheckoutOptions> = {
handler,
builder,
command: 'checkout <pr-number>',
describe: 'Checkout a PR from the upstream repo',
};