|
| 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