opencommit 2.4.2 → 3.0.1

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.
Files changed (4) hide show
  1. package/README.md +151 -68
  2. package/out/cli.cjs +4500 -4057
  3. package/package.json +6 -3
  4. package/out/github-action.cjs +0 -28321
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:18px; height:18px;" src=".github/github-mark-white.png" align="center"></a>
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
 
@@ -29,72 +29,18 @@ You can use OpenCommit by simply running it via the CLI like this `oco`. 2 secon
29
29
  npm install -g opencommit
30
30
  ```
31
31
 
32
+ MacOS may ask to run the command with `sudo` when installing a package globally.
33
+
32
34
  2. Get your API key from [OpenAI](https://platform.openai.com/account/api-keys). Make sure that you add your payment details, so the API works.
33
35
 
34
36
  3. Set the key to OpenCommit config:
35
37
 
36
38
  ```sh
37
- opencommit config set OCO_OPENAI_API_KEY=<your_api_key>
39
+ oco config set OCO_OPENAI_API_KEY=<your_api_key>
38
40
  ```
39
41
 
40
42
  Your API key is stored locally in the `~/.opencommit` config file.
41
43
 
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
44
  ## Usage
99
45
 
100
46
  You can call OpenCommit directly to generate a commit message for your staged changes:
@@ -121,11 +67,12 @@ Create a `.env` file and add OpenCommit config variables there like this:
121
67
  OCO_OPENAI_API_KEY=<your OpenAI API token>
122
68
  OCO_OPENAI_MAX_TOKENS=<max response tokens from OpenAI API>
123
69
  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-4>
70
+ OCO_DESCRIPTION=<postface a message with ~3 sentences description of the changes>
71
+ OCO_EMOJI=<boolean, add GitMoji>
72
+ OCO_MODEL=<either 'gpt-4', 'gpt-3.5-turbo-16k' (default), 'gpt-3.5-turbo-0613' or 'gpt-3.5-turbo'>
127
73
  OCO_LANGUAGE=<locale, scroll to the bottom to see options>
128
- OCO_MESSAGE_TEMPLATE_PLACEHOLDER=<message template placeholder, example: '$msg'>
74
+ OCO_MESSAGE_TEMPLATE_PLACEHOLDER=<message template placeholder, default: '$msg'>
75
+ OCO_PROMPT_MODULE=<either conventional-commit or @commitlint, default: conventional-commit>
129
76
  ```
130
77
 
131
78
  ### Global config for all repos
@@ -135,7 +82,7 @@ Local config still has more priority than Global config, but you may set `OCO_MO
135
82
  Simply set any of the variables above like this:
136
83
 
137
84
  ```sh
138
- oco config set OCO_OPENAI_API_KEY=gpt-4
85
+ oco config set OCO_MODEL=gpt-4
139
86
  ```
140
87
 
141
88
  Configure [GitMoji](https://gitmoji.dev/) to preface a message.
@@ -168,7 +115,7 @@ oco config set OCO_MODEL=gpt-3.5-turbo
168
115
 
169
116
  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
117
 
171
- ## Locale configuration
118
+ ### Locale configuration
172
119
 
173
120
  To globally specify the language used to generate commit messages:
174
121
 
@@ -187,7 +134,55 @@ oco config set OCO_LANGUAGE=française
187
134
  The default language setting is **English**
188
135
  All available languages are currently listed in the [i18n](https://github.com/di-sukharev/opencommit/tree/master/src/i18n) folder
189
136
 
190
- ### Git flags
137
+ ### Switch to `@commitlint`
138
+
139
+ 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.
140
+
141
+ You can set this option by running the following command:
142
+
143
+ ```sh
144
+ oco config set OCO_PROMPT_MODULE=<module>
145
+ ```
146
+
147
+ Replace `<module>` with either `conventional-commit` or `@commitlint`.
148
+
149
+ #### Example:
150
+
151
+ To switch to using th` '@commitlint` prompt module, run:
152
+
153
+ ```sh
154
+ oco config set OCO_PROMPT_MODULE=@commitlint
155
+ ```
156
+
157
+ To switch back to the default conventional-commit message generator, run:
158
+
159
+ ```sh
160
+ oco config set OCO_PROMPT_MODULE=conventional-commit
161
+ ```
162
+
163
+ #### Integrating with `@commitlint`
164
+
165
+ 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:
166
+
167
+ ```sh
168
+ oco commitlint force
169
+ ```
170
+
171
+ To view the generated configuration for `@commitlint`, you can use this command:
172
+
173
+ ```sh
174
+ oco commitlint get
175
+ ```
176
+
177
+ This allows you to ensure that the configuration is set up as desired.
178
+
179
+ 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.
180
+
181
+ 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.
182
+
183
+ This offers you greater control over the generated commit messages, allowing for customization that aligns with your project's conventions.
184
+
185
+ ## Git flags
191
186
 
192
187
  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
188
 
@@ -201,14 +196,41 @@ is translated to :
201
196
  git commit -m "${generatedMessage}" --no-verify
202
197
  ```
203
198
 
204
- To include a message in the generated message, you can utilize the template function! For instance:
199
+ To include a message in the generated message, you can utilize the template function, for instance:
205
200
 
206
201
  ```sh
207
- oco '$msg #205
202
+ oco '#205: $msg’
208
203
  ```
209
204
 
210
205
  > 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
206
 
207
+ ### Message Template Placeholder Config
208
+
209
+ #### Overview
210
+
211
+ 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.
212
+
213
+ #### Implementation Details
214
+
215
+ In our codebase, the implementation of this feature can be found in the following segment:
216
+
217
+ ```javascript
218
+ commitMessage = messageTemplate.replace(
219
+ config?.OCO_MESSAGE_TEMPLATE_PLACEHOLDER,
220
+ commitMessage
221
+ );
222
+ ```
223
+
224
+ This line is responsible for replacing the placeholder in the `messageTemplate` with the actual `commitMessage`.
225
+
226
+ #### Usage
227
+
228
+ 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.
229
+
230
+ #### Committing with the Message
231
+
232
+ 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.
233
+
212
234
  ### Ignore files
213
235
 
214
236
  You can remove files from being sent to OpenAI by creating a `.opencommitignore` file. For example:
@@ -247,6 +269,67 @@ git commit
247
269
 
248
270
  Or follow the process of your IDE Source Control feature, when it calls `git commit` command — OpenCommit will integrate into the flow.
249
271
 
272
+ ## Setup OpenCommit as a GitHub Action (BETA) 🔥
273
+
274
+ OpenCommit is now available as a GitHub Action which automatically improves all new commits messages when you push to remote!
275
+
276
+ 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`.
277
+
278
+ Create a file `.github/workflows/opencommit.yml` with the contents below:
279
+
280
+ ```yml
281
+ name: 'OpenCommit Action'
282
+
283
+ on:
284
+ push:
285
+ # this list of branches is often enough,
286
+ # but you may still ignore other public branches
287
+ branches-ignore: [main master dev development release]
288
+
289
+ jobs:
290
+ opencommit:
291
+ timeout-minutes: 10
292
+ name: OpenCommit
293
+ runs-on: ubuntu-latest
294
+ permissions: write-all
295
+ steps:
296
+ - name: Setup Node.js Environment
297
+ uses: actions/setup-node@v2
298
+ with:
299
+ node-version: '16'
300
+ - uses: actions/checkout@v3
301
+ with:
302
+ fetch-depth: 0
303
+ - uses: di-sukharev/opencommit@github-action-v1.0.4
304
+ with:
305
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
306
+
307
+ env:
308
+ # set openAI api key in repo actions secrets,
309
+ # for openAI keys go to: https://platform.openai.com/account/api-keys
310
+ # for repo secret go to: <your_repo_url>/settings/secrets/actions
311
+ OCO_OPENAI_API_KEY: ${{ secrets.OCO_OPENAI_API_KEY }}
312
+
313
+ # customization
314
+ OCO_OPENAI_MAX_TOKENS: 500
315
+ OCO_OPENAI_BASE_PATH: ''
316
+ OCO_DESCRIPTION: false
317
+ OCO_EMOJI: false
318
+ OCO_MODEL: gpt-3.5-turbo-16k
319
+ OCO_LANGUAGE: en
320
+ OCO_PROMPT_MODULE: conventional-commit
321
+ ```
322
+
323
+ That is it. Now when you push to any branch in your repo — all NEW commits are being improved by your never-tired AI.
324
+
325
+ Make sure you exclude public collaboration branches (`main`, `dev`, `etc`) in `branches-ignore`, so OpenCommit does not rebase commits there while improving the messages.
326
+
327
+ 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.
328
+
250
329
  ## Payments
251
330
 
252
- You pay for your requests to OpenAI API. OpenCommit uses ChatGPT (3.5-turbo) official model, which is ~15x times cheaper than GPT-4.
331
+ You pay for your requests to OpenAI API on your own.
332
+
333
+ OpenCommit stores your key locally.
334
+
335
+ OpenCommit by default uses ChatGPT (3.5-turbo-16k) official model, which is a lot cheaper than gpt-4.