Skip to content

Commit 897eb73

Browse files
committed
feat(README.md): add GitHub Hackathon winner badge to project description
docs(README.md): restructure README, move CLI setup instructions to top for better visibility feat(cli.cjs): extend file exclusion list in 'getDiff' to include image files for better performance refactor(config.ts): add more model options in configValidators for flexibility refactor(config.ts): set default model to 'gpt-3.5-turbo-16k' for better performance refactor(git.ts): simplify 'getCoreHooksPath' function for readability feat(git.ts): extend file exclusion list in 'getDiff' to include image files for better performance
1 parent e7ce40a commit 897eb73

5 files changed

Lines changed: 68 additions & 47 deletions

File tree

.github/github-mark-white.png

4.72 KB
Loading

README.md

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
<img src=".github/logo-grad.svg" alt="OpenCommit logo"/>
44
<h1 align="center">OpenCommit</h1>
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>
6-
</h4>
76
</div>
87
<h2>Auto-generate meaningful commits in 1 second</h2>
98
<p>Killing lame commits with AI 🤯🔫</p>
109
<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>
11+
</h4>
1112
</div>
1213

1314
---
@@ -18,6 +19,26 @@
1819

1920
All the commits in this repo are authored by OpenCommit — look at [the commits](https://github.com/di-sukharev/opencommit/commit/eae7618d575ee8d2e9fff5de56da79d40c4bc5fc) to see how OpenCommit works. Emojis and long commit descriptions are configurable.
2021

22+
## Setup OpenCommit as a CLI tool
23+
24+
You can use OpenCommit by simply running it via the CLI like this `oco`. 2 seconds and your staged changes are committed with a meaningful message.
25+
26+
1. Install OpenCommit globally to use in any repository:
27+
28+
```sh
29+
npm install -g opencommit
30+
```
31+
32+
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+
34+
3. Set the key to OpenCommit config:
35+
36+
```sh
37+
opencommit config set OCO_OPENAI_API_KEY=<your_api_key>
38+
```
39+
40+
Your API key is stored locally in the `~/.opencommit` config file.
41+
2142
## Setup OpenCommit as a GitHub Action 🔥
2243

2344
OpenCommit is now available as a GitHub Action which automatically improves all new commits messages when you push to remote!
@@ -74,26 +95,6 @@ Make sure you exclude public collaboration branches (`main`, `dev`, `etc`) in `b
7495

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

77-
## Setup OpenCommit as a CLI tool
78-
79-
You can use OpenCommit by simply running it via the CLI like this `oco`. 2 seconds and your staged changes are committed with a meaningful message.
80-
81-
1. Install OpenCommit globally to use in any repository:
82-
83-
```sh
84-
npm install -g opencommit
85-
```
86-
87-
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.
88-
89-
3. Set the key to OpenCommit config:
90-
91-
```sh
92-
opencommit config set OCO_OPENAI_API_KEY=<your_api_key>
93-
```
94-
95-
Your API key is stored locally in the `~/.opencommit` config file.
96-
9798
## Usage
9899

99100
You can call OpenCommit directly to generate a commit message for your staged changes:
@@ -149,16 +150,22 @@ To remove preface emojis:
149150
oco config set OCO_EMOJI=false
150151
```
151152

152-
### Switch to GPT-4
153+
### Switch to GPT-4 or other models
153154

154-
By default, OpenCommit uses GPT-3.5-turbo (ChatGPT).
155+
By default, OpenCommit uses `gpt-3.5-turbo-16k` model.
155156

156157
You may switch to GPT-4 which performs better, but costs ~x15 times more 🤠
157158

158159
```sh
159160
oco config set OCO_MODEL=gpt-4
160161
```
161162

163+
or for as a cheaper option:
164+
165+
```sh
166+
oco config set OCO_MODEL=gpt-3.5-turbo
167+
```
168+
162169
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.
163170

164171
## Locale configuration

out/cli.cjs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18717,10 +18717,7 @@ var getOpenCommitIgnore = () => {
1871718717
return ig;
1871818718
};
1871918719
var getCoreHooksPath = async () => {
18720-
const { stdout } = await execa("git", [
18721-
"config",
18722-
"core.hooksPath"
18723-
]);
18720+
const { stdout } = await execa("git", ["config", "core.hooksPath"]);
1872418721
return stdout;
1872518722
};
1872618723
var getStagedFiles = async () => {
@@ -18764,11 +18761,11 @@ var gitAdd = async ({ files }) => {
1876418761
};
1876518762
var getDiff = async ({ files }) => {
1876618763
const lockFiles = files.filter(
18767-
(file) => file.includes(".lock") || file.includes("-lock.")
18764+
(file) => file.includes(".lock") || file.includes("-lock.") || file.includes(".svg") || file.includes(".png") || file.includes(".jpg") || file.includes(".jpeg") || file.includes(".webp") || file.includes(".gif")
1876818765
);
1876918766
if (lockFiles.length) {
1877018767
ce(
18771-
`Some files are '.lock' files which are excluded by default from 'git diff'. No commit messages are generated for this files:
18768+
`Some files are excluded by default from 'git diff'. No commit messages are generated for this files:
1877218769
${lockFiles.join(
1877318770
"\n"
1877418771
)}`

src/commands/config.ts

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
import { intro, outro } from '@clack/prompts';
2+
import chalk from 'chalk';
13
import { command } from 'cleye';
2-
import { join as pathJoin } from 'path';
4+
import { existsSync, readFileSync, writeFileSync } from 'fs';
35
import { parse as iniParse, stringify as iniStringify } from 'ini';
4-
import { existsSync, writeFileSync, readFileSync } from 'fs';
56
import { homedir } from 'os';
6-
import { intro, outro } from '@clack/prompts';
7-
import chalk from 'chalk';
7+
import { join as pathJoin } from 'path';
88
import { COMMANDS } from '../CommandsEnum';
99
import { getI18nLocal } from '../i18n';
1010

@@ -20,7 +20,7 @@ export enum CONFIG_KEYS {
2020
OCO_EMOJI = 'OCO_EMOJI',
2121
OCO_MODEL = 'OCO_MODEL',
2222
OCO_LANGUAGE = 'OCO_LANGUAGE',
23-
OCO_MESSAGE_TEMPLATE_PLACEHOLDER = 'OCO_MESSAGE_TEMPLATE_PLACEHOLDER',
23+
OCO_MESSAGE_TEMPLATE_PLACEHOLDER = 'OCO_MESSAGE_TEMPLATE_PLACEHOLDER'
2424
}
2525

2626
export const DEFAULT_MODEL_TOKEN_LIMIT = 4096;
@@ -121,8 +121,13 @@ export const configValidators = {
121121
[CONFIG_KEYS.OCO_MODEL](value: any) {
122122
validateConfig(
123123
CONFIG_KEYS.OCO_MODEL,
124-
['gpt-3.5-turbo', 'gpt-4','gpt-3.5-turbo-16k'].includes(value),
125-
`${value} is not supported yet, use 'gpt-4' or 'gpt-3.5-turbo' (default)`
124+
[
125+
'gpt-3.5-turbo',
126+
'gpt-4',
127+
'gpt-3.5-turbo-16k',
128+
'gpt-3.5-turbo-0613'
129+
].includes(value),
130+
`${value} is not supported yet, use 'gpt-4', 'gpt-3.5-turbo-0613', 'gpt-3.5-turbo-0613' or 'gpt-3.5-turbo' (default)`
126131
);
127132
return value;
128133
},
@@ -145,13 +150,16 @@ const configPath = pathJoin(homedir(), '.opencommit');
145150
export const getConfig = (): ConfigType | null => {
146151
const configFromEnv = {
147152
OCO_OPENAI_API_KEY: process.env.OCO_OPENAI_API_KEY,
148-
OCO_OPENAI_MAX_TOKENS: process.env.OCO_OPENAI_MAX_TOKENS ? Number(process.env.OCO_OPENAI_MAX_TOKENS) : undefined,
153+
OCO_OPENAI_MAX_TOKENS: process.env.OCO_OPENAI_MAX_TOKENS
154+
? Number(process.env.OCO_OPENAI_MAX_TOKENS)
155+
: undefined,
149156
OCO_OPENAI_BASE_PATH: process.env.OCO_OPENAI_BASE_PATH,
150157
OCO_DESCRIPTION: process.env.OCO_DESCRIPTION === 'true' ? true : false,
151158
OCO_EMOJI: process.env.OCO_EMOJI === 'true' ? true : false,
152-
OCO_MODEL: process.env.OCO_MODEL || 'gpt-3.5-turbo',
159+
OCO_MODEL: process.env.OCO_MODEL || 'gpt-3.5-turbo-16k',
153160
OCO_LANGUAGE: process.env.OCO_LANGUAGE || 'en',
154-
OCO_MESSAGE_TEMPLATE_PLACEHOLDER: process.env.OCO_MESSAGE_TEMPLATE_PLACEHOLDER || '$msg'
161+
OCO_MESSAGE_TEMPLATE_PLACEHOLDER:
162+
process.env.OCO_MESSAGE_TEMPLATE_PLACEHOLDER || '$msg'
155163
};
156164

157165
const configExists = existsSync(configPath);
@@ -161,7 +169,10 @@ export const getConfig = (): ConfigType | null => {
161169
const config = iniParse(configFile);
162170

163171
for (const configKey of Object.keys(config)) {
164-
if (!config[configKey] || ['null', 'undefined'].includes(config[configKey])) {
172+
if (
173+
!config[configKey] ||
174+
['null', 'undefined'].includes(config[configKey])
175+
) {
165176
config[configKey] = undefined;
166177
continue;
167178
}

src/utils/git.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,11 @@ export const getOpenCommitIgnore = (): Ignore => {
2525
return ig;
2626
};
2727

28-
export const getCoreHooksPath = async(): Promise<string> => {
29-
const { stdout } = await execa('git', [
30-
'config',
31-
'core.hooksPath']);
28+
export const getCoreHooksPath = async (): Promise<string> => {
29+
const { stdout } = await execa('git', ['config', 'core.hooksPath']);
3230

3331
return stdout;
34-
}
32+
};
3533

3634
export const getStagedFiles = async (): Promise<string[]> => {
3735
const { stdout: gitDir } = await execa('git', [
@@ -83,12 +81,20 @@ export const gitAdd = async ({ files }: { files: string[] }) => {
8381

8482
export const getDiff = async ({ files }: { files: string[] }) => {
8583
const lockFiles = files.filter(
86-
(file) => file.includes('.lock') || file.includes('-lock.')
84+
(file) =>
85+
file.includes('.lock') ||
86+
file.includes('-lock.') ||
87+
file.includes('.svg') ||
88+
file.includes('.png') ||
89+
file.includes('.jpg') ||
90+
file.includes('.jpeg') ||
91+
file.includes('.webp') ||
92+
file.includes('.gif')
8793
);
8894

8995
if (lockFiles.length) {
9096
outro(
91-
`Some files are '.lock' files which are excluded by default from 'git diff'. No commit messages are generated for this files:\n${lockFiles.join(
97+
`Some files are excluded by default from 'git diff'. No commit messages are generated for this files:\n${lockFiles.join(
9298
'\n'
9399
)}`
94100
);

0 commit comments

Comments
 (0)