Skip to content

Commit

Permalink
feat(README.md): add GitHub Hackathon winner badge to project descrip…
Browse files Browse the repository at this point in the history
…tion

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
  • Loading branch information
di-sukharev committed Jul 5, 2023
1 parent e7ce40a commit 897eb73
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 47 deletions.
Binary file added .github/github-mark-white.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
53 changes: 30 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
<img src=".github/logo-grad.svg" alt="OpenCommit logo"/>
<h1 align="center">OpenCommit</h1>
<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>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>
<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>
</h4>
</div>

---
Expand All @@ -18,6 +19,26 @@

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.

## Setup OpenCommit as a CLI tool

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.

1. Install OpenCommit globally to use in any repository:

```sh
npm install -g opencommit
```

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.

3. Set the key to OpenCommit config:

```sh
opencommit config set OCO_OPENAI_API_KEY=<your_api_key>
```

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

## 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!
Expand Down Expand Up @@ -74,26 +95,6 @@ Make sure you exclude public collaboration branches (`main`, `dev`, `etc`) in `b

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.

## Setup OpenCommit as a CLI tool

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.

1. Install OpenCommit globally to use in any repository:

```sh
npm install -g opencommit
```

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.

3. Set the key to OpenCommit config:

```sh
opencommit config set OCO_OPENAI_API_KEY=<your_api_key>
```

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

## Usage

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

### Switch to GPT-4
### Switch to GPT-4 or other models

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

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

```sh
oco config set OCO_MODEL=gpt-4
```

or for as a cheaper option:

```sh
oco config set OCO_MODEL=gpt-3.5-turbo
```

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.

## Locale configuration
Expand Down
9 changes: 3 additions & 6 deletions out/cli.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -18717,10 +18717,7 @@ var getOpenCommitIgnore = () => {
return ig;
};
var getCoreHooksPath = async () => {
const { stdout } = await execa("git", [
"config",
"core.hooksPath"
]);
const { stdout } = await execa("git", ["config", "core.hooksPath"]);
return stdout;
};
var getStagedFiles = async () => {
Expand Down Expand Up @@ -18764,11 +18761,11 @@ var gitAdd = async ({ files }) => {
};
var getDiff = async ({ files }) => {
const lockFiles = files.filter(
(file) => file.includes(".lock") || file.includes("-lock.")
(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")
);
if (lockFiles.length) {
ce(
`Some files are '.lock' files which are excluded by default from 'git diff'. No commit messages are generated for this files:
`Some files are excluded by default from 'git diff'. No commit messages are generated for this files:
${lockFiles.join(
"\n"
)}`
Expand Down
33 changes: 22 additions & 11 deletions src/commands/config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { intro, outro } from '@clack/prompts';
import chalk from 'chalk';
import { command } from 'cleye';
import { join as pathJoin } from 'path';
import { existsSync, readFileSync, writeFileSync } from 'fs';
import { parse as iniParse, stringify as iniStringify } from 'ini';
import { existsSync, writeFileSync, readFileSync } from 'fs';
import { homedir } from 'os';
import { intro, outro } from '@clack/prompts';
import chalk from 'chalk';
import { join as pathJoin } from 'path';
import { COMMANDS } from '../CommandsEnum';
import { getI18nLocal } from '../i18n';

Expand All @@ -20,7 +20,7 @@ export enum CONFIG_KEYS {
OCO_EMOJI = 'OCO_EMOJI',
OCO_MODEL = 'OCO_MODEL',
OCO_LANGUAGE = 'OCO_LANGUAGE',
OCO_MESSAGE_TEMPLATE_PLACEHOLDER = 'OCO_MESSAGE_TEMPLATE_PLACEHOLDER',
OCO_MESSAGE_TEMPLATE_PLACEHOLDER = 'OCO_MESSAGE_TEMPLATE_PLACEHOLDER'
}

export const DEFAULT_MODEL_TOKEN_LIMIT = 4096;
Expand Down Expand Up @@ -121,8 +121,13 @@ export const configValidators = {
[CONFIG_KEYS.OCO_MODEL](value: any) {
validateConfig(
CONFIG_KEYS.OCO_MODEL,
['gpt-3.5-turbo', 'gpt-4','gpt-3.5-turbo-16k'].includes(value),
`${value} is not supported yet, use 'gpt-4' or 'gpt-3.5-turbo' (default)`
[
'gpt-3.5-turbo',
'gpt-4',
'gpt-3.5-turbo-16k',
'gpt-3.5-turbo-0613'
].includes(value),
`${value} is not supported yet, use 'gpt-4', 'gpt-3.5-turbo-0613', 'gpt-3.5-turbo-0613' or 'gpt-3.5-turbo' (default)`
);
return value;
},
Expand All @@ -145,13 +150,16 @@ const configPath = pathJoin(homedir(), '.opencommit');
export const getConfig = (): ConfigType | null => {
const configFromEnv = {
OCO_OPENAI_API_KEY: process.env.OCO_OPENAI_API_KEY,
OCO_OPENAI_MAX_TOKENS: process.env.OCO_OPENAI_MAX_TOKENS ? Number(process.env.OCO_OPENAI_MAX_TOKENS) : undefined,
OCO_OPENAI_MAX_TOKENS: process.env.OCO_OPENAI_MAX_TOKENS
? Number(process.env.OCO_OPENAI_MAX_TOKENS)
: undefined,
OCO_OPENAI_BASE_PATH: process.env.OCO_OPENAI_BASE_PATH,
OCO_DESCRIPTION: process.env.OCO_DESCRIPTION === 'true' ? true : false,
OCO_EMOJI: process.env.OCO_EMOJI === 'true' ? true : false,
OCO_MODEL: process.env.OCO_MODEL || 'gpt-3.5-turbo',
OCO_MODEL: process.env.OCO_MODEL || 'gpt-3.5-turbo-16k',
OCO_LANGUAGE: process.env.OCO_LANGUAGE || 'en',
OCO_MESSAGE_TEMPLATE_PLACEHOLDER: process.env.OCO_MESSAGE_TEMPLATE_PLACEHOLDER || '$msg'
OCO_MESSAGE_TEMPLATE_PLACEHOLDER:
process.env.OCO_MESSAGE_TEMPLATE_PLACEHOLDER || '$msg'
};

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

for (const configKey of Object.keys(config)) {
if (!config[configKey] || ['null', 'undefined'].includes(config[configKey])) {
if (
!config[configKey] ||
['null', 'undefined'].includes(config[configKey])
) {
config[configKey] = undefined;
continue;
}
Expand Down
20 changes: 13 additions & 7 deletions src/utils/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,11 @@ export const getOpenCommitIgnore = (): Ignore => {
return ig;
};

export const getCoreHooksPath = async(): Promise<string> => {
const { stdout } = await execa('git', [
'config',
'core.hooksPath']);
export const getCoreHooksPath = async (): Promise<string> => {
const { stdout } = await execa('git', ['config', 'core.hooksPath']);

return stdout;
}
};

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

export const getDiff = async ({ files }: { files: string[] }) => {
const lockFiles = files.filter(
(file) => file.includes('.lock') || file.includes('-lock.')
(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')
);

if (lockFiles.length) {
outro(
`Some files are '.lock' files which are excluded by default from 'git diff'. No commit messages are generated for this files:\n${lockFiles.join(
`Some files are excluded by default from 'git diff'. No commit messages are generated for this files:\n${lockFiles.join(
'\n'
)}`
);
Expand Down

0 comments on commit 897eb73

Please sign in to comment.