From 700478ba89c5a5424a342b6b9814a538435dcd0d Mon Sep 17 00:00:00 2001 From: nabin Date: Sat, 28 Jun 2025 12:11:25 +0545 Subject: [PATCH] fix: validate API key based on selected AI provider Previously only checked OpenAI key even when Gemini was configured --- src/extension.ts | 44 +++++++++++++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 11 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index 8fcb66b..4dcce07 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -21,19 +21,41 @@ export async function activate(context: vscode.ExtensionContext) { } }); - const apiKey = configManager.getConfig('OPENAI_API_KEY'); - if (!apiKey) { - const result = await vscode.window.showWarningMessage( - 'OpenAI API Key not configured. Would you like to configure it now?', - 'Yes', - 'No' - ); + // Check API key based on configured AI provider + const aiProvider = configManager.getConfig('AI_PROVIDER', 'openai'); + + if (aiProvider === 'gemini') { + const geminiApiKey = configManager.getConfig('GEMINI_API_KEY'); + if (!geminiApiKey) { + const result = await vscode.window.showWarningMessage( + 'Gemini API Key not configured. Would you like to configure it now?', + 'Yes', + 'No' + ); - if (result === 'Yes') { - await vscode.commands.executeCommand( - 'workbench.action.openSettings', - 'ai-commit.OPENAI_API_KEY' + if (result === 'Yes') { + await vscode.commands.executeCommand( + 'workbench.action.openSettings', + 'ai-commit.GEMINI_API_KEY' + ); + } + } + } else { + // Default to OpenAI provider + const openaiApiKey = configManager.getConfig('OPENAI_API_KEY'); + if (!openaiApiKey) { + const result = await vscode.window.showWarningMessage( + 'OpenAI API Key not configured. Would you like to configure it now?', + 'Yes', + 'No' ); + + if (result === 'Yes') { + await vscode.commands.executeCommand( + 'workbench.action.openSettings', + 'ai-commit.OPENAI_API_KEY' + ); + } } } } catch (error) {