Joey Perrott 009f394237 feat(dev-infra): create rebase-pr tool in ng-dev (#37055)
Creates a tool in ng-dev which rebases a PR automatically and pushes
the rebase commits back to the PR.  This is meant to be a replacement
to the local merge script currently in the repo and currently has
feature parity.

PR Close #37055
2020-05-18 16:18:32 -07:00

36 lines
1.2 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 {Arguments, Argv} from 'yargs';
import {rebasePr} from './index';
/** 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 rebase pull request command. */
export function buildRebaseCommand(yargs: Argv) {
return yargs.option('github-token', {
type: 'string',
description: 'Github token. If not set, token is retrieved from the environment variables.'
});
}
/** Handles the rebase pull request command. */
export async function handleRebaseCommand(args: Arguments) {
const githubToken = args.githubToken || process.env.GITHUB_TOKEN || process.env.TOKEN;
if (!githubToken) {
console.error('No Github token set. Please set the `GITHUB_TOKEN` environment variable.');
console.error('Alternatively, pass the `--github-token` command line flag.');
console.error(`You can generate a token here: ${GITHUB_TOKEN_GENERATE_URL}`);
process.exit(1);
}
await rebasePr(args.prNumber, githubToken);
}