Skip to content

Commit b98b892

Browse files
di-sukharevEwiththeBowtiezavodnyukmalpousebastienfi
authored
v3.0.0 (#243)
* update major version --------- Co-authored-by: E Einowski <5124085+EwiththeBowtie@users.noreply.github.com> Co-authored-by: Max Zavodniuk <lovemaxonly@gmail.com> Co-authored-by: Malthe Poulsen <30603252+malpou@users.noreply.github.com> Co-authored-by: Sébastien Fichot <fichot.sebastien@gmail.com>
1 parent ba5dd84 commit b98b892

30 files changed

Lines changed: 27437 additions & 25775 deletions

.opencommitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
out

README.md

Lines changed: 148 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<h2>Auto-generate meaningful commits in 1 second</h2>
88
<p>Killing lame commits with AI 🤯🔫</p>
99
<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>
1111
</h4>
1212
</div>
1313

@@ -34,67 +34,11 @@ You can use OpenCommit by simply running it via the CLI like this `oco`. 2 secon
3434
3. Set the key to OpenCommit config:
3535

3636
```sh
37-
opencommit config set OCO_OPENAI_API_KEY=<your_api_key>
37+
oco config set OCO_OPENAI_API_KEY=<your_api_key>
3838
```
3939

4040
Your API key is stored locally in the `~/.opencommit` config file.
4141

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-
9842
## Usage
9943

10044
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:
12165
OCO_OPENAI_API_KEY=<your OpenAI API token>
12266
OCO_OPENAI_MAX_TOKENS=<max response tokens from OpenAI API>
12367
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>
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'>
12771
OCO_LANGUAGE=<locale, scroll to the bottom to see options>
128-
OCO_MESSAGE_TEMPLATE_PLACEHOLDER=<message template placeholder, example: '$msg'>
72+
OCO_MESSAGE_TEMPLATE_PLACEHOLDER=<message template placeholder, default: '$msg'>
73+
OCO_PROMPT_MODULE=<either conventional-commit or @commitlint, default: conventional-commit>
12974
```
13075

13176
### Global config for all repos
@@ -168,7 +113,7 @@ oco config set OCO_MODEL=gpt-3.5-turbo
168113

169114
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.
170115

171-
## Locale configuration
116+
### Locale configuration
172117

173118
To globally specify the language used to generate commit messages:
174119

@@ -187,7 +132,55 @@ oco config set OCO_LANGUAGE=française
187132
The default language setting is **English**
188133
All available languages are currently listed in the [i18n](https://github.com/di-sukharev/opencommit/tree/master/src/i18n) folder
189134

190-
### Git flags
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
191184

192185
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`.
193186

@@ -201,14 +194,41 @@ is translated to :
201194
git commit -m "${generatedMessage}" --no-verify
202195
```
203196

204-
To include a message in the generated message, you can utilize the template function! For instance:
197+
To include a message in the generated message, you can utilize the template function, for instance:
205198

206199
```sh
207-
oco '$msg #205’
200+
oco '#205: $msg
208201
```
209202
210203
> 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!"
211204
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+
212232
### Ignore files
213233
214234
You can remove files from being sent to OpenAI by creating a `.opencommitignore` file. For example:
@@ -247,6 +267,67 @@ git commit
247267
248268
Or follow the process of your IDE Source Control feature, when it calls `git commit` command — OpenCommit will integrate into the flow.
249269
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+
250327
## Payments
251328

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.
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.

0 commit comments

Comments
 (0)