36 lines
1.2 KiB
TypeScript
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);
|
||
|
}
|