backport
Version:
A CLI tool that automates the process of backporting commits
48 lines • 2.14 kB
JavaScript
import { BackportError } from './backport-error.js';
import { cherrypickAndCreateTargetPullRequest } from './cherrypickAndCreateTargetPullRequest/cherrypick-and-create-target-pull-request.js';
import { getLogfilePath } from './env.js';
import { logger, consoleLog } from './logger.js';
import { sequentially } from './sequential-helper.js';
export async function runSequentially({ options, commits, targetBranches, }) {
logger.verbose('Backport options', options);
const results = [];
await sequentially(targetBranches, async (targetBranch) => {
logger.info(`Backporting ${JSON.stringify(commits)} to ${targetBranch}`);
try {
const { number, url } = await cherrypickAndCreateTargetPullRequest({
options,
commits,
targetBranch,
});
results.push({
targetBranch,
status: 'success',
pullRequestUrl: url,
pullRequestNumber: number,
});
}
catch (error) {
const isBackportError = error instanceof BackportError;
const errorMessage = error instanceof Error ? error.message : String(error);
const errorCode = isBackportError ? error.errorContext.code : 'unhandled-exception';
const errorContext = isBackportError ? error.errorContext : undefined;
results.push({
status: 'error',
targetBranch,
errorMessage,
errorCode,
errorContext,
});
logger.error('runSequentially failed', error);
if (isBackportError) {
if (errorCode !== 'invalid-branch-exception') {
consoleLog(errorMessage);
}
return;
}
consoleLog(`An unhandled error occurred while backporting commit. Re-run with --verbose for details or see the logfile: ${getLogfilePath({ logFilePath: options.logFilePath, logLevel: 'info' })}`);
}
});
return results;
}
//# sourceMappingURL=run-sequentially.js.map