diff --git a/src/cli.js b/src/cli.js index 65d7919..e2409b3 100755 --- a/src/cli.js +++ b/src/cli.js @@ -95,6 +95,16 @@ export default function getCLI(context) { }); if (context.source === 'CLI') { + program.command('rebase') + .description('Rebase a PR') + .addOption(issueOption) + .action(async function () { + const opts = context.processOptions(this, ['issue', 'repo']); + const github = new Github({ context }); + await github.rebase({ ...opts }); + }); + } + else if (context.source === 'CLI') { program.command('release-label-prs') .description('Given a set of PRs, auto-release label them') .option('-s, --search ', 'extra search string to append using the GitHub mini-language') diff --git a/src/github.js b/src/github.js index 539f547..5972271 100644 --- a/src/github.js +++ b/src/github.js @@ -24,7 +24,7 @@ class Github { if (!githubToken) { const msg = 'GITHUB_TOKEN is not set'; this.context.logError(msg); - //this.context.exit(1); + this.context.exit(1); } const throttledOctokit = Octokit.plugin(throttling); // eslint-disable-next-line new-cap @@ -332,7 +332,7 @@ class Github { data = await fs.promises.readFile(tomlFilePath, 'utf8'); } catch (error) { console.error('Error reading ./pyproject.toml'); - process.exit(1); + this.context.exit(1); } const parsedData = toml.parse(data); @@ -374,6 +374,14 @@ class Github { } } + async rebase({ verbose = false }) { + const shellOptions = { + verbose, raiseOnError: true, exitOnError: false, + }; + await runShellCommand({ command: 'git pull --rebase origin master', ...shellOptions }); + await runShellCommand({ command: 'git push', ...shellOptions }); + } + async searchExistingPRs(branchName) { const owner = this.context.repo.split('/')[0]; const resp = await this.octokit.rest.pulls.list({