|
| 1 | +import { Command } from 'commander'; |
| 2 | +import { Context } from '../types.js'; |
| 3 | +import { color, Listr, ListrDefaultRendererLogLevels } from 'listr2'; |
| 4 | +import startServer from '../tasks/startServer.js'; |
| 5 | +import auth from '../tasks/auth.js'; |
| 6 | +import ctxInit from '../lib/ctx.js'; |
| 7 | +import getGitInfo from '../tasks/getGitInfo.js'; |
| 8 | +import createBuild from '../tasks/createBuild.js'; |
| 9 | +import snapshotQueue from '../lib/snapshotQueue.js'; |
| 10 | +import { startPolling, startPingPolling } from '../lib/utils.js'; |
| 11 | +import fetchBuildInfo from '../tasks/fetchBuildInfo.js' |
| 12 | +import mergeBuilds from '../tasks/mergeBuilds.js' |
| 13 | + |
| 14 | +const command = new Command(); |
| 15 | + |
| 16 | +command |
| 17 | + .name('merge') |
| 18 | + .description('Merge a source branch into the target branch') |
| 19 | + .command('branch') |
| 20 | + .description('Merge the source branch into the target branch') |
| 21 | + .requiredOption('--source <string>', 'Source branch to merge') |
| 22 | + .requiredOption('--target <string>', 'Target branch to merge into') |
| 23 | + .action(async function(this: Command, options: { source: string, target: string }) { |
| 24 | + const { source, target } = options; |
| 25 | + let ctx: Context = ctxInit(command.optsWithGlobals()); |
| 26 | + |
| 27 | + if (!source || source.trim() === '') { |
| 28 | + ctx.log.error('Error: The --source option cannot be empty.'); |
| 29 | + process.exit(1); |
| 30 | + } |
| 31 | + if (!target || target.trim() === '') { |
| 32 | + ctx.log.error('Error: The --target option cannot be empty.'); |
| 33 | + process.exit(1); |
| 34 | + } |
| 35 | + |
| 36 | + ctx.log.debug(`Merging source branch '${source}' into target branch '${target}'`); |
| 37 | + ctx.snapshotQueue = new snapshotQueue(ctx); |
| 38 | + ctx.totalSnapshots = 0; |
| 39 | + ctx.isStartExec = true; |
| 40 | + |
| 41 | + let tasks = new Listr<Context>( |
| 42 | + [ |
| 43 | + auth(ctx), |
| 44 | + fetchBuildInfo(ctx), |
| 45 | + mergeBuilds(ctx), |
| 46 | + ], |
| 47 | + { |
| 48 | + rendererOptions: { |
| 49 | + icon: { |
| 50 | + [ListrDefaultRendererLogLevels.OUTPUT]: '→' |
| 51 | + }, |
| 52 | + color: { |
| 53 | + [ListrDefaultRendererLogLevels.OUTPUT]: color.gray |
| 54 | + } |
| 55 | + } |
| 56 | + } |
| 57 | + ); |
| 58 | + |
| 59 | + try { |
| 60 | + await tasks.run(ctx); |
| 61 | + } catch (error) { |
| 62 | + console.error('Error during merge operation:', error); |
| 63 | + } |
| 64 | + }); |
| 65 | + |
| 66 | +export default command; |
0 commit comments