From b35a393152c876dd49c826f92cd37fe1fd7f781e Mon Sep 17 00:00:00 2001 From: di-sukharev Date: Sat, 11 Mar 2023 13:23:46 +0800 Subject: [PATCH] * docs(README.md): add reminder to add payment details to OpenAI API key * docs(api.ts): update error message to remind user to add payment details to OpenAI API key * refactor(cli.ts): remove unused import * refactor(config.ts): update error message to use outro instead of throwing an error and exit the process * chore(generateCommitMessageFromGitDiff.ts): add console.log for error debugging --- README.md | 2 +- src/api.ts | 15 ++------------- src/cli.ts | 2 -- src/commands/config.ts | 5 ++++- src/generateCommitMessageFromGitDiff.ts | 1 + 5 files changed, 8 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index b5f3b2a..c613115 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ All the commits in this repo are done with OpenCommit — look into [the commits npm install -g opencommit ``` -2. Get your API key from [OpenAI](https://platform.openai.com/account/api-keys) +2. Get your API key from [OpenAI](https://platform.openai.com/account/api-keys). Make sure you add payment details, so API works. 3. Set the key to opencommit config: diff --git a/src/api.ts b/src/api.ts index b82e518..2be4cf5 100644 --- a/src/api.ts +++ b/src/api.ts @@ -17,26 +17,15 @@ if (!apiKey && command !== 'config' && mode !== CONFIG_MODES.set) { intro('opencommit'); outro( - 'OPENAI_API_KEY is not set, please run `oc config set OPENAI_API_KEY=`' + 'OPENAI_API_KEY is not set, please run `oc config set OPENAI_API_KEY=. Make sure you add payment details, so API works.`' ); outro( - 'For help Look into README https://github.com/di-sukharev/opencommit#setup' + 'For help look into README https://github.com/di-sukharev/opencommit#setup' ); process.exit(1); } -// if (!apiKey) { -// intro('opencommit'); -// const apiKey = await text({ -// message: 'input your OPENAI_API_KEY' -// }); - -// setConfig([[CONFIG_KEYS.OPENAI_API_KEY as string, apiKey as any]]); - -// outro('OPENAI_API_KEY is set'); -// } - class OpenAi { private openAiApiConfiguration = new OpenAiApiConfiguration({ apiKey: apiKey diff --git a/src/cli.ts b/src/cli.ts index e669ce4..5bc56e5 100755 --- a/src/cli.ts +++ b/src/cli.ts @@ -7,8 +7,6 @@ import { configCommand } from './commands/config'; import { hookCommand, isHookCalled } from './commands/githook.js'; import { prepareCommitMessageHook } from './commands/prepare-commit-msg-hook'; import { commit } from './commands/commit'; -import { execa } from 'execa'; -import { outro } from '@clack/prompts'; const rawArgv = process.argv.slice(2); diff --git a/src/commands/config.ts b/src/commands/config.ts index 55c59ae..e104035 100644 --- a/src/commands/config.ts +++ b/src/commands/config.ts @@ -24,7 +24,10 @@ const validateConfig = ( validationMessage: string ) => { if (!condition) { - throw new Error(`Unsupported config key ${key}: ${validationMessage}`); + outro( + `${chalk.red('✖')} Unsupported config key ${key}: ${validationMessage}` + ); + process.exit(1); } }; diff --git a/src/generateCommitMessageFromGitDiff.ts b/src/generateCommitMessageFromGitDiff.ts index 4aabcc4..d860e2d 100644 --- a/src/generateCommitMessageFromGitDiff.ts +++ b/src/generateCommitMessageFromGitDiff.ts @@ -105,6 +105,7 @@ export const generateCommitMessageWithChatCompletion = async ( return commitMessage; } } catch (error) { + console.log({ error }); return { error: GenerateCommitMessageErrorEnum.internalError }; } };