Skip to content

Commit 616c993

Browse files
committed
Marge remote-tracking branch 'di-sukharev/master'
Upgrade from upstream
1 parent cfe7209 commit 616c993

23 files changed

Lines changed: 30556 additions & 2577 deletions

.eslintrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
"rules": {
2222
"prettier/prettier": "error",
2323
"no-console": "error",
24-
"sort-imports": "off",
2524
"import/order": "off",
25+
"sort-imports": "off",
2626
"simple-import-sort/imports": "error",
2727
"simple-import-sort/exports": "error",
2828
"import/first": "error",

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
node_modules/
22
coverage/
3-
out/
43
temp/
54
build/
6-
dist/
75
application.log
86
.DS_Store
97
/*.env

.prettierignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/build
2-
/dist
2+
/dist
3+
/out

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) Dima Sukharev
3+
Copyright (c) Dima Sukharev, https://github.com/di-sukharev
44

55
Permission is hereby granted, free of charge, to any person obtaining a
66
copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

README.md

Lines changed: 124 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<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>
66
</h4>
77
</div>
8-
<h2>GPT CLI to auto-generate impressive commits in 1 second</h2>
8+
<h2>Auto-generate meaningful commits in 1 second</h2>
99
<p>Killing lame commits with AI 🤯🔫</p>
1010
<a href="https://www.npmjs.com/package/opencommit"><img src="https://img.shields.io/npm/v/opencommit" alt="Current version"></a>
1111
</div>
@@ -18,7 +18,65 @@
1818

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

21-
## Setup
21+
## Setup OpenCommit as a Github Action 🔥
22+
23+
OpenCommit is now available as a GitHub Action which automatically improves all new commits messages when you push to remote!
24+
25+
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`.
26+
27+
Create a file `.github/workflows/opencommit.yml` with contents below:
28+
29+
```yml
30+
name: 'OpenCommit Action'
31+
32+
on:
33+
push:
34+
# this list of branches is often enough,
35+
# but you may still ignore other public branches
36+
branches-ignore: [main master dev development release]
37+
38+
jobs:
39+
opencommit:
40+
timeout-minutes: 10
41+
name: OpenCommit
42+
runs-on: ubuntu-latest
43+
permissions: write-all
44+
steps:
45+
- name: Setup Node.js Environment
46+
uses: actions/setup-node@v2
47+
with:
48+
node-version: '16'
49+
- uses: actions/checkout@v3
50+
with:
51+
fetch-depth: 0
52+
- uses: di-sukharev/opencommit@github-action-v1.0.4
53+
with:
54+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
55+
56+
env:
57+
# set openAI api key in repo actions secrets,
58+
# for openAI keys go to: https://platform.openai.com/account/api-keys
59+
# for repo secret go to: <your_repo_url>/settings/secrets/actions
60+
OCO_OPENAI_API_KEY: ${{ secrets.OCO_OPENAI_API_KEY }}
61+
62+
# customization
63+
OCO_OPENAI_MAX_TOKENS: 500
64+
OCO_OPENAI_BASE_PATH: ''
65+
OCO_DESCRIPTION: false
66+
OCO_EMOJI: false
67+
OCO_MODEL: gpt-3.5-turbo
68+
OCO_LANGUAGE: en
69+
```
70+
71+
That is it. Now when you push to any branch in your repo — all NEW commits are being improved by never-tired-AI.
72+
73+
Make sure you exclude public collaboration branches (`main`, `dev`, `etc`) in `branches-ignore`, so OpenCommit does not rebase commits there when improving the messages.
74+
75+
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.
76+
77+
## Setup OpenCommit as a CLI
78+
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.
2280

2381
1. Install OpenCommit globally to use in any repository:
2482

@@ -31,7 +89,7 @@ All the commits in this repo are done with OpenCommit — look into [the commits
3189
3. Set the key to OpenCommit config:
3290

3391
```sh
34-
opencommit config set OPENAI_API_KEY=<your_api_key>
92+
opencommit config set OCO_OPENAI_API_KEY=<your_api_key>
3593
```
3694

3795
Your api key is stored locally in `~/.opencommit` config file.
@@ -45,88 +103,108 @@ git add <files...>
45103
opencommit
46104
```
47105

48-
You can also use the `oc` shortcut:
106+
You can also use the `oco` shortcut:
49107

50108
```sh
51109
git add <files...>
52110
oc
53111
```
54112

55-
## Features
113+
## Configuration
56114

57-
### Switch to Azure OpenAI
58-
59-
By default OpenCommit uses [OpenAI](https://openai.com).
115+
### Local per repo configuration
60116

61-
You could switch to [Azure OpenAI Service](https://learn.microsoft.com/azure/cognitive-services/openai/)🚀
117+
Create an `.env` file and add OpenCommit config variables there like this:
62118

63-
```sh
64-
opencommit config set OPENAI_API_TYPE=azure
119+
```env
120+
OCO_OPENAI_API_KEY=<your openAI API token>
121+
OCO_OPENAI_MAX_TOKENS=<max response tokens from openAI API>
122+
OCO_OPENAI_BASE_PATH=<may be used to set proxy path to openAI api>
123+
OCO_DESCRIPTION=<postface a message with ~3 sentences description>
124+
OCO_EMOJI=<add GitMoji>
125+
OCO_MODEL=<either gpt-3.5-turbo or gpt-4>
126+
OCO_LANGUAGE=<locale, scroll to the bottom to see options>
65127
```
66128

67-
Of course need to set 'OPENAI_API_KEY'. And also need to set the
68-
'OPENAI_BASE_PATH' for the endpoint and set the deployment name to
69-
'model'.
129+
### Global config for all repos
70130

71-
### Switch to GPT-4
72-
73-
By default OpenCommit uses GPT-3.5-turbo (ChatGPT).
131+
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.
74132

75-
You may switch to GPT-4 which performs better, but costs ~x15 times more 🤠
133+
Simply run any of the variable above like this:
76134

77135
```sh
78-
oc config set model=gpt-4
136+
oco config set OCO_OPENAI_API_KEY=gpt-4
79137
```
80138

81-
Make sure you do lowercase `gpt-4`.
82-
83-
### Preface commits with emoji 🤠
139+
Configure [GitMoji](https://gitmoji.dev/) to preface a message.
84140

85-
[GitMoji](https://gitmoji.dev/) convention is used.
141+
```sh
142+
oco config set OCO_EMOJI=true
143+
```
86144

87-
To add emoji:
145+
To remove preface emoji:
88146

89147
```sh
90-
oc config set emoji=true
148+
oco config set OCO_EMOJI=false
91149
```
92150

93-
To remove emoji:
151+
### Switch to Azure OpenAI
152+
153+
By default OpenCommit uses [OpenAI](https://openai.com).
154+
155+
You could switch to [Azure OpenAI Service](https://learn.microsoft.com/azure/cognitive-services/openai/)🚀
94156

95157
```sh
96-
oc config set emoji=false
158+
opencommit config set OPENAI_API_TYPE=azure
97159
```
98160

99-
### Postface commits with descriptions of changes
161+
Of course need to set 'OPENAI_API_KEY'. And also need to set the
162+
'OPENAI_BASE_PATH' for the endpoint and set the deployment name to
163+
'model'.
164+
165+
### Switch to Azure OpenAI
166+
167+
By default OpenCommit uses [OpenAI](https://openai.com).
100168

101-
To add descriptions:
169+
You could switch to [Azure OpenAI Service](https://learn.microsoft.com/azure/cognitive-services/openai/)🚀
102170

103171
```sh
104-
oc config set description=true
172+
opencommit config set OPENAI_API_TYPE=azure
105173
```
106174

107-
To remove description:
175+
Of course need to set 'OPENAI_API_KEY'. And also need to set the
176+
'OPENAI_BASE_PATH' for the endpoint and set the deployment name to
177+
'model'.
178+
179+
### Switch to GPT-4
180+
181+
By default OpenCommit uses GPT-3.5-turbo (ChatGPT).
182+
183+
You may switch to GPT-4 which performs better, but costs ~x15 times more 🤠
108184

109185
```sh
110-
oc config set description=false
186+
oco config set OCO_MODEL=gpt-4
111187
```
112188

113-
### Internationalization support
189+
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.
190+
191+
## Locale configuration
114192

115-
To specify the language used to generate commit messages:
193+
To globally specify the language used to generate commit messages:
116194

117195
```sh
118196
# de, German ,Deutsch
119-
oc config set language=de
120-
oc config set language=German
121-
oc config set language=Deutsch
197+
oco config set OCO_LANGUAGE=de
198+
oco config set OCO_LANGUAGE=German
199+
oco config set OCO_LANGUAGE=Deutsch
122200
123201
# fr, French, française
124-
oc config set language=fr
125-
oc config set language=French
126-
oc config set language=française
202+
oco config set OCO_LANGUAGE=fr
203+
oco config set OCO_LANGUAGE=French
204+
oco config set OCO_LANGUAGE=française
127205
```
128206

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

132210
### Push to git
@@ -138,10 +216,10 @@ oc config set gitpush=false
138216

139217
### Git flags
140218

141-
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`.
219+
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`.
142220

143221
```sh
144-
oc --no-verify
222+
oco --no-verify
145223
```
146224

147225
is translated to :
@@ -163,20 +241,20 @@ This is useful for preventing opencommit from uploading artifacts and large file
163241

164242
By default, opencommit ignores files matching: `*-lock.*` and `*.lock`
165243

166-
## Git hook
244+
## Git hook (KILLER FEATURE)
167245

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

170248
To set the hook:
171249

172250
```sh
173-
oc hook set
251+
oco hook set
174252
```
175253

176254
To unset the hook:
177255

178256
```sh
179-
oc hook unset
257+
oco hook unset
180258
```
181259

182260
To use the hook:

action.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: 'OpenCommit — improve commits with AI 🧙'
2+
description: 'Replaces lame commit messages with meaningful AI-generated messages when you push to remote'
3+
author: 'https://github.com/di-sukharev'
4+
repo: 'https://github.com/di-sukharev/opencommit/tree/github-action'
5+
branding:
6+
icon: 'git-commit'
7+
color: 'green'
8+
keywords:
9+
[
10+
'git',
11+
'chatgpt',
12+
'gpt',
13+
'ai',
14+
'openai',
15+
'opencommit',
16+
'aicommit',
17+
'aicommits',
18+
'gptcommit',
19+
'commit'
20+
]
21+
22+
inputs:
23+
GITHUB_TOKEN:
24+
description: 'GitHub token'
25+
required: true
26+
27+
runs:
28+
using: 'node16'
29+
main: 'out/github-action.cjs'

esbuild.config.js

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
1-
import { build } from 'esbuild'
2-
import fs from 'fs'
1+
import { build } from 'esbuild';
2+
import fs from 'fs';
33

44
await build({
5-
entryPoints: ['./src/cli.ts'],
6-
bundle: true,
7-
platform: 'node',
8-
format: 'cjs',
9-
outfile: './out/cli.cjs',
5+
entryPoints: ['./src/cli.ts'],
6+
bundle: true,
7+
platform: 'node',
8+
format: 'cjs',
9+
outfile: './out/cli.cjs'
1010
});
1111

12-
const wasmFile = fs.readFileSync('./node_modules/@dqbd/tiktoken/lite/tiktoken_bg.wasm')
12+
await build({
13+
entryPoints: ['./src/github-action.ts'],
14+
bundle: true,
15+
platform: 'node',
16+
format: 'cjs',
17+
outfile: './out/github-action.cjs'
18+
});
19+
20+
const wasmFile = fs.readFileSync(
21+
'./node_modules/@dqbd/tiktoken/lite/tiktoken_bg.wasm'
22+
);
1323

14-
fs.writeFileSync('./out/tiktoken_bg.wasm', wasmFile)
24+
fs.writeFileSync('./out/tiktoken_bg.wasm', wasmFile);

0 commit comments

Comments
 (0)