Skip to content

Commit 0eaa9fc

Browse files
committed
refactor: use async getApiKey in model services
- Updated getApiKey calls to async - Improved error logging in git blame Updated Files 2025-05-22@08:25PM
1 parent 934b2e5 commit 0eaa9fc

File tree

6 files changed

+8
-10
lines changed

6 files changed

+8
-10
lines changed

services/codestralService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class CodestralService extends ModelService {
1818
attempt = 1
1919
): Promise<CommitMessage> {
2020
try {
21-
const apiKey: string = ConfigService.getApiKey("Codestral");
21+
const apiKey: string = await ConfigService.getApiKey("Codestral");
2222

2323
const { ok: model, error: modelError } = await ConfigService.get(
2424
"codestral",

services/configService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ const ConfigService = {
129129
message: `Enter your ${service} API Key:`,
130130
label: "API Key",
131131
prefix: "",
132-
minLength: 32
132+
minLength: 32,
133133
});
134134

135135
const { error: validationErr } = KeyValidationService.baseValidation(key);

services/geminiService.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import axios, { type AxiosError } from "axios";
22
import { errorMessages } from "../lib/constants.ts";
33
import type { CommitMessage } from "../lib/index.d.ts";
4-
import { logError } from "../lib/Logger.ts";
54
import { ConfigurationError } from "../models/errors.ts";
65
import ConfigService from "./configService.ts";
76
import { ModelService } from "./modelService.ts";
@@ -22,7 +21,7 @@ class GeminiService extends ModelService {
2221
attempt = 1
2322
): Promise<CommitMessage> {
2423
try {
25-
const apiKey: string = ConfigService.getApiKey("Gemini");
24+
const apiKey: string = await ConfigService.getApiKey("Gemini");
2625

2726
const { ok: model, error: modelError } = await ConfigService.get(
2827
"gemini",
@@ -58,7 +57,6 @@ class GeminiService extends ModelService {
5857
const message = GeminiService.extractCommitMessage(response.data);
5958
return { message, model };
6059
} catch (error) {
61-
logError(error);
6260
const axiosError = error as AxiosError;
6361
if (axiosError.response) {
6462
const { status } = axiosError.response;

services/gitBlameAnalyzer.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const GitBlameAnalyzer = {
3232
const blameOutput = this.executeGitBlame(filePath);
3333
return this.parseBlameOutput(blameOutput);
3434
} catch (error) {
35-
void logError("Error getting blame info:", error as Error);
35+
void logError("Error getting blame info:", (error as Error).message);
3636
throw error;
3737
}
3838
},
@@ -118,7 +118,7 @@ const GitBlameAnalyzer = {
118118
);
119119
return GitBlameAnalyzer.formatAnalysis(authorChanges);
120120
} catch (error) {
121-
void logError("Error analyzing changes:", error as Error);
121+
void logError("Error analyzing changes:", (error as Error).message);
122122
throw error;
123123
}
124124
},
@@ -198,7 +198,7 @@ const GitBlameAnalyzer = {
198198
const blameOutput = GitBlameAnalyzer.executeGitBlame(filePath);
199199
return GitBlameAnalyzer.parseBlameOutput(blameOutput);
200200
} catch (error) {
201-
void logError("Error getting blame info:", error as Error);
201+
void logError("Error getting blame info:", (error as Error).message);
202202
throw error;
203203
}
204204
},

services/gitService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class GitService {
3131
static initialize(): string | undefined {
3232
const { ok: output, error } = this.getRepoPath();
3333

34-
if (error !== undefined) logError(error);
34+
if (error !== undefined) logError(error.message);
3535
else {
3636
this.setRepoPath(output);
3737
return output;

services/openaiService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class OpenAIService extends ModelService {
3030
attempt = 1
3131
): Promise<CommitMessage> {
3232
try {
33-
const apiKey: string = ConfigService.getApiKey("OpenAI");
33+
const apiKey: string = await ConfigService.getApiKey("OpenAI");
3434

3535
const { ok: model, error: modelError } = await ConfigService.get(
3636
"openai",

0 commit comments

Comments
 (0)