Skip to content

Commit 77fb8b4

Browse files
thePunderWomanjosephperrott
authored andcommitted
refactor(ng-dev): add option for interactive rebase (#2727)
There are a lot of PRs that just need a commit message fix. This adds a -i flag so people can just interactively rebase to fix that for people quickly rather than dealing with a bunch of back and forth. PR Close #2727
1 parent 40b1b25 commit 77fb8b4

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

ng-dev/pr/rebase/cli.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,24 @@ import {rebasePr} from './index.js';
1515
/** The options available to the rebase command via CLI. */
1616
export interface RebaseOptions {
1717
pr: number;
18+
i?: boolean;
1819
}
1920

2021
/** Builds the rebase pull request command. */
2122
function builder(argv: Argv): Argv<RebaseOptions> {
22-
return addGithubTokenOption(argv).positional('pr', {type: 'number', demandOption: true});
23+
return addGithubTokenOption(argv)
24+
.positional('pr', {type: 'number', demandOption: true})
25+
.option('interactive', {
26+
type: 'boolean',
27+
alias: ['i'],
28+
demandOption: false,
29+
describe: 'Do the rebase interactively so that things can be squashed and amended',
30+
});
2331
}
2432

2533
/** Handles the rebase pull request command. */
26-
async function handler({pr}: Arguments<RebaseOptions>) {
27-
process.exitCode = await rebasePr(pr);
34+
async function handler({pr, i}: Arguments<RebaseOptions>) {
35+
process.exitCode = await rebasePr(pr, i);
2836
}
2937

3038
/** yargs command module for rebasing a PR */

ng-dev/pr/rebase/index.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {fetchPullRequestFromGithub} from '../common/fetch-pull-request.js';
1919
*
2020
* @returns a status code indicating whether the rebase was successful.
2121
*/
22-
export async function rebasePr(prNumber: number): Promise<number> {
22+
export async function rebasePr(prNumber: number, interactive: boolean = false): Promise<number> {
2323
/** The singleton instance of the authenticated git client. */
2424
const git = await AuthenticatedGitClient.get();
2525

@@ -99,9 +99,18 @@ export async function rebasePr(prNumber: number): Promise<number> {
9999
* Additional flags to perform the autosquashing are added when the user confirm squashing of
100100
* fixup commits should occur.
101101
*/
102-
const [flags, env] = squashFixups
103-
? [['--interactive', '--autosquash'], {...process.env, GIT_SEQUENCE_EDITOR: 'true'}]
104-
: [[], undefined];
102+
103+
let flags: string[] = [];
104+
let env = undefined;
105+
106+
if (squashFixups || interactive) {
107+
env = {...process.env, GIT_SEQUENCE_EDITOR: 'true'};
108+
flags.push('--interactive');
109+
}
110+
if (squashFixups) {
111+
flags.push('--autosquash');
112+
}
113+
105114
const rebaseResult = git.runGraceful(['rebase', ...flags, 'FETCH_HEAD'], {env: env});
106115

107116
// If the rebase was clean, push the rebased PR up to the authors fork.

0 commit comments

Comments
 (0)