Skip to content

Commit a82f8d0

Browse files
committedMay 27, 2023
Merge branch 'dev' of https://github.com/di-sukharev/opencommit into allowForCommitPrefix
2 parents 59bc005 + 32f3e17 commit a82f8d0

11 files changed

+202
-137
lines changed
 

‎.prettierrc

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"trailingComma": "none",
3-
"singleQuote": true
2+
"singleQuote": true,
3+
"trailingComma": "none"
44
}

‎README.md

+18-17
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ on:
3737

3838
jobs:
3939
opencommit:
40+
timeout-minutes: 10
4041
name: OpenCommit
4142
runs-on: ubuntu-latest
4243
permissions: write-all
@@ -75,7 +76,7 @@ Interactive rebase (`rebase -i`) changes commit SHA, so commit history in remote
7576

7677
## Setup OpenCommit as a CLI
7778

78-
You can use OpenCommit by simply running it via CLI like this `oc`. 2 seconds and your staged changes are committed with a meaningful message.
79+
You can use OpenCommit by simply running it via CLI like this `oco`. 2 seconds and your staged changes are committed with a meaningful message.
7980

8081
1. Install OpenCommit globally to use in any repository:
8182

@@ -102,7 +103,7 @@ git add <files...>
102103
opencommit
103104
```
104105

105-
You can also use the `oc` shortcut:
106+
You can also use the `oco` shortcut:
106107

107108
```sh
108109
git add <files...>
@@ -132,19 +133,19 @@ Local config still has more priority as Global config, but you may set `OCO_MODE
132133
Simply run any of the variable above like this:
133134

134135
```sh
135-
oc config set OCO_OPENAI_API_KEY=gpt-4
136+
oco config set OCO_OPENAI_API_KEY=gpt-4
136137
```
137138

138139
Configure [GitMoji](https://gitmoji.dev/) to preface a message.
139140

140141
```sh
141-
oc config set OCO_EMOJI=true
142+
oco config set OCO_EMOJI=true
142143
```
143144

144145
To remove preface emoji:
145146

146147
```sh
147-
oc config set OCO_EMOJI=false
148+
oco config set OCO_EMOJI=false
148149
```
149150

150151
### Switch to GPT-4
@@ -154,7 +155,7 @@ By default OpenCommit uses GPT-3.5-turbo (ChatGPT).
154155
You may switch to GPT-4 which performs better, but costs ~x15 times more 🤠
155156

156157
```sh
157-
oc config set OCO_MODEL=gpt-4
158+
oco config set OCO_MODEL=gpt-4
158159
```
159160

160161
Make sure you do lowercase `gpt-4` and you have API access to the 4th model. Even if you have ChatGPT+ it doesn't necessarily mean that you have API access to GPT-4.
@@ -165,25 +166,25 @@ To globally specify the language used to generate commit messages:
165166

166167
```sh
167168
# de, German ,Deutsch
168-
oc config set OCO_LANGUAGE=de
169-
oc config set OCO_LANGUAGE=German
170-
oc config set OCO_LANGUAGE=Deutsch
169+
oco config set OCO_LANGUAGE=de
170+
oco config set OCO_LANGUAGE=German
171+
oco config set OCO_LANGUAGE=Deutsch
171172
172173
# fr, French, française
173-
oc config set OCO_LANGUAGE=fr
174-
oc config set OCO_LANGUAGE=French
175-
oc config set OCO_LANGUAGE=française
174+
oco config set OCO_LANGUAGE=fr
175+
oco config set OCO_LANGUAGE=French
176+
oco config set OCO_LANGUAGE=française
176177
```
177178

178-
The default language set is **English**
179+
The default language set is **English**
179180
All available languages are currently listed in the [i18n](https://github.com/di-sukharev/opencommit/tree/master/src/i18n) folder
180181

181182
### Git flags
182183

183-
The `opencommit` or `oc` commands can be used in place of the `git commit -m "${generatedMessage}"` command. This means that any regular flags that are used with the `git commit` command will also be applied when using `opencommit` or `oc`.
184+
The `opencommit` or `oco` commands can be used in place of the `git commit -m "${generatedMessage}"` command. This means that any regular flags that are used with the `git commit` command will also be applied when using `opencommit` or `oco`.
184185

185186
```sh
186-
oc --no-verify
187+
oco --no-verify
187188
```
188189

189190
is translated to :
@@ -212,13 +213,13 @@ You can set OpenCommit as Git [`prepare-commit-msg`](https://git-scm.com/docs/gi
212213
To set the hook:
213214

214215
```sh
215-
oc hook set
216+
oco hook set
216217
```
217218

218219
To unset the hook:
219220

220221
```sh
221-
oc hook unset
222+
oco hook unset
222223
```
223224

224225
To use the hook:

‎out/cli.cjs

+4-5
Original file line numberDiff line numberDiff line change
@@ -16272,7 +16272,7 @@ function G3(t, e2) {
1627216272
// package.json
1627316273
var package_default = {
1627416274
name: "opencommit",
16275-
version: "2.0.17",
16275+
version: "2.0.19",
1627616276
description: "Auto-generate impressive commits in 1 second. Killing lame commits with AI \u{1F92F}\u{1F52B}",
1627716277
keywords: [
1627816278
"git",
@@ -16289,7 +16289,6 @@ var package_default = {
1628916289
main: "cli.js",
1629016290
bin: {
1629116291
opencommit: "./out/cli.cjs",
16292-
oc: "./out/cli.cjs",
1629316292
oco: "./out/cli.cjs"
1629416293
},
1629516294
repository: {
@@ -21797,7 +21796,7 @@ var [command, mode] = process.argv.slice(2);
2179721796
if (!apiKey && command !== "config" && mode !== "set" /* set */) {
2179821797
ae("opencommit");
2179921798
ce(
21800-
"OCO_OPENAI_API_KEY is not set, please run `oc config set OCO_OPENAI_API_KEY=<your token>. Make sure you add payment details, so API works.`"
21799+
"OCO_OPENAI_API_KEY is not set, please run `oco config set OCO_OPENAI_API_KEY=<your token>. Make sure you add payment details, so API works.`"
2180121800
);
2180221801
ce(
2180321802
"For help look into README https://github.com/di-sukharev/opencommit#setup"
@@ -22058,7 +22057,7 @@ var prepareCommitMessageHook = async (isStageAllFlag = false) => {
2205822057
if (changedFiles)
2205922058
await gitAdd({ files: changedFiles });
2206022059
else {
22061-
ce("No changes detected, write some code and run `oc` again");
22060+
ce("No changes detected, write some code and run `oco` again");
2206222061
process.exit(1);
2206322062
}
2206422063
}
@@ -22192,7 +22191,7 @@ async function commit(extraArgs2 = [], isStageAllFlag = false) {
2219222191
if (changedFiles2)
2219322192
await gitAdd({ files: changedFiles2 });
2219422193
else {
22195-
ce("No changes detected, write some code and run `oc` again");
22194+
ce("No changes detected, write some code and run `oco` again");
2219622195
process.exit(1);
2219722196
}
2219822197
}

‎out/github-action.cjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28600,7 +28600,7 @@ var [command, mode] = process.argv.slice(2);
2860028600
if (!apiKey && command !== "config" && mode !== "set" /* set */) {
2860128601
ae("opencommit");
2860228602
ce(
28603-
"OCO_OPENAI_API_KEY is not set, please run `oc config set OCO_OPENAI_API_KEY=<your token>. Make sure you add payment details, so API works.`"
28603+
"OCO_OPENAI_API_KEY is not set, please run `oco config set OCO_OPENAI_API_KEY=<your token>. Make sure you add payment details, so API works.`"
2860428604
);
2860528605
ce(
2860628606
"For help look into README https://github.com/di-sukharev/opencommit#setup"

‎package-lock.json

+2-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "opencommit",
3-
"version": "2.0.17",
3+
"version": "2.0.19",
44
"description": "Auto-generate impressive commits in 1 second. Killing lame commits with AI 🤯🔫",
55
"keywords": [
66
"git",
@@ -17,7 +17,6 @@
1717
"main": "cli.js",
1818
"bin": {
1919
"opencommit": "./out/cli.cjs",
20-
"oc": "./out/cli.cjs",
2120
"oco": "./out/cli.cjs"
2221
},
2322
"repository": {

‎src/api.ts

+12-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ import {
77
OpenAIApi
88
} from 'openai';
99

10-
import { CONFIG_MODES, getConfig } from './commands/config';
10+
import {CONFIG_MODES, DEFAULT_MODEL_TOKEN_LIMIT, getConfig} from './commands/config';
11+
import {tokenCount} from './utils/tokenCount';
12+
import {GenerateCommitMessageErrorEnum} from './generateCommitMessageFromGitDiff';
1113
import { execaCommandSync } from 'execa';
1214

1315
const config = getConfig();
@@ -22,7 +24,7 @@ if (!apiKey && command !== 'config' && mode !== CONFIG_MODES.set) {
2224
intro('opencommit');
2325

2426
outro(
25-
'OCO_OPENAI_API_KEY is not set, please run `oc config set OCO_OPENAI_API_KEY=<your token>. Make sure you add payment details, so API works.`'
27+
'OCO_OPENAI_API_KEY is not set, please run `oco config set OCO_OPENAI_API_KEY=<your token>. Make sure you add payment details, so API works.`'
2628
);
2729
outro(
2830
'For help look into README https://github.com/di-sukharev/opencommit#setup'
@@ -57,6 +59,14 @@ class OpenAi {
5759
max_tokens: maxTokens || 500
5860
};
5961
try {
62+
const REQUEST_TOKENS = messages.map(
63+
(msg) => tokenCount(msg.content) + 4
64+
).reduce((a, b) => a + b, 0);
65+
66+
if (REQUEST_TOKENS > (DEFAULT_MODEL_TOKEN_LIMIT - maxTokens)) {
67+
throw new Error(GenerateCommitMessageErrorEnum.tooMuchTokens);
68+
}
69+
6070
const { data } = await this.openAI.createChatCompletion(params);
6171

6272
const message = data.choices[0].message;

‎src/commands/commit.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ export async function commit(
138138

139139
if (changedFiles) await gitAdd({ files: changedFiles });
140140
else {
141-
outro('No changes detected, write some code and run `oc` again');
141+
outro('No changes detected, write some code and run `oco` again');
142142
process.exit(1);
143143
}
144144
}

‎src/commands/config.ts

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ export enum CONFIG_KEYS {
2323
OCO_PREFIX = 'OCO_PREFIX'
2424
}
2525

26+
export const DEFAULT_MODEL_TOKEN_LIMIT = 4096;
27+
2628
export enum CONFIG_MODES {
2729
get = 'get',
2830
set = 'set'

‎src/commands/prepare-commit-msg-hook.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const prepareCommitMessageHook = async (
2424

2525
if (changedFiles) await gitAdd({ files: changedFiles });
2626
else {
27-
outro('No changes detected, write some code and run `oc` again');
27+
outro('No changes detected, write some code and run `oco` again');
2828
process.exit(1);
2929
}
3030
}

0 commit comments

Comments
 (0)
Failed to load comments.