Skip to content

Commit

Permalink
micro feature to rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
mistercrunch committed Apr 10, 2024
1 parent 797e8e8 commit 0c84fae
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
});
}

Check failure on line 106 in src/cli.js

View workflow job for this annotation

GitHub Actions / build

Closing curly brace does not appear on the same line as the subsequent block
else if (context.source === 'CLI') {

Check failure on line 107 in src/cli.js

View workflow job for this annotation

GitHub Actions / build

This branch can never execute. Its condition is a duplicate or covered by previous conditions in the if-else-if chain
program.command('release-label-prs')
.description('Given a set of PRs, auto-release label them')
.option('-s, --search <search>', 'extra search string to append using the GitHub mini-language')
Expand Down
12 changes: 10 additions & 2 deletions src/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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({
Expand Down

0 comments on commit 0c84fae

Please sign in to comment.