Skip to content

Commit aa53a75

Browse files
committed
feat: add git node staging command
Add a new `git node staging` command that automates cherry-picking commits into staging branches. It works by cherry-picking all commits that have no conflicts and skipping any commits that have conflicts while automating the sending of GitHub PR interactions to request backport for these commits, sending a message to the original PR and properly labelling it. Usage: Fetches a commit list using `branch-diff` and automatically cherry-picks / skips commits based on whether or not they land cleanly: git node staging Sets a custom reporter at the end of the automated operation: git node staging --reporter=markdown Limits to 10 the number of commits to be cherry-picked: git node staging --pagination=10 Defines the release line (usually this can be inferred from the ncu.branch value os it should not be required most of the time): git node staging --releaseLine=22 Automates the backport request message, this won't run any of the `branch-diff` or cherry-pick routines. Useful for when you removed a faulty commit from the branch and want to signal to PR author and collaborators that commit now needs backporting, just use its PR#: git node staging --backport=12345 More: The automate cherry-pick logic also includes local persistency of the ongoing commit list, in case a fatal error happens during the command execution, it's possible to resume after cleaning up the git repo state by running `git node staging` again.
1 parent 01db083 commit aa53a75

File tree

2 files changed

+524
-0
lines changed

2 files changed

+524
-0
lines changed

components/git/staging.js

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import CLI from '../../lib/cli.js';
2+
import { runPromise } from '../../lib/run.js';
3+
import { Staging } from '../../lib/staging.js';
4+
5+
export const command = 'staging';
6+
export const describe = 'Automatic port commits to a release line branch';
7+
8+
const stagingOptions = {
9+
backport: {
10+
describe: 'The PR ID / number to backport, skip staging commits',
11+
type: 'number'
12+
},
13+
paginate: {
14+
describe: 'Sets a maximum number of commits to port',
15+
type: 'number'
16+
},
17+
skipGH: {
18+
describe: 'Skip `gh` cli actions. Will not comment / label GitHub PRs',
19+
type: 'boolean'
20+
},
21+
releaseLine: {
22+
describe: 'The major version of the target release',
23+
type: 'number'
24+
},
25+
reporter: {
26+
describe: 'The reporter to use for the output',
27+
type: 'string',
28+
default: 'json'
29+
}
30+
};
31+
32+
export function builder(yargs) {
33+
return yargs
34+
.options(stagingOptions)
35+
.example('git node staging --releaseLine=1',
36+
'Port commits to the v1.x-staging branch');
37+
}
38+
39+
export function handler(argv) {
40+
const logStream = process.stdout.isTTY ? process.stdout : process.stderr;
41+
const cli = new CLI(logStream);
42+
const dir = process.cwd();
43+
44+
return runPromise(main(argv, cli, dir)).catch((err) => {
45+
if (cli.spinner.enabled) {
46+
cli.spinner.fail();
47+
}
48+
throw err;
49+
});
50+
}
51+
52+
async function main(argv, cli, dir) {
53+
const { backport, paginate, releaseLine, reporter, skipGH } = argv;
54+
const staging = new Staging({
55+
cli,
56+
dir,
57+
paginate,
58+
skipGH,
59+
releaseLine,
60+
reporter
61+
});
62+
if (backport) {
63+
await staging.requestBackport(backport);
64+
} else {
65+
await staging.run();
66+
}
67+
}

0 commit comments

Comments
 (0)