Skip to content

Commit 8bfc3bc

Browse files
yamork779claude
andcommitted
refactor(commit): consolidate custom prompt handling into generateCommitMessage
The generateWithCustomPrompt function has been merged into the main generateCommitMessage function by adding an optional customPrompt parameter. The function signature is simplified to reduce code duplication while maintaining the same functionality. The unused export has been removed and imports have been updated accordingly. 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
1 parent fa16e79 commit 8bfc3bc

5 files changed

Lines changed: 10 additions & 25 deletions

File tree

‎src/extension.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as vscode from "vscode";
2-
import { generateCommitMessage, editCommitMessage, generateWithCustomPrompt } from "./generators/commit";
2+
import { generateCommitMessage, editCommitMessage } from "./generators/commit";
33
import type { GitRepository, GitAPI, Language } from "./types";
44

55
/**
@@ -301,11 +301,11 @@ async function handleCustomPrompt(repo: GitRepository): Promise<void> {
301301
progress.report({ message });
302302
};
303303

304-
const newMessage = await generateWithCustomPrompt(
304+
const newMessage = await generateCommitMessage(
305305
repo,
306-
customPrompt,
307306
language,
308-
updateProgress
307+
updateProgress,
308+
customPrompt
309309
);
310310

311311
if (newMessage) {

‎src/generators/commit.ts‎

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ import { generateWithCLI, generateWithCLIManaged, generateWithAPI } from "../cli
1717
export async function generateCommitMessage(
1818
repo: GitRepository,
1919
language: Language = "en",
20-
progressCallback: ProgressCallback | null = null
20+
progressCallback: ProgressCallback | null = null,
21+
customPrompt: string = ""
2122
): Promise<string> {
2223
const repoPath = repo.rootUri.fsPath;
2324
const config = vscode.workspace.getConfiguration("claudeCommit");
@@ -42,7 +43,7 @@ export async function generateCommitMessage(
4243
const keepCoAuthoredBy = config.get<boolean>("keepCoAuthoredBy", false);
4344
const multiLine = config.get<boolean>("multiLineCommit", false);
4445
const diffSource = config.get<DiffSource>("diffSource", "auto");
45-
const prompt = createManagedPrompt(language, keepCoAuthoredBy, multiLine, diffSource, "");
46+
const prompt = createManagedPrompt(language, keepCoAuthoredBy, multiLine, diffSource, customPrompt);
4647
return await generateWithCLIManaged(prompt, repoPath, progressCallback);
4748
}
4849

@@ -149,25 +150,6 @@ export async function generateCommitMessage(
149150
);
150151
}
151152

152-
export async function generateWithCustomPrompt(
153-
repo: GitRepository,
154-
customPrompt: string,
155-
language: Language = "en",
156-
progressCallback: ProgressCallback | null = null
157-
): Promise<string> {
158-
const repoPath = repo.rootUri.fsPath;
159-
const config = vscode.workspace.getConfiguration("claudeCommit");
160-
161-
if (progressCallback) {
162-
progressCallback("Regenerating with custom prompt...");
163-
}
164-
165-
const keepCoAuthoredBy = config.get<boolean>("keepCoAuthoredBy", false);
166-
const multiLine = config.get<boolean>("multiLineCommit", false);
167-
const diffSource = config.get<DiffSource>("diffSource", "auto");
168-
const prompt = createManagedPrompt(language, keepCoAuthoredBy, multiLine, diffSource, customPrompt);
169-
return await generateWithCLIManaged(prompt, repoPath, progressCallback);
170-
}
171153

172154
export async function editCommitMessage(
173155
repo: GitRepository,

‎src/prompts/en.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ From output start to output end, strictly follow this format:
132132
133133
Keep at the end of footer:
134134
🤖 Generated with Claude Code
135+
135136
Co-Authored-By: Claude <noreply@anthropic.com>`;
136137
}
137138

‎src/prompts/ua.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ export function getManagedPrompt(keepCoAuthoredBy: boolean, multiline: boolean,
132132
133133
В кінці footer додай:
134134
🤖 Generated with Claude Code
135+
135136
Co-Authored-By: Claude <noreply@anthropic.com>`;
136137
}
137138

‎src/prompts/zh.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ export function getManagedPrompt(keepCoAuthoredBy: boolean, multiline: boolean,
132132
133133
footer 末尾保留:
134134
🤖 Generated with Claude Code
135+
135136
Co-Authored-By: Claude <noreply@anthropic.com>`;
136137
}
137138

0 commit comments

Comments
 (0)