Compare commits

...

24 Commits

Author SHA1 Message Date
di-sukharev
5d0c69e849 1.1.11 2023-03-16 11:48:42 +08:00
di-sukharev
9754442efa chore(README.md): update Twitter handle in header 2023-03-16 11:48:31 +08:00
di-sukharev
a619cd1f78 docs(README.md): update payment information to include GPT-4 cost comparison 2023-03-15 17:35:25 +08:00
di-sukharev
1fc4a6b6c0 1.1.10 2023-03-15 17:33:55 +08:00
di-sukharev
798bddba81 docs(README.md): remove outdated information about minimum supported version of Node.js 2023-03-15 17:33:43 +08:00
di-sukharev
42ed2a31f4 fix(commit.ts): remove '-u' and 'origin' arguments from git push command to push to the current branch 2023-03-15 14:51:26 +08:00
di-sukharev
571e1e9d8f chore(TODO.md): mark batch small files in one request as completed
refactor(TODO.md): rephrase optimize prompt TODO to suggest exploring cleaner alternatives to prompt
2023-03-15 14:49:38 +08:00
di-sukharev
bd8de7a8ea feat(commit.ts): add '-u origin HEAD' flag to 'git push' command to set upstream branch and push current branch to it 2023-03-15 14:46:15 +08:00
di-sukharev
913bcd379f 1.1.9 2023-03-14 18:51:06 +08:00
di-sukharev
25468f67ad 1.1.8 2023-03-14 18:50:57 +08:00
Benny Neugebauer
6766f62848 Replace type assertion with built-in error detection (#10)
* refactor(api.ts): use built-in axios error detection
2023-03-14 18:50:25 +08:00
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
di-sukharev
6821e937cf 1.1.2 2023-03-11 00:58:18 +08:00
di-sukharev
69f3c48b2c * chore(TODO.md): mark "show new version available message" as completed
* chore(package.json): add `--tag latest` flag to `npm publish` command in `deploy` script
* refactor(cli.ts): add async/await to `prepareCommitMessageHook` and `commit` functions, and check for new version of `opencommit` after commit is made
2023-03-11 00:57:48 +08:00
di-sukharev
f49f1a86df * chore(package.json): update version from 1.0.17 to 1.1.1 2023-03-11 00:55:36 +08:00
di-sukharev
98945df561 1.0.17 2023-03-11 00:53:29 +08:00
8 changed files with 32 additions and 31 deletions

3
.github/TODO.md vendored
View File

@@ -5,5 +5,6 @@
- [] 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
- [] batch small files in one request
- [x] batch small files in one request
- [] add tests
- [] optimize prompt, maybe no prompt would be cleaner

View File

@@ -2,7 +2,7 @@
<div>
<img src=".github/logo-grad.svg" alt="OpenCommit logo"/>
<h1 align="center">OpenCommit</h1>
<h4 align="center">Author <a href="https://github.com/di-sukharev">@di-sukharev</a> <a href="https://twitter.com/io_Y_oi"><img src="https://img.shields.io/twitter/follow/io_Y_oi?style=flat&label=io_Y_oi&logo=twitter&color=0bf&logoColor=fff" align="center"></a>
<h4 align="center">Follow the bird <a href="https://twitter.com/io_Y_oi"><img src="https://img.shields.io/twitter/follow/io_Y_oi?style=flat&label=io_Y_oi&logo=twitter&color=0bf&logoColor=fff" align="center"></a>
</h4>
</div>
<h2>GPT CLI to auto-generate impressive commits in 1 second</h2>
@@ -20,15 +20,13 @@ All the commits in this repo are done with OpenCommit — look into [the commits
## Setup
> The minimum supported version of Node.js is the latest v14. Check your Node.js version with `node --version`.
1. Install opencommit globally to use in any repository:
```sh
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:
@@ -113,4 +111,4 @@ Or follow the process of your IDE Source Control feature, when it calls `git com
## Payments
You pay for your own requests to OpenAI API. OpenCommit uses ChatGPT official model, that is ~10x times cheaper than GPT-3.
You pay for your own requests to OpenAI API. OpenCommit uses ChatGPT official model, that is ~10x times cheaper than GPT-3 and ~6x times cheaper than GPT-4.

4
package-lock.json generated
View File

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

View File

@@ -1,6 +1,6 @@
{
"name": "opencommit",
"version": "1.0.16",
"version": "1.1.11",
"description": "GPT CLI to auto-generate impressive commits in 1 second. Killing lame commits with AI 🤯🔫",
"keywords": [
"git",
@@ -41,7 +41,7 @@
"start": "node ./out/cli.cjs",
"dev": "ts-node ./src/cli.ts",
"build": "rimraf out && esbuild ./src/cli.ts --bundle --outfile=out/cli.cjs --format=cjs --platform=node",
"deploy": "npm run build && npm version patch && npm publish",
"deploy": "npm run build && npm version patch && npm publish --tag latest",
"lint": "eslint src --ext ts && tsc --noEmit"
},
"devDependencies": {

View File

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

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

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.' : ''}`
}
];