Skip to content

Commit

Permalink
feat: add git node staging command
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ruyadorno committed Nov 27, 2024
1 parent 01db083 commit 4dfd7c2
Show file tree
Hide file tree
Showing 2 changed files with 522 additions and 0 deletions.
67 changes: 67 additions & 0 deletions components/git/staging.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import CLI from '../../lib/cli.js';
import { runPromise } from '../../lib/run.js';
import { Staging } from '../../lib/staging.js';

export const command = 'staging';
export const describe = 'Automatic port commits to a release line branch';

const stagingOptions = {
backport: {
describe: 'The PR ID / number to backport, skip staging commits',
type: 'number'
},
paginate: {
describe: 'Sets a maximum number of commits to port',
type: 'number'
},
skipGH: {
describe: 'Skip `gh` cli actions. Will not comment / label GitHub PRs',
type: 'boolean'
},
releaseLine: {
describe: 'The major version of the target release',
type: 'number'
},
reporter: {
describe: 'The reporter to use for the output',
type: 'string',
default: 'json'
}
};

export function builder(yargs) {
return yargs
.options(stagingOptions)
.example('git node staging --releaseLine=1',
'Port commits to the v1.x-staging branch');
}

export function handler(argv) {
const logStream = process.stdout.isTTY ? process.stdout : process.stderr;
const cli = new CLI(logStream);
const dir = process.cwd();

return runPromise(main(argv, cli, dir)).catch((err) => {
if (cli.spinner.enabled) {
cli.spinner.fail();
}
throw err;
});
}

async function main(argv, cli, dir) {
const { backport, paginate, releaseLine, reporter, skipGH } = argv;
const staging = new Staging({
cli,
dir,
paginate,
skipGH,
releaseLine,
reporter
});
if (backport) {
await staging.requestBackport(backport);
} else {
await staging.run();
}
}
Loading

0 comments on commit 4dfd7c2

Please sign in to comment.