Skip to content

Commit 6afa493

Browse files
authored
GitHub action (#173) (#174)
* add option to run OpenCommit as a Github Action
1 parent 5400682 commit 6afa493

17 files changed

+50409
-202
lines changed

.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

README.md

Lines changed: 98 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,70 @@
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+
### Automatic 1 click setup
28+
29+
You can simply [setup the action automatically via the GitHub Marketplace](TODO).
30+
31+
### Manual 3 clicks setup
32+
33+
Create a file `.github/workflows/opencommit.yml` with contents below:
34+
35+
```yml
36+
name: 'OpenCommit'
37+
38+
on:
39+
push:
40+
# this list of branches is often enough,
41+
# but you may still ignore other public branches
42+
branches-ignore: [main master dev development release]
43+
44+
jobs:
45+
opencommit:
46+
name: OpenCommit
47+
runs-on: ubuntu-latest
48+
permissions: write-all
49+
steps:
50+
- name: Setup Node.js Environment
51+
uses: actions/setup-node@v2
52+
with:
53+
node-version: '16'
54+
- uses: actions/checkout@v3
55+
with:
56+
fetch-depth: 0
57+
- uses: di-sukharev/opencommit@github-action
58+
with:
59+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
60+
61+
env:
62+
# set openAI api key in repo actions secrets,
63+
# for openAI keys go to: https://platform.openai.com/account/api-keys
64+
# for repo secret go to: <your_repo_url>/settings/secrets/actions
65+
OCO_OPENAI_API_KEY: ${{ secrets.OCO_OPENAI_API_KEY }}
66+
67+
# customization
68+
OCO_OPENAI_MAX_TOKENS: 500
69+
OCO_OPENAI_BASE_PATH: ''
70+
OCO_DESCRIPTION: false
71+
OCO_EMOJI: false
72+
OCO_MODEL: gpt-3.5-turbo
73+
OCO_LANGUAGE: en
74+
```
75+
76+
That is it. Now when you push to any branch in your repo — all NEW commits are being improved by never-tired-AI.
77+
78+
Make sure you exclude public collaboration branches (`main`, `dev`, `etc`) in `branches-ignore`, so OpenCommit does not rebase commits there when improving the messages.
79+
80+
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.
81+
82+
## Setup OpenCommit as a CLI
83+
84+
You can use OpenCommit by simply running it via CLI like this `oc`. 2 seconds and your staged changes are committed with a meaningful message.
2285

2386
1. Install OpenCommit globally to use in any repository:
2487

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

3396
```sh
34-
opencommit config set OPENAI_API_KEY=<your_api_key>
97+
opencommit config set OCO_OPENAI_API_KEY=<your_api_key>
3598
```
3699

37100
Your api key is stored locally in `~/.opencommit` config file.
@@ -52,82 +115,70 @@ git add <files...>
52115
oc
53116
```
54117

55-
## Features
118+
## Configuration
56119

57-
### Switch to GPT-4
120+
### Local per repo configuration
58121

59-
By default OpenCommit uses GPT-3.5-turbo (ChatGPT).
60-
61-
You may switch to GPT-4 which performs better, but costs ~x15 times more 🤠
122+
Create an `.env` file and add OpenCommit config variables there like this:
62123

63-
```sh
64-
oc config set model=gpt-4
124+
```env
125+
OCO_OPENAI_API_KEY=<your openAI API token>
126+
OCO_OPENAI_MAX_TOKENS=<max response tokens from openAI API>
127+
OCO_OPENAI_BASE_PATH=<may be used to set proxy path to openAI api>
128+
OCO_DESCRIPTION=<postface a message with ~3 sentences description>
129+
OCO_EMOJI=<add GitMoji>
130+
OCO_MODEL=<either gpt-3.5-turbo or gpt-4>
131+
OCO_LANGUAGE=<locale, scroll to the bottom to see options>
65132
```
66133

67-
Make sure you do lowercase `gpt-4`.
68-
69-
### Preface commits with emoji 🤠
134+
### Global config for all repos
70135

71-
[GitMoji](https://gitmoji.dev/) convention is used.
136+
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.
72137

73-
To add emoji:
138+
Simply run any of the variable above like this:
74139

75140
```sh
76-
oc config set emoji=true
141+
oc config set OCO_OPENAI_API_KEY=gpt-4
77142
```
78143

79-
To remove emoji:
144+
Configure [GitMoji](https://gitmoji.dev/) to preface a message.
80145

81146
```sh
82-
oc config set emoji=false
147+
oc config set OCO_EMOJI=true
83148
```
84149

85-
### Postface commits with descriptions of changes
86-
87-
To add descriptions:
150+
To remove preface emoji:
88151

89152
```sh
90-
oc config set description=true
153+
oc config set OCO_EMOJI=false
91154
```
92155

93-
To remove description:
94-
95-
```sh
96-
oc config set description=false
97-
```
98-
99-
### Configure openAI maxTokens param
156+
### Switch to GPT-4
100157

101-
Default value for `maxTokens` is 196, sometimes you can get 400 error if request+response exceeds `maxToken` parameter.
158+
By default OpenCommit uses GPT-3.5-turbo (ChatGPT).
102159

103-
so you can increase it:
160+
You may switch to GPT-4 which performs better, but costs ~x15 times more 🤠
104161

105162
```sh
106-
oc config set OPENAI_MAX_TOKENS=<number>
163+
oc config set OCO_MODEL=gpt-4
107164
```
108165

109-
### Configure BASE_PATH for openAI api
110-
111-
if you want to call GPT via proxy — you can change `BASE_PATH` parameter:
112-
113-
```sh
114-
oc config set OPENAI_BASE_PATH=<string>
115-
```
166+
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.
116167

117-
### Internationalization support
168+
## Locale configuration
118169

119-
To specify the language used to generate commit messages:
170+
To globally specify the language used to generate commit messages:
120171

121172
```sh
122173
# de, German ,Deutsch
123-
oc config set language=de
124-
oc config set language=German
125-
oc config set language=Deutsch
174+
oc config set OCO_LANGUAGE=de
175+
oc config set OCO_LANGUAGE=German
176+
oc config set OCO_LANGUAGE=Deutsch
126177
127178
# fr, French, française
128-
oc config set language=fr
129-
oc config set language=French
130-
oc config set language=française
179+
oc config set OCO_LANGUAGE=fr
180+
oc config set OCO_LANGUAGE=French
181+
oc config set OCO_LANGUAGE=française
131182
```
132183

133184
The default language set is **English**
@@ -160,7 +211,7 @@ This is useful for preventing opencommit from uploading artifacts and large file
160211

161212
By default, opencommit ignores files matching: `*-lock.*` and `*.lock`
162213

163-
## Git hook
214+
## Git hook (KILLER FEATURE)
164215

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

action.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: 'OpenCommit'
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+
keywords:
6+
[
7+
'git',
8+
'chatgpt',
9+
'gpt',
10+
'ai',
11+
'openai',
12+
'opencommit',
13+
'aicommit',
14+
'aicommits',
15+
'gptcommit',
16+
'commit'
17+
]
18+
19+
inputs:
20+
GITHUB_TOKEN:
21+
description: 'GitHub token'
22+
required: true
23+
24+
runs:
25+
using: 'node16'
26+
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)