mirror of
https://github.com/di-sukharev/opencommit.git
synced 2026-01-13 07:38:01 -05:00
Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
913bcd379f | ||
|
|
25468f67ad | ||
|
|
6766f62848 | ||
|
|
71c36db265 | ||
|
|
ed66e403e7 | ||
|
|
b89e50ebbf | ||
|
|
38ebe49daa | ||
|
|
6ccded1f23 | ||
|
|
31357132e4 | ||
|
|
b35a393152 | ||
|
|
8fe382a072 | ||
|
|
4b703c634a |
2
.github/TODO.md
vendored
2
.github/TODO.md
vendored
@@ -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
|
||||
|
||||
@@ -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
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "opencommit",
|
||||
"version": "1.1.2",
|
||||
"version": "1.1.9",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "opencommit",
|
||||
"version": "1.1.2",
|
||||
"version": "1.1.9",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@clack/prompts": "^0.6.1",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "opencommit",
|
||||
"version": "1.1.2",
|
||||
"version": "1.1.9",
|
||||
"description": "GPT CLI to auto-generate impressive commits in 1 second. Killing lame commits with AI 🤯🔫",
|
||||
"keywords": [
|
||||
"git",
|
||||
|
||||
33
src/api.ts
33
src/api.ts
@@ -1,4 +1,6 @@
|
||||
import { intro, outro } from '@clack/prompts';
|
||||
import axios 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,19 @@ class OpenAi {
|
||||
const message = data.choices[0].message;
|
||||
|
||||
return message?.content;
|
||||
} catch (error) {
|
||||
// console.error('openAI api error', { error });
|
||||
throw error;
|
||||
} catch (error: unknown) {
|
||||
outro(`${chalk.red('✖')} ${error}`);
|
||||
|
||||
if (axios.isAxiosError<{ error?: { message: string } }>(error) && error.response?.status === 401) {
|
||||
const openAiError = error.response.data.error;
|
||||
|
||||
if (openAiError?.message) outro(openAiError.message);
|
||||
outro(
|
||||
'For help look into README https://github.com/di-sukharev/opencommit#setup'
|
||||
);
|
||||
}
|
||||
|
||||
process.exit(1);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
15
src/cli.ts
15
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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -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.' : ''}`
|
||||
}
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user