glu-cli
Version:
Git stacked branch management with GitHub integration
72 lines ⢠3.02 kB
JavaScript
import ora from "ora";
import { RequestReviewUseCase } from "../../use-cases/request-review-use-case.js";
import { BaseCommand } from "../base-command.js";
import chalk from "chalk";
export class RequestReviewCommand extends BaseCommand {
requestReviewUseCase;
range;
options;
constructor(requestReviewUseCase, range, options) {
super();
this.requestReviewUseCase = requestReviewUseCase;
this.range = range;
this.options = options;
}
static create(range, options) {
const requestReviewUseCase = RequestReviewUseCase.default();
return new RequestReviewCommand(requestReviewUseCase, range, options);
}
async run() {
console.log(`Creating review branch from commits ${this.range}...\n`);
const spinner = ora(`Creating review branch from range ${this.range}...`).start();
try {
const result = await this.requestReviewUseCase.execute(this.range, this.options, {
onValidatingWorkingDirectory: () => {
spinner.text = "Validating working directory...";
},
onValidatingRange: () => {
spinner.text = "Validating commit range...";
},
onInjectingGluIds: (process, modified) => {
if (modified > 0) {
spinner.text = `Ensuring commits have glu IDs (${modified} added)...`;
}
},
onCreatingStagingBranch: () => {
spinner.text = "Creating staging branch...";
},
onCreatingReviewBranch: (branchName) => {
spinner.text = `Creating review branch: ${branchName}`;
},
onPushingBranch: (branchName) => {
spinner.text = `Pushing ${branchName} to origin...`;
},
onCleaningUp: () => {
spinner.text = `Cleaning up...`;
},
});
const successMessage = this.options.push === false
? `${chalk.green(`${result.branch}`)} created locally`
: `${chalk.green(`${result.branch}`)} created and pushed`;
if (spinner.isSpinning) {
spinner.succeed(successMessage);
}
else {
console.log(`ā ${successMessage}`);
}
console.log(`\n${chalk.cyan.bold("Commits:")}`);
result.commits.forEach((commit) => {
const shortMsg = commit.body.split("\n")[0];
console.log(` ${chalk.yellow(`${commit.hash.substring(0, 7)}`)} - ${shortMsg}`);
});
if (result.pullRequestUrl) {
console.log(`\nš Create pull request: ${chalk.cyan(`${result.pullRequestUrl}`)}`);
}
}
catch (error) {
spinner.stop();
throw error;
}
}
}
//# sourceMappingURL=request-review.js.map