|
| 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 | + autoSkip: { |
| 10 | + describe: 'Automatically skip commits with conflicts that have to be manually resolved', |
| 11 | + type: 'boolean' |
| 12 | + }, |
| 13 | + backport: { |
| 14 | + describe: 'The PR ID / number to backport, skip staging commits', |
| 15 | + type: 'number' |
| 16 | + }, |
| 17 | + continue: { |
| 18 | + describe: 'Continue the staging process after a conflict', |
| 19 | + type: 'boolean' |
| 20 | + }, |
| 21 | + paginate: { |
| 22 | + describe: 'Sets a maximum number of commits to port', |
| 23 | + type: 'number' |
| 24 | + }, |
| 25 | + releaseLine: { |
| 26 | + describe: 'The major version of the target release', |
| 27 | + type: 'number' |
| 28 | + }, |
| 29 | + reportDestination: { |
| 30 | + describe: 'The destination to write the report to. Possible values are: ' + |
| 31 | + 'stdout, github, or a file path, defaults to an interactive prompt.', |
| 32 | + type: 'string', |
| 33 | + default: undefined |
| 34 | + }, |
| 35 | + reporter: { |
| 36 | + describe: 'The reporter to use for the output', |
| 37 | + type: 'string', |
| 38 | + default: 'markdown' |
| 39 | + }, |
| 40 | + reset: { |
| 41 | + describe: 'Reset the staging process', |
| 42 | + type: 'boolean' |
| 43 | + }, |
| 44 | + skip: { |
| 45 | + describe: 'Continue the staging process marking the current commit as skipped', |
| 46 | + type: 'boolean' |
| 47 | + }, |
| 48 | + skipGH: { |
| 49 | + describe: 'Skip all `gh` cli actions. Will not read / add label to GitHub PRs', |
| 50 | + type: 'boolean' |
| 51 | + } |
| 52 | +}; |
| 53 | + |
| 54 | +export function builder(yargs) { |
| 55 | + return yargs |
| 56 | + .options(stagingOptions) |
| 57 | + .example('git node staging --releaseLine=23', |
| 58 | + 'Port commits to the v1.x-staging branch'); |
| 59 | +} |
| 60 | + |
| 61 | +export function handler(argv) { |
| 62 | + const logStream = process.stdout.isTTY ? process.stdout : process.stderr; |
| 63 | + const cli = new CLI(logStream); |
| 64 | + const dir = process.cwd(); |
| 65 | + |
| 66 | + return runPromise(main(argv, cli, dir)).catch((err) => { |
| 67 | + if (cli.spinner.enabled) { |
| 68 | + cli.spinner.fail(); |
| 69 | + } |
| 70 | + throw err; |
| 71 | + }); |
| 72 | +} |
| 73 | + |
| 74 | +async function main(argv, cli, dir) { |
| 75 | + const { |
| 76 | + autoSkip, |
| 77 | + backport, |
| 78 | + paginate, |
| 79 | + releaseLine, |
| 80 | + reportDestination, |
| 81 | + reporter, |
| 82 | + reset, |
| 83 | + skip, |
| 84 | + skipGH |
| 85 | + } = argv; |
| 86 | + const staging = new Staging({ |
| 87 | + cli, |
| 88 | + dir, |
| 89 | + cont: argv.continue, |
| 90 | + autoSkip, |
| 91 | + paginate, |
| 92 | + releaseLine, |
| 93 | + reportDestination, |
| 94 | + reporter, |
| 95 | + skip, |
| 96 | + skipGH |
| 97 | + }); |
| 98 | + if (backport) { |
| 99 | + await staging.requestBackport(backport); |
| 100 | + } else if (reset) { |
| 101 | + await staging.reset(); |
| 102 | + } else { |
| 103 | + await staging.run(); |
| 104 | + } |
| 105 | +} |
0 commit comments