forked from di-sukharev/opencommit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Marge remote-tracking branch 'di-sukharev/master'
Upgrade from upstream
- Loading branch information
Showing
23 changed files
with
30,556 additions
and
2,577 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,7 @@ | ||
node_modules/ | ||
coverage/ | ||
out/ | ||
temp/ | ||
build/ | ||
dist/ | ||
application.log | ||
.DS_Store | ||
/*.env | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
/build | ||
/dist | ||
/dist | ||
/out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
<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> | ||
<h2>Auto-generate meaningful commits in 1 second</h2> | ||
<p>Killing lame commits with AI 🤯🔫</p> | ||
<a href="https://www.npmjs.com/package/opencommit"><img src="https://img.shields.io/npm/v/opencommit" alt="Current version"></a> | ||
</div> | ||
|
@@ -18,7 +18,65 @@ | |
|
||
All the commits in this repo are done with OpenCommit — look into [the commits](https://github.com/di-sukharev/opencommit/commit/eae7618d575ee8d2e9fff5de56da79d40c4bc5fc) to see how OpenCommit works. Emoji and long commit description text is configurable. | ||
|
||
## Setup | ||
## Setup OpenCommit as a Github Action 🔥 | ||
|
||
OpenCommit is now available as a GitHub Action which automatically improves all new commits messages when you push to remote! | ||
|
||
This is great if you want to make sure all of the commits in all of repository branches are meaningful and not lame like `fix1` or `done2`. | ||
|
||
Create a file `.github/workflows/opencommit.yml` with contents below: | ||
|
||
```yml | ||
name: 'OpenCommit Action' | ||
|
||
on: | ||
push: | ||
# this list of branches is often enough, | ||
# but you may still ignore other public branches | ||
branches-ignore: [main master dev development release] | ||
|
||
jobs: | ||
opencommit: | ||
timeout-minutes: 10 | ||
name: OpenCommit | ||
runs-on: ubuntu-latest | ||
permissions: write-all | ||
steps: | ||
- name: Setup Node.js Environment | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: '16' | ||
- uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
- uses: di-sukharev/[email protected] | ||
with: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
env: | ||
# set openAI api key in repo actions secrets, | ||
# for openAI keys go to: https://platform.openai.com/account/api-keys | ||
# for repo secret go to: <your_repo_url>/settings/secrets/actions | ||
OCO_OPENAI_API_KEY: ${{ secrets.OCO_OPENAI_API_KEY }} | ||
|
||
# customization | ||
OCO_OPENAI_MAX_TOKENS: 500 | ||
OCO_OPENAI_BASE_PATH: '' | ||
OCO_DESCRIPTION: false | ||
OCO_EMOJI: false | ||
OCO_MODEL: gpt-3.5-turbo | ||
OCO_LANGUAGE: en | ||
``` | ||
That is it. Now when you push to any branch in your repo — all NEW commits are being improved by never-tired-AI. | ||
Make sure you exclude public collaboration branches (`main`, `dev`, `etc`) in `branches-ignore`, so OpenCommit does not rebase commits there when improving the messages. | ||
|
||
Interactive rebase (`rebase -i`) changes commit SHA, so commit history in remote becomes different with your local branch history. It's ok when you work on the branch alone, but may be inconvenient for other collaborators. | ||
|
||
## Setup OpenCommit as a CLI | ||
|
||
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. | ||
|
||
1. Install OpenCommit globally to use in any repository: | ||
|
||
|
@@ -31,7 +89,7 @@ All the commits in this repo are done with OpenCommit — look into [the commits | |
3. Set the key to OpenCommit config: | ||
|
||
```sh | ||
opencommit config set OPENAI_API_KEY=<your_api_key> | ||
opencommit config set OCO_OPENAI_API_KEY=<your_api_key> | ||
``` | ||
|
||
Your api key is stored locally in `~/.opencommit` config file. | ||
|
@@ -45,88 +103,108 @@ git add <files...> | |
opencommit | ||
``` | ||
|
||
You can also use the `oc` shortcut: | ||
You can also use the `oco` shortcut: | ||
|
||
```sh | ||
git add <files...> | ||
oc | ||
``` | ||
|
||
## Features | ||
## Configuration | ||
|
||
### Switch to Azure OpenAI | ||
|
||
By default OpenCommit uses [OpenAI](https://openai.com). | ||
### Local per repo configuration | ||
|
||
You could switch to [Azure OpenAI Service](https://learn.microsoft.com/azure/cognitive-services/openai/)🚀 | ||
Create an `.env` file and add OpenCommit config variables there like this: | ||
|
||
```sh | ||
opencommit config set OPENAI_API_TYPE=azure | ||
```env | ||
OCO_OPENAI_API_KEY=<your openAI API token> | ||
OCO_OPENAI_MAX_TOKENS=<max response tokens from openAI API> | ||
OCO_OPENAI_BASE_PATH=<may be used to set proxy path to openAI api> | ||
OCO_DESCRIPTION=<postface a message with ~3 sentences description> | ||
OCO_EMOJI=<add GitMoji> | ||
OCO_MODEL=<either gpt-3.5-turbo or gpt-4> | ||
OCO_LANGUAGE=<locale, scroll to the bottom to see options> | ||
``` | ||
|
||
Of course need to set 'OPENAI_API_KEY'. And also need to set the | ||
'OPENAI_BASE_PATH' for the endpoint and set the deployment name to | ||
'model'. | ||
### Global config for all repos | ||
|
||
### Switch to GPT-4 | ||
|
||
By default OpenCommit uses GPT-3.5-turbo (ChatGPT). | ||
Local config still has more priority as Global config, but you may set `OCO_MODEL` and `OCO_LOCALE` globally and set local configs for `OCO_EMOJI` and `OCO_DESCRIPTION` per repo which is more convenient. | ||
|
||
You may switch to GPT-4 which performs better, but costs ~x15 times more 🤠 | ||
Simply run any of the variable above like this: | ||
|
||
```sh | ||
oc config set model=gpt-4 | ||
oco config set OCO_OPENAI_API_KEY=gpt-4 | ||
``` | ||
|
||
Make sure you do lowercase `gpt-4`. | ||
|
||
### Preface commits with emoji 🤠 | ||
Configure [GitMoji](https://gitmoji.dev/) to preface a message. | ||
|
||
[GitMoji](https://gitmoji.dev/) convention is used. | ||
```sh | ||
oco config set OCO_EMOJI=true | ||
``` | ||
|
||
To add emoji: | ||
To remove preface emoji: | ||
|
||
```sh | ||
oc config set emoji=true | ||
oco config set OCO_EMOJI=false | ||
``` | ||
|
||
To remove emoji: | ||
### Switch to Azure OpenAI | ||
|
||
By default OpenCommit uses [OpenAI](https://openai.com). | ||
|
||
You could switch to [Azure OpenAI Service](https://learn.microsoft.com/azure/cognitive-services/openai/)🚀 | ||
|
||
```sh | ||
oc config set emoji=false | ||
opencommit config set OPENAI_API_TYPE=azure | ||
``` | ||
|
||
### Postface commits with descriptions of changes | ||
Of course need to set 'OPENAI_API_KEY'. And also need to set the | ||
'OPENAI_BASE_PATH' for the endpoint and set the deployment name to | ||
'model'. | ||
|
||
### Switch to Azure OpenAI | ||
|
||
By default OpenCommit uses [OpenAI](https://openai.com). | ||
|
||
To add descriptions: | ||
You could switch to [Azure OpenAI Service](https://learn.microsoft.com/azure/cognitive-services/openai/)🚀 | ||
|
||
```sh | ||
oc config set description=true | ||
opencommit config set OPENAI_API_TYPE=azure | ||
``` | ||
|
||
To remove description: | ||
Of course need to set 'OPENAI_API_KEY'. And also need to set the | ||
'OPENAI_BASE_PATH' for the endpoint and set the deployment name to | ||
'model'. | ||
|
||
### Switch to GPT-4 | ||
|
||
By default OpenCommit uses GPT-3.5-turbo (ChatGPT). | ||
|
||
You may switch to GPT-4 which performs better, but costs ~x15 times more 🤠 | ||
|
||
```sh | ||
oc config set description=false | ||
oco config set OCO_MODEL=gpt-4 | ||
``` | ||
|
||
### Internationalization support | ||
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. | ||
|
||
## Locale configuration | ||
|
||
To specify the language used to generate commit messages: | ||
To globally specify the language used to generate commit messages: | ||
|
||
```sh | ||
# de, German ,Deutsch | ||
oc config set language=de | ||
oc config set language=German | ||
oc config set language=Deutsch | ||
oco config set OCO_LANGUAGE=de | ||
oco config set OCO_LANGUAGE=German | ||
oco config set OCO_LANGUAGE=Deutsch | ||
# fr, French, française | ||
oc config set language=fr | ||
oc config set language=French | ||
oc config set language=française | ||
oco config set OCO_LANGUAGE=fr | ||
oco config set OCO_LANGUAGE=French | ||
oco config set OCO_LANGUAGE=française | ||
``` | ||
|
||
The default language set is **English** | ||
The default language set is **English** | ||
All available languages are currently listed in the [i18n](https://github.com/di-sukharev/opencommit/tree/master/src/i18n) folder | ||
|
||
### Push to git | ||
|
@@ -138,10 +216,10 @@ oc config set gitpush=false | |
|
||
### Git flags | ||
|
||
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`. | ||
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`. | ||
|
||
```sh | ||
oc --no-verify | ||
oco --no-verify | ||
``` | ||
|
||
is translated to : | ||
|
@@ -163,20 +241,20 @@ This is useful for preventing opencommit from uploading artifacts and large file | |
|
||
By default, opencommit ignores files matching: `*-lock.*` and `*.lock` | ||
|
||
## Git hook | ||
## Git hook (KILLER FEATURE) | ||
|
||
You can set OpenCommit as Git [`prepare-commit-msg`](https://git-scm.com/docs/githooks#_prepare_commit_msg) hook. Hook integrates with you IDE Source Control and allows you edit the message before commit. | ||
|
||
To set the hook: | ||
|
||
```sh | ||
oc hook set | ||
oco hook set | ||
``` | ||
|
||
To unset the hook: | ||
|
||
```sh | ||
oc hook unset | ||
oco hook unset | ||
``` | ||
|
||
To use the hook: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
name: 'OpenCommit — improve commits with AI 🧙' | ||
description: 'Replaces lame commit messages with meaningful AI-generated messages when you push to remote' | ||
author: 'https://github.com/di-sukharev' | ||
repo: 'https://github.com/di-sukharev/opencommit/tree/github-action' | ||
branding: | ||
icon: 'git-commit' | ||
color: 'green' | ||
keywords: | ||
[ | ||
'git', | ||
'chatgpt', | ||
'gpt', | ||
'ai', | ||
'openai', | ||
'opencommit', | ||
'aicommit', | ||
'aicommits', | ||
'gptcommit', | ||
'commit' | ||
] | ||
|
||
inputs: | ||
GITHUB_TOKEN: | ||
description: 'GitHub token' | ||
required: true | ||
|
||
runs: | ||
using: 'node16' | ||
main: 'out/github-action.cjs' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,24 @@ | ||
import { build } from 'esbuild' | ||
import fs from 'fs' | ||
import { build } from 'esbuild'; | ||
import fs from 'fs'; | ||
|
||
await build({ | ||
entryPoints: ['./src/cli.ts'], | ||
bundle: true, | ||
platform: 'node', | ||
format: 'cjs', | ||
outfile: './out/cli.cjs', | ||
entryPoints: ['./src/cli.ts'], | ||
bundle: true, | ||
platform: 'node', | ||
format: 'cjs', | ||
outfile: './out/cli.cjs' | ||
}); | ||
|
||
const wasmFile = fs.readFileSync('./node_modules/@dqbd/tiktoken/lite/tiktoken_bg.wasm') | ||
await build({ | ||
entryPoints: ['./src/github-action.ts'], | ||
bundle: true, | ||
platform: 'node', | ||
format: 'cjs', | ||
outfile: './out/github-action.cjs' | ||
}); | ||
|
||
const wasmFile = fs.readFileSync( | ||
'./node_modules/@dqbd/tiktoken/lite/tiktoken_bg.wasm' | ||
); | ||
|
||
fs.writeFileSync('./out/tiktoken_bg.wasm', wasmFile) | ||
fs.writeFileSync('./out/tiktoken_bg.wasm', wasmFile); |
Oops, something went wrong.