opencommit 2.4.1 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +149 -68
- package/out/cli.cjs +4499 -4057
- package/out/github-action.cjs +21972 -21511
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
<h2>Auto-generate meaningful commits in 1 second</h2>
|
|
8
8
|
<p>Killing lame commits with AI 🤯🔫</p>
|
|
9
9
|
<a href="https://www.npmjs.com/package/opencommit"><img src="https://img.shields.io/npm/v/opencommit" alt="Current version"></a>
|
|
10
|
-
<h4 align="center">🪩 Winner of GitHub 2023 HACKATHON <a href="https://twitter.com/io_Y_oi"><img style="width:
|
|
10
|
+
<h4 align="center">🪩 Winner of GitHub 2023 HACKATHON <a href="https://twitter.com/io_Y_oi/status/1683448136973582336"><img style="width:14px; height:14px; margin-top: -4px" src=".github/github-mark-white.png" align="center"></a>
|
|
11
11
|
</h4>
|
|
12
12
|
</div>
|
|
13
13
|
|
|
@@ -34,67 +34,11 @@ You can use OpenCommit by simply running it via the CLI like this `oco`. 2 secon
|
|
|
34
34
|
3. Set the key to OpenCommit config:
|
|
35
35
|
|
|
36
36
|
```sh
|
|
37
|
-
|
|
37
|
+
oco config set OCO_OPENAI_API_KEY=<your_api_key>
|
|
38
38
|
```
|
|
39
39
|
|
|
40
40
|
Your API key is stored locally in the `~/.opencommit` config file.
|
|
41
41
|
|
|
42
|
-
## Setup OpenCommit as a GitHub Action 🔥
|
|
43
|
-
|
|
44
|
-
OpenCommit is now available as a GitHub Action which automatically improves all new commits messages when you push to remote!
|
|
45
|
-
|
|
46
|
-
This is great if you want to make sure all of the commits in all of your repository branches are meaningful and not lame like `fix1` or `done2`.
|
|
47
|
-
|
|
48
|
-
Create a file `.github/workflows/opencommit.yml` with the contents below:
|
|
49
|
-
|
|
50
|
-
```yml
|
|
51
|
-
name: 'OpenCommit Action'
|
|
52
|
-
|
|
53
|
-
on:
|
|
54
|
-
push:
|
|
55
|
-
# this list of branches is often enough,
|
|
56
|
-
# but you may still ignore other public branches
|
|
57
|
-
branches-ignore: [main master dev development release]
|
|
58
|
-
|
|
59
|
-
jobs:
|
|
60
|
-
opencommit:
|
|
61
|
-
timeout-minutes: 10
|
|
62
|
-
name: OpenCommit
|
|
63
|
-
runs-on: ubuntu-latest
|
|
64
|
-
permissions: write-all
|
|
65
|
-
steps:
|
|
66
|
-
- name: Setup Node.js Environment
|
|
67
|
-
uses: actions/setup-node@v2
|
|
68
|
-
with:
|
|
69
|
-
node-version: '16'
|
|
70
|
-
- uses: actions/checkout@v3
|
|
71
|
-
with:
|
|
72
|
-
fetch-depth: 0
|
|
73
|
-
- uses: di-sukharev/opencommit@github-action-v1.0.4
|
|
74
|
-
with:
|
|
75
|
-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
76
|
-
|
|
77
|
-
env:
|
|
78
|
-
# set openAI api key in repo actions secrets,
|
|
79
|
-
# for openAI keys go to: https://platform.openai.com/account/api-keys
|
|
80
|
-
# for repo secret go to: <your_repo_url>/settings/secrets/actions
|
|
81
|
-
OCO_OPENAI_API_KEY: ${{ secrets.OCO_OPENAI_API_KEY }}
|
|
82
|
-
|
|
83
|
-
# customization
|
|
84
|
-
OCO_OPENAI_MAX_TOKENS: 500
|
|
85
|
-
OCO_OPENAI_BASE_PATH: ''
|
|
86
|
-
OCO_DESCRIPTION: false
|
|
87
|
-
OCO_EMOJI: false
|
|
88
|
-
OCO_MODEL: gpt-3.5-turbo
|
|
89
|
-
OCO_LANGUAGE: en
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
That is it. Now when you push to any branch in your repo — all NEW commits are being improved by your never-tired AI.
|
|
93
|
-
|
|
94
|
-
Make sure you exclude public collaboration branches (`main`, `dev`, `etc`) in `branches-ignore`, so OpenCommit does not rebase commits there while improving the messages.
|
|
95
|
-
|
|
96
|
-
Interactive rebase (`rebase -i`) changes commits' SHA, so the commit history in remote becomes different from your local branch history. This is okay if you work on the branch alone, but may be inconvenient for other collaborators.
|
|
97
|
-
|
|
98
42
|
## Usage
|
|
99
43
|
|
|
100
44
|
You can call OpenCommit directly to generate a commit message for your staged changes:
|
|
@@ -121,11 +65,12 @@ Create a `.env` file and add OpenCommit config variables there like this:
|
|
|
121
65
|
OCO_OPENAI_API_KEY=<your OpenAI API token>
|
|
122
66
|
OCO_OPENAI_MAX_TOKENS=<max response tokens from OpenAI API>
|
|
123
67
|
OCO_OPENAI_BASE_PATH=<may be used to set proxy path to OpenAI api>
|
|
124
|
-
OCO_DESCRIPTION=<postface a message with ~3 sentences description>
|
|
125
|
-
OCO_EMOJI=<add GitMoji>
|
|
126
|
-
OCO_MODEL=<either gpt-3.5-turbo or gpt-
|
|
68
|
+
OCO_DESCRIPTION=<postface a message with ~3 sentences description of the changes>
|
|
69
|
+
OCO_EMOJI=<boolean, add GitMoji>
|
|
70
|
+
OCO_MODEL=<either 'gpt-4', 'gpt-3.5-turbo-16k' (default), 'gpt-3.5-turbo-0613' or 'gpt-3.5-turbo'>
|
|
127
71
|
OCO_LANGUAGE=<locale, scroll to the bottom to see options>
|
|
128
|
-
OCO_MESSAGE_TEMPLATE_PLACEHOLDER=<message template placeholder,
|
|
72
|
+
OCO_MESSAGE_TEMPLATE_PLACEHOLDER=<message template placeholder, default: '$msg'>
|
|
73
|
+
OCO_PROMPT_MODULE=<either conventional-commit or @commitlint, default: conventional-commit>
|
|
129
74
|
```
|
|
130
75
|
|
|
131
76
|
### Global config for all repos
|
|
@@ -135,7 +80,7 @@ Local config still has more priority than Global config, but you may set `OCO_MO
|
|
|
135
80
|
Simply set any of the variables above like this:
|
|
136
81
|
|
|
137
82
|
```sh
|
|
138
|
-
oco config set
|
|
83
|
+
oco config set OCO_MODEL=gpt-4
|
|
139
84
|
```
|
|
140
85
|
|
|
141
86
|
Configure [GitMoji](https://gitmoji.dev/) to preface a message.
|
|
@@ -168,7 +113,7 @@ oco config set OCO_MODEL=gpt-3.5-turbo
|
|
|
168
113
|
|
|
169
114
|
Make sure that you spell it `gpt-4` (lowercase) and that you have API access to the 4th model. Even if you have ChatGPT+, that doesn't necessarily mean that you have API access to GPT-4.
|
|
170
115
|
|
|
171
|
-
|
|
116
|
+
### Locale configuration
|
|
172
117
|
|
|
173
118
|
To globally specify the language used to generate commit messages:
|
|
174
119
|
|
|
@@ -187,7 +132,55 @@ oco config set OCO_LANGUAGE=française
|
|
|
187
132
|
The default language setting is **English**
|
|
188
133
|
All available languages are currently listed in the [i18n](https://github.com/di-sukharev/opencommit/tree/master/src/i18n) folder
|
|
189
134
|
|
|
190
|
-
###
|
|
135
|
+
### Switch to `@commitlint`
|
|
136
|
+
|
|
137
|
+
OpenCommit allows you to choose the prompt module used to generate commit messages. By default, OpenCommit uses its conventional-commit message generator. However, you can switch to using the `@commitlint` prompt module if you prefer. This option lets you generate commit messages in respect with the local config.
|
|
138
|
+
|
|
139
|
+
You can set this option by running the following command:
|
|
140
|
+
|
|
141
|
+
```sh
|
|
142
|
+
oco config set OCO_PROMPT_MODULE=<module>
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
Replace `<module>` with either `conventional-commit` or `@commitlint`.
|
|
146
|
+
|
|
147
|
+
#### Example:
|
|
148
|
+
|
|
149
|
+
To switch to using th` '@commitlint` prompt module, run:
|
|
150
|
+
|
|
151
|
+
```sh
|
|
152
|
+
oco config set OCO_PROMPT_MODULE=@commitlint
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
To switch back to the default conventional-commit message generator, run:
|
|
156
|
+
|
|
157
|
+
```sh
|
|
158
|
+
oco config set OCO_PROMPT_MODULE=conventional-commit
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
#### Integrating with `@commitlint`
|
|
162
|
+
|
|
163
|
+
The integration between `@commitlint` and OpenCommit is done automatically the first time OpenCommit is run with `OCO_PROMPT_MODULE` set to `@commitlint`. However, if you need to force set or reset the configuration for `@commitlint`, you can run the following command:
|
|
164
|
+
|
|
165
|
+
```sh
|
|
166
|
+
oco commitlint force
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
To view the generated configuration for `@commitlint`, you can use this command:
|
|
170
|
+
|
|
171
|
+
```sh
|
|
172
|
+
oco commitlint get
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
This allows you to ensure that the configuration is set up as desired.
|
|
176
|
+
|
|
177
|
+
Additionally, the integration creates a file named `.opencommit-commitlint` which contains the prompts used for the local `@commitlint` configuration. You can modify this file to fine-tune the example commit message generated by OpenAI. This gives you the flexibility to make adjustments based on your preferences or project guidelines.
|
|
178
|
+
|
|
179
|
+
OpenCommit generates a file named `.opencommit-commitlint` in your project directory which contains the prompts used for the local `@commitlint` configuration. You can modify this file to fine-tune the example commit message generated by OpenAI. If the local `@commitlint` configuration changes, this file will be updated the next time OpenCommit is run.
|
|
180
|
+
|
|
181
|
+
This offers you greater control over the generated commit messages, allowing for customization that aligns with your project's conventions.
|
|
182
|
+
|
|
183
|
+
## Git flags
|
|
191
184
|
|
|
192
185
|
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`.
|
|
193
186
|
|
|
@@ -201,14 +194,41 @@ is translated to :
|
|
|
201
194
|
git commit -m "${generatedMessage}" --no-verify
|
|
202
195
|
```
|
|
203
196
|
|
|
204
|
-
To include a message in the generated message, you can utilize the template function
|
|
197
|
+
To include a message in the generated message, you can utilize the template function, for instance:
|
|
205
198
|
|
|
206
199
|
```sh
|
|
207
|
-
oco '$msg
|
|
200
|
+
oco '#205: $msg’
|
|
208
201
|
```
|
|
209
202
|
|
|
210
203
|
> opencommit examines placeholders in the parameters, allowing you to append additional information before and after the placeholders, such as the relevant Issue or Pull Request. Similarly, you have the option to customize the OCO_MESSAGE_TEMPLATE_PLACEHOLDER configuration item, for example, simplifying it to $m!"
|
|
211
204
|
|
|
205
|
+
### Message Template Placeholder Config
|
|
206
|
+
|
|
207
|
+
#### Overview
|
|
208
|
+
|
|
209
|
+
The `OCO_MESSAGE_TEMPLATE_PLACEHOLDER` feature in the `opencommit` tool allows users to embed a custom message within the generated commit message using a template function. This configuration is designed to enhance the flexibility and customizability of commit messages, making it easier for users to include relevant information directly within their commits.
|
|
210
|
+
|
|
211
|
+
#### Implementation Details
|
|
212
|
+
|
|
213
|
+
In our codebase, the implementation of this feature can be found in the following segment:
|
|
214
|
+
|
|
215
|
+
```javascript
|
|
216
|
+
commitMessage = messageTemplate.replace(
|
|
217
|
+
config?.OCO_MESSAGE_TEMPLATE_PLACEHOLDER,
|
|
218
|
+
commitMessage
|
|
219
|
+
);
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
This line is responsible for replacing the placeholder in the `messageTemplate` with the actual `commitMessage`.
|
|
223
|
+
|
|
224
|
+
#### Usage
|
|
225
|
+
|
|
226
|
+
For instance, using the command `oco '$msg #205’`, users can leverage this feature. The provided code represents the backend mechanics of such commands, ensuring that the placeholder is replaced with the appropriate commit message.
|
|
227
|
+
|
|
228
|
+
#### Committing with the Message
|
|
229
|
+
|
|
230
|
+
Once users have generated their desired commit message, they can proceed to commit using the generated message. By understanding the feature's full potential and its implementation details, users can confidently use the generated messages for their commits.
|
|
231
|
+
|
|
212
232
|
### Ignore files
|
|
213
233
|
|
|
214
234
|
You can remove files from being sent to OpenAI by creating a `.opencommitignore` file. For example:
|
|
@@ -247,6 +267,67 @@ git commit
|
|
|
247
267
|
|
|
248
268
|
Or follow the process of your IDE Source Control feature, when it calls `git commit` command — OpenCommit will integrate into the flow.
|
|
249
269
|
|
|
270
|
+
## Setup OpenCommit as a GitHub Action (BETA) 🔥
|
|
271
|
+
|
|
272
|
+
OpenCommit is now available as a GitHub Action which automatically improves all new commits messages when you push to remote!
|
|
273
|
+
|
|
274
|
+
This is great if you want to make sure all of the commits in all of your repository branches are meaningful and not lame like `fix1` or `done2`.
|
|
275
|
+
|
|
276
|
+
Create a file `.github/workflows/opencommit.yml` with the contents below:
|
|
277
|
+
|
|
278
|
+
```yml
|
|
279
|
+
name: 'OpenCommit Action'
|
|
280
|
+
|
|
281
|
+
on:
|
|
282
|
+
push:
|
|
283
|
+
# this list of branches is often enough,
|
|
284
|
+
# but you may still ignore other public branches
|
|
285
|
+
branches-ignore: [main master dev development release]
|
|
286
|
+
|
|
287
|
+
jobs:
|
|
288
|
+
opencommit:
|
|
289
|
+
timeout-minutes: 10
|
|
290
|
+
name: OpenCommit
|
|
291
|
+
runs-on: ubuntu-latest
|
|
292
|
+
permissions: write-all
|
|
293
|
+
steps:
|
|
294
|
+
- name: Setup Node.js Environment
|
|
295
|
+
uses: actions/setup-node@v2
|
|
296
|
+
with:
|
|
297
|
+
node-version: '16'
|
|
298
|
+
- uses: actions/checkout@v3
|
|
299
|
+
with:
|
|
300
|
+
fetch-depth: 0
|
|
301
|
+
- uses: di-sukharev/opencommit@github-action-v1.0.4
|
|
302
|
+
with:
|
|
303
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
304
|
+
|
|
305
|
+
env:
|
|
306
|
+
# set openAI api key in repo actions secrets,
|
|
307
|
+
# for openAI keys go to: https://platform.openai.com/account/api-keys
|
|
308
|
+
# for repo secret go to: <your_repo_url>/settings/secrets/actions
|
|
309
|
+
OCO_OPENAI_API_KEY: ${{ secrets.OCO_OPENAI_API_KEY }}
|
|
310
|
+
|
|
311
|
+
# customization
|
|
312
|
+
OCO_OPENAI_MAX_TOKENS: 500
|
|
313
|
+
OCO_OPENAI_BASE_PATH: ''
|
|
314
|
+
OCO_DESCRIPTION: false
|
|
315
|
+
OCO_EMOJI: false
|
|
316
|
+
OCO_MODEL: gpt-3.5-turbo-16k
|
|
317
|
+
OCO_LANGUAGE: en
|
|
318
|
+
OCO_PROMPT_MODULE: conventional-commit
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
That is it. Now when you push to any branch in your repo — all NEW commits are being improved by your never-tired AI.
|
|
322
|
+
|
|
323
|
+
Make sure you exclude public collaboration branches (`main`, `dev`, `etc`) in `branches-ignore`, so OpenCommit does not rebase commits there while improving the messages.
|
|
324
|
+
|
|
325
|
+
Interactive rebase (`rebase -i`) changes commits' SHA, so the commit history in remote becomes different from your local branch history. This is okay if you work on the branch alone, but may be inconvenient for other collaborators.
|
|
326
|
+
|
|
250
327
|
## Payments
|
|
251
328
|
|
|
252
|
-
You pay for your requests to OpenAI API
|
|
329
|
+
You pay for your requests to OpenAI API on your own.
|
|
330
|
+
|
|
331
|
+
OpenCommit stores your key locally.
|
|
332
|
+
|
|
333
|
+
OpenCommit by default uses ChatGPT (3.5-turbo-16k) official model, which is a lot cheaper than gpt-4.
|