fix(commit): handle no-change analysis
This commit is contained in:
+32
-4
@@ -9,6 +9,13 @@ import { getCliMode, printJson, runWithSuppressedOutput } from "../helpers.climo
|
||||
import { appendPendingChangelogEntry } from "../helpers.changelog.js";
|
||||
import { resolveCommitWorkflow, type IResolvedCommitWorkflow } from "../helpers.workflow.js";
|
||||
|
||||
const isNoChangesError = (error: unknown): boolean => {
|
||||
return (
|
||||
error instanceof plugins.tsdoc.NoChangesError ||
|
||||
(error instanceof Error && error.name === "NoChangesError")
|
||||
);
|
||||
};
|
||||
|
||||
export const run = async (argvArg: any) => {
|
||||
const mode = await getCliMode(argvArg);
|
||||
const subcommand = argvArg._?.[1];
|
||||
@@ -65,7 +72,15 @@ export const run = async (argvArg: any) => {
|
||||
await runCommandStep(smartshellInstance, "Running build", workflow.buildCommand);
|
||||
break;
|
||||
case "analyze":
|
||||
nextCommitObject = await runAnalyzeStep();
|
||||
try {
|
||||
nextCommitObject = await runAnalyzeStep();
|
||||
} catch (error) {
|
||||
if (isNoChangesError(error)) {
|
||||
logger.log("info", "No uncommitted changes found. Nothing to commit.");
|
||||
return;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
answerBucket = await buildAnswerBucket(nextCommitObject, workflow, mode, argvArg);
|
||||
break;
|
||||
case "changelog":
|
||||
@@ -284,9 +299,22 @@ async function handleRecommend(mode: ICliMode): Promise<void> {
|
||||
}
|
||||
};
|
||||
|
||||
const recommendation = mode.json
|
||||
? await runWithSuppressedOutput(recommendationBuilder)
|
||||
: await recommendationBuilder();
|
||||
let recommendation: any;
|
||||
try {
|
||||
recommendation = mode.json
|
||||
? await runWithSuppressedOutput(recommendationBuilder)
|
||||
: await recommendationBuilder();
|
||||
} catch (error) {
|
||||
if (isNoChangesError(error)) {
|
||||
if (mode.json) {
|
||||
printJson({ ok: true, noChanges: true });
|
||||
} else {
|
||||
logger.log("info", "No uncommitted changes found.");
|
||||
}
|
||||
return;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
|
||||
if (mode.json) {
|
||||
printJson(recommendation);
|
||||
|
||||
Reference in New Issue
Block a user