Compare commits

...

9 Commits

Author SHA1 Message Date
di-sukharev
71c36db265 1.1.7 2023-03-13 16:44:36 +08:00
di-sukharev
ed66e403e7 1.1.6 2023-03-13 16:44:19 +08:00
di-sukharev
b89e50ebbf * fix(generateCommitMessageFromGitDiff.ts): fix formatting of commit message prompt
* feat(generateCommitMessageFromGitDiff.ts): add description to commit message prompt
2023-03-13 16:43:59 +08:00
di-sukharev
38ebe49daa 1.1.5 2023-03-11 18:04:04 +08:00
di-sukharev
6ccded1f23 1.1.4 2023-03-11 13:24:58 +08:00
di-sukharev
31357132e4 * chore(api.ts): add error handling for openAI api error
* chore(generateCommitMessageFromGitDiff.ts): remove console.log statement
2023-03-11 13:24:02 +08:00
di-sukharev
b35a393152 * 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
2023-03-11 13:23:46 +08:00
di-sukharev
8fe382a072 1.1.3 2023-03-11 01:02:37 +08:00
di-sukharev
4b703c634a * chore(TODO.md): update TODO list, remove completed task
* refactor(cli.ts): remove unnecessary async/await keywords, remove version check and "new version available" message
2023-03-11 01:01:26 +08:00
8 changed files with 35 additions and 36 deletions

2
.github/TODO.md vendored
View File

@@ -1,7 +1,7 @@
# TODOs
- [x] set prepare-commit-msg hook
- [x] show "new version available" message, look into this commit e146d4d cli.ts file
- [] show "new version available" message, look into this commit e146d4d cli.ts file
- [] make bundle smaller by properly configuring esbuild
- [] [build for both mjs and cjs](https://snyk.io/blog/best-practices-create-modern-npm-package/)
- [] do // TODOs in the code

View File

@@ -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:

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{
"name": "opencommit",
"version": "1.1.2",
"version": "1.1.7",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "opencommit",
"version": "1.1.2",
"version": "1.1.7",
"license": "ISC",
"dependencies": {
"@clack/prompts": "^0.6.1",

View File

@@ -1,6 +1,6 @@
{
"name": "opencommit",
"version": "1.1.2",
"version": "1.1.7",
"description": "GPT CLI to auto-generate impressive commits in 1 second. Killing lame commits with AI 🤯🔫",
"keywords": [
"git",

View File

@@ -1,4 +1,6 @@
import { intro, outro } from '@clack/prompts';
import { AxiosError } from 'axios';
import chalk from 'chalk';
import {
ChatCompletionRequestMessage,
Configuration as OpenAiApiConfiguration,
@@ -17,26 +19,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=<your token>`'
'OPENAI_API_KEY is not set, please run `oc config set OPENAI_API_KEY=<your token>. 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
@@ -59,9 +50,23 @@ class OpenAi {
const message = data.choices[0].message;
return message?.content;
} catch (error) {
// console.error('openAI api error', { error });
throw error;
} catch (error: any) {
outro(`${chalk.red('✖')} ${error}`);
if (error.isAxiosError && error.response?.status === 401) {
const err = error as AxiosError;
const openAiError = (
err.response?.data as { error?: { message: string } }
).error;
if (openAiError?.message) outro(openAiError.message);
outro(
'For help look into README https://github.com/di-sukharev/opencommit#setup'
);
}
process.exit(1);
}
};
}

View File

@@ -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);
@@ -21,18 +19,11 @@ cli(
ignoreArgv: (type) => type === 'unknown-flag' || type === 'argument',
help: { description: packageJSON.description }
},
async () => {
() => {
if (isHookCalled) {
await prepareCommitMessageHook();
prepareCommitMessageHook();
} else {
await commit();
const { stdout } = await execa('npm', ['view', 'opencommit', 'version']);
if (stdout !== packageJSON.version) {
outro(
'new opencommit version is available, update with `npm i -g opencommit`'
);
}
commit();
}
},
rawArgv

View File

@@ -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);
}
};

View File

@@ -49,8 +49,8 @@ const INIT_MESSAGES_PROMPT: Array<ChatCompletionRequestMessage> = [
{
role: ChatCompletionRequestMessageRoleEnum.Assistant,
// prettier-ignore
content: `* ${config?.emoji ? '🐛 ' : ''}fix(server.ts): change port variable case from lowercase port to uppercase PORT
* ${config?.emoji ? '✨ ' : ''}feat(server.ts): add support for process.env.PORT environment variable
content: `${config?.emoji ? '🐛 ' : ''}fix(server.ts): change port variable case from lowercase port to uppercase PORT
${config?.emoji ? '✨ ' : ''}feat(server.ts): add support for process.env.PORT environment variable
${config?.description ? 'The port variable is now named PORT, which improves consistency with the naming conventions as PORT is a constant. Support for an environment variable allows the application to be more flexible as it can now run on any available port specified via the process.env.PORT environment variable.' : ''}`
}
];