2018-06-22 00:56:51 -04:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
|
|
|
const shell = require('shelljs');
|
|
|
|
shell.config.fatal = true;
|
|
|
|
const util = require('./utils/git_util');
|
|
|
|
|
|
|
|
if (require.main === module) {
|
|
|
|
main(process.argv.splice(2)).then(
|
|
|
|
(v) => process.exitCode,
|
|
|
|
(e) => console.error(process.exitCode = 1, e)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
async function main(args) {
|
2018-10-11 19:13:59 -04:00
|
|
|
let flags = '';
|
2018-06-22 00:56:51 -04:00
|
|
|
let prNumber = 0;
|
|
|
|
let printHelp = false;
|
|
|
|
|
|
|
|
args.forEach((arg) => {
|
2018-10-11 19:13:59 -04:00
|
|
|
if (prNumber == 0 && Number.parseInt(arg) > 0) {
|
|
|
|
prNumber = Number.parseInt(arg);
|
2018-06-22 00:56:51 -04:00
|
|
|
} else if (arg == '--help') {
|
|
|
|
printHelp = true;
|
|
|
|
} else if (arg == '--force-with-lease') {
|
2018-10-11 19:13:59 -04:00
|
|
|
flags += ' --force-with-lease';
|
|
|
|
} else if (arg == '--force') {
|
|
|
|
flags += ' --force';
|
2018-06-22 00:56:51 -04:00
|
|
|
} else {
|
|
|
|
shell.echo('Unexpected argument: ', arg);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!prNumber) {
|
|
|
|
const branch = util.getCurrentBranch();
|
|
|
|
const maybePr = branch.split('/')[1];
|
|
|
|
if (maybePr > 0) {
|
|
|
|
shell.echo(`PR number not specified. Defaulting to #${maybePr}.`);
|
|
|
|
prNumber = maybePr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!prNumber || printHelp) {
|
|
|
|
shell.echo(`Push the current HEAD into an existing pull request.`);
|
|
|
|
shell.echo(``);
|
|
|
|
shell.echo(`${process.argv[1]} [PR_NUMBER] [--force-with-lease]`);
|
|
|
|
shell.echo(``);
|
|
|
|
shell.echo(` --force-with-lease Continues even \if change can\'t be fast-forwarded.`);
|
2018-10-11 19:13:59 -04:00
|
|
|
shell.echo(` --force Forces the push with --force.`);
|
2018-06-22 00:56:51 -04:00
|
|
|
shell.echo(` [PR_NUMBER] If not present the script guesses the PR from the branch name.`);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
const prInfo = await util.githubPrInfo(prNumber);
|
2018-10-11 19:13:59 -04:00
|
|
|
const prPushCmd = `git push${flags} ${prInfo.repository.gitUrl} HEAD:${prInfo.branch}`;
|
2018-06-22 00:56:51 -04:00
|
|
|
shell.echo(`>>> ${prPushCmd}`);
|
|
|
|
shell.exec(prPushCmd);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|