Compare commits

..

1 Commits

Author SHA1 Message Date
Sukharev
7eb65b014e Update action.yml 2023-05-21 16:45:53 +08:00
16 changed files with 73 additions and 107 deletions

View File

@@ -21,8 +21,8 @@
"rules": {
"prettier/prettier": "error",
"no-console": "error",
"import/order": "off",
"sort-imports": "off",
"import/order": "off",
"simple-import-sort/imports": "error",
"simple-import-sort/exports": "error",
"import/first": "error",

View File

@@ -1,3 +1,2 @@
/build
/dist
/out
/dist

View File

@@ -1,4 +1,4 @@
{
"singleQuote": true,
"trailingComma": "none"
"trailingComma": "none",
"singleQuote": true
}

View File

@@ -1,6 +1,6 @@
MIT License
Copyright (c) Dima Sukharev, https://github.com/di-sukharev
Copyright (c) Dima Sukharev
Permission is hereby granted, free of charge, to any person obtaining a
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:

View File

@@ -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>Auto-generate meaningful commits in 1 second</h2>
<h2>GPT CLI to auto-generate impressive 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,16 +18,22 @@
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 OpenCommit as a Github Action 🔥
## 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`.
### Automatic 1 click setup
You can simply [setup the action automatically via the GitHub Marketplace](TODO).
### Manual 3 clicks setup
Create a file `.github/workflows/opencommit.yml` with contents below:
```yml
name: 'OpenCommit Action'
name: 'OpenCommit'
on:
push:
@@ -37,7 +43,6 @@ on:
jobs:
opencommit:
timeout-minutes: 10
name: OpenCommit
runs-on: ubuntu-latest
permissions: write-all
@@ -49,7 +54,7 @@ jobs:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: di-sukharev/opencommit@github-action-v1.0.4
- uses: di-sukharev/opencommit@github-action
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -76,7 +81,7 @@ Interactive rebase (`rebase -i`) changes commit SHA, so commit history in remote
## 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.
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.
1. Install OpenCommit globally to use in any repository:
@@ -103,7 +108,7 @@ git add <files...>
opencommit
```
You can also use the `oco` shortcut:
You can also use the `oc` shortcut:
```sh
git add <files...>
@@ -133,19 +138,19 @@ Local config still has more priority as Global config, but you may set `OCO_MODE
Simply run any of the variable above like this:
```sh
oco config set OCO_OPENAI_API_KEY=gpt-4
oc config set OCO_OPENAI_API_KEY=gpt-4
```
Configure [GitMoji](https://gitmoji.dev/) to preface a message.
```sh
oco config set OCO_EMOJI=true
oc config set OCO_EMOJI=true
```
To remove preface emoji:
```sh
oco config set OCO_EMOJI=false
oc config set OCO_EMOJI=false
```
### Switch to GPT-4
@@ -155,7 +160,7 @@ By default OpenCommit uses GPT-3.5-turbo (ChatGPT).
You may switch to GPT-4 which performs better, but costs ~x15 times more 🤠
```sh
oco config set OCO_MODEL=gpt-4
oc config set OCO_MODEL=gpt-4
```
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.
@@ -166,25 +171,25 @@ To globally specify the language used to generate commit messages:
```sh
# de, German ,Deutsch
oco config set OCO_LANGUAGE=de
oco config set OCO_LANGUAGE=German
oco config set OCO_LANGUAGE=Deutsch
oc config set OCO_LANGUAGE=de
oc config set OCO_LANGUAGE=German
oc config set OCO_LANGUAGE=Deutsch
# fr, French, française
oco config set OCO_LANGUAGE=fr
oco config set OCO_LANGUAGE=French
oco config set OCO_LANGUAGE=française
oc config set OCO_LANGUAGE=fr
oc config set OCO_LANGUAGE=French
oc 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
### Git flags
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`.
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`.
```sh
oco --no-verify
oc --no-verify
```
is translated to :
@@ -213,13 +218,13 @@ You can set OpenCommit as Git [`prepare-commit-msg`](https://git-scm.com/docs/gi
To set the hook:
```sh
oco hook set
oc hook set
```
To unset the hook:
```sh
oco hook unset
oc hook unset
```
To use the hook:

View File

@@ -16272,7 +16272,7 @@ function G3(t, e2) {
// package.json
var package_default = {
name: "opencommit",
version: "2.1.0",
version: "2.0.16",
description: "Auto-generate impressive commits in 1 second. Killing lame commits with AI \u{1F92F}\u{1F52B}",
keywords: [
"git",
@@ -16289,6 +16289,7 @@ var package_default = {
main: "cli.js",
bin: {
opencommit: "./out/cli.cjs",
oc: "./out/cli.cjs",
oco: "./out/cli.cjs"
},
repository: {
@@ -16313,8 +16314,7 @@ var package_default = {
start: "node ./out/cli.cjs",
dev: "ts-node ./src/cli.ts",
build: "rimraf out && node esbuild.config.js",
deploy: "npm run build:push && npm version patch && git push origin --tags && npm publish --tag latest",
"build:push": "npm run build && git add . && git commit -m 'build' && git push",
deploy: "npm run build && npm version patch && npm publish --tag latest",
lint: "eslint src --ext ts && tsc --noEmit",
format: "prettier --write src"
},
@@ -17643,7 +17643,7 @@ var configValidators = {
}
validateConfig(
"OCO_OPENAI_MAX_TOKENS" /* OCO_OPENAI_MAX_TOKENS */,
value ? typeof value === "number" : void 0,
typeof value === "number",
"Must be a number"
);
return value;
@@ -17674,8 +17674,8 @@ var configValidators = {
},
["OCO_MODEL" /* OCO_MODEL */](value) {
validateConfig(
"OCO_MODEL" /* OCO_MODEL */,
["gpt-3.5-turbo", "gpt-4"].includes(value),
"OCO_OPENAI_BASE_PATH" /* OCO_OPENAI_BASE_PATH */,
value === "gpt-3.5-turbo" || value === "gpt-4",
`${value} is not supported yet, use 'gpt-4' or 'gpt-3.5-turbo' (default)`
);
return value;
@@ -17685,12 +17685,12 @@ var configPath = (0, import_path.join)((0, import_os.homedir)(), ".opencommit");
var getConfig = () => {
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) : void 0,
OCO_OPENAI_MAX_TOKENS: Number(process.env.OCO_OPENAI_MAX_TOKENS),
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_LANGUAGE: process.env.OCO_LANGUAGE || "en"
OCO_MODEL: process.env.OCO_MODEL,
OCO_LANGUAGE: process.env.OCO_LANGUAGE
};
const configExists = (0, import_fs.existsSync)(configPath);
if (!configExists)
@@ -17698,10 +17698,6 @@ var getConfig = () => {
const configFile = (0, import_fs.readFileSync)(configPath, "utf8");
const config4 = (0, import_ini.parse)(configFile);
for (const configKey of Object.keys(config4)) {
if (!config4[configKey] || ["null", "undefined"].includes(config4[configKey])) {
config4[configKey] = void 0;
continue;
}
try {
const validator = configValidators[configKey];
const validValue = validator(
@@ -21685,7 +21681,7 @@ var [command, mode] = process.argv.slice(2);
if (!apiKey && command !== "config" && mode !== "set" /* set */) {
ae("opencommit");
ce(
"OCO_OPENAI_API_KEY is not set, please run `oco config set OCO_OPENAI_API_KEY=<your token>. Make sure you add payment details, so API works.`"
"OCO_OPENAI_API_KEY is not set, please run `oc config set OCO_OPENAI_API_KEY=<your token>. Make sure you add payment details, so API works.`"
);
ce(
"For help look into README https://github.com/di-sukharev/opencommit#setup"
@@ -21732,17 +21728,6 @@ var OpenAi = class {
}
};
};
var getOpenCommitLatestVersion = async () => {
try {
const { data } = await axios_default.get(
"https://unpkg.com/opencommit/package.json"
);
return data.version;
} catch (_6) {
ce("Error while getting the latest version of opencommit");
return void 0;
}
};
var api = new OpenAi();
// src/utils/tokenCount.ts
@@ -21913,7 +21898,7 @@ var prepareCommitMessageHook = async (isStageAllFlag = false) => {
if (changedFiles)
await gitAdd({ files: changedFiles });
else {
ce("No changes detected, write some code and run `oco` again");
ce("No changes detected, write some code and run `oc` again");
process.exit(1);
}
}
@@ -22047,7 +22032,7 @@ async function commit(extraArgs2 = [], isStageAllFlag = false) {
if (changedFiles2)
await gitAdd({ files: changedFiles2 });
else {
ce("No changes detected, write some code and run `oco` again");
ce("No changes detected, write some code and run `oc` again");
process.exit(1);
}
}
@@ -22105,25 +22090,6 @@ ${stagedFiles.map((file) => ` ${file}`).join("\n")}`
process.exit(0);
}
// src/utils/checkIsLatestVersion.ts
var checkIsLatestVersion = async () => {
const latestVersion = await getOpenCommitLatestVersion();
if (latestVersion) {
const currentVersion = package_default.version;
if (currentVersion !== latestVersion) {
console.warn(
source_default.yellow(
`
You are not using the latest stable version of OpenCommit with new features and bug fixes.
Current version: ${currentVersion}. Latest version: ${latestVersion}.
\u{1F680} To update run: npm i -g opencommit@latest.
`
)
);
}
}
};
// src/cli.ts
var extraArgs = process.argv.slice(2);
Z2(
@@ -22136,7 +22102,6 @@ Z2(
help: { description: package_default.description }
},
async () => {
await checkIsLatestVersion();
if (await isHookCalled()) {
prepareCommitMessageHook();
} else {

View File

@@ -26839,7 +26839,7 @@ var configValidators = {
}
validateConfig(
"OCO_OPENAI_MAX_TOKENS" /* OCO_OPENAI_MAX_TOKENS */,
value ? typeof value === "number" : void 0,
typeof value === "number",
"Must be a number"
);
return value;
@@ -26870,8 +26870,8 @@ var configValidators = {
},
["OCO_MODEL" /* OCO_MODEL */](value) {
validateConfig(
"OCO_MODEL" /* OCO_MODEL */,
["gpt-3.5-turbo", "gpt-4"].includes(value),
"OCO_OPENAI_BASE_PATH" /* OCO_OPENAI_BASE_PATH */,
value === "gpt-3.5-turbo" || value === "gpt-4",
`${value} is not supported yet, use 'gpt-4' or 'gpt-3.5-turbo' (default)`
);
return value;
@@ -26881,12 +26881,12 @@ var configPath = (0, import_path.join)((0, import_os.homedir)(), ".opencommit");
var getConfig = () => {
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) : void 0,
OCO_OPENAI_MAX_TOKENS: Number(process.env.OCO_OPENAI_MAX_TOKENS),
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_LANGUAGE: process.env.OCO_LANGUAGE || "en"
OCO_MODEL: process.env.OCO_MODEL,
OCO_LANGUAGE: process.env.OCO_LANGUAGE
};
const configExists = (0, import_fs.existsSync)(configPath);
if (!configExists)
@@ -26894,10 +26894,6 @@ var getConfig = () => {
const configFile = (0, import_fs.readFileSync)(configPath, "utf8");
const config4 = (0, import_ini.parse)(configFile);
for (const configKey of Object.keys(config4)) {
if (!config4[configKey] || ["null", "undefined"].includes(config4[configKey])) {
config4[configKey] = void 0;
continue;
}
try {
const validator = configValidators[configKey];
const validValue = validator(
@@ -26973,7 +26969,7 @@ var [command, mode] = process.argv.slice(2);
if (!apiKey && command !== "config" && mode !== "set" /* set */) {
ae("opencommit");
ce(
"OCO_OPENAI_API_KEY is not set, please run `oco config set OCO_OPENAI_API_KEY=<your token>. Make sure you add payment details, so API works.`"
"OCO_OPENAI_API_KEY is not set, please run `oc config set OCO_OPENAI_API_KEY=<your token>. Make sure you add payment details, so API works.`"
);
ce(
"For help look into README https://github.com/di-sukharev/opencommit#setup"

5
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{
"name": "opencommit",
"version": "2.1.1",
"version": "2.0.17",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "opencommit",
"version": "2.1.1",
"version": "2.0.17",
"license": "MIT",
"dependencies": {
"@actions/core": "^1.10.0",
@@ -26,6 +26,7 @@
"openai": "^3.2.1"
},
"bin": {
"oc": "out/cli.cjs",
"oco": "out/cli.cjs",
"opencommit": "out/cli.cjs"
},

View File

@@ -1,6 +1,6 @@
{
"name": "opencommit",
"version": "2.2.0",
"version": "2.0.17",
"description": "Auto-generate impressive commits in 1 second. Killing lame commits with AI 🤯🔫",
"keywords": [
"git",
@@ -17,6 +17,7 @@
"main": "cli.js",
"bin": {
"opencommit": "./out/cli.cjs",
"oc": "./out/cli.cjs",
"oco": "./out/cli.cjs"
},
"repository": {
@@ -41,8 +42,7 @@
"start": "node ./out/cli.cjs",
"dev": "ts-node ./src/cli.ts",
"build": "rimraf out && node esbuild.config.js",
"deploy": "npm run build:push && npm version patch && git push origin --tags && npm publish --tag latest",
"build:push": "npm run build && git add . && git commit -m 'build' && git push",
"deploy": "npm run build && npm version patch && npm publish --tag latest",
"lint": "eslint src --ext ts && tsc --noEmit",
"format": "prettier --write src"
},

View File

@@ -21,7 +21,7 @@ if (!apiKey && command !== 'config' && mode !== CONFIG_MODES.set) {
intro('opencommit');
outro(
'OCO_OPENAI_API_KEY is not set, please run `oco config set OCO_OPENAI_API_KEY=<your token>. Make sure you add payment details, so API works.`'
'OCO_OPENAI_API_KEY is not set, please run `oc config set OCO_OPENAI_API_KEY=<your token>. Make sure you add payment details, so API works.`'
);
outro(
'For help look into README https://github.com/di-sukharev/opencommit#setup'

View File

@@ -7,7 +7,7 @@ import { configCommand } from './commands/config';
import { hookCommand, isHookCalled } from './commands/githook.js';
import { prepareCommitMessageHook } from './commands/prepare-commit-msg-hook';
import { commit } from './commands/commit';
import { checkIsLatestVersion } from './utils/checkIsLatestVersion';
// import { checkIsLatestVersion } from './utils/checkIsLatestVersion';
const extraArgs = process.argv.slice(2);
@@ -21,7 +21,7 @@ cli(
help: { description: packageJSON.description }
},
async () => {
await checkIsLatestVersion();
// await checkIsLatestVersion();
if (await isHookCalled()) {
prepareCommitMessageHook();

View File

@@ -1,5 +1,6 @@
import { execa } from 'execa';
import {
GenerateCommitMessageErrorEnum,
generateCommitMessageByDiff
} from '../generateCommitMessageFromGitDiff';
import {
@@ -138,7 +139,7 @@ export async function commit(
if (changedFiles) await gitAdd({ files: changedFiles });
else {
outro('No changes detected, write some code and run `oco` again');
outro('No changes detected, write some code and run `oc` again');
process.exit(1);
}
}

View File

@@ -80,7 +80,7 @@ export const configValidators = {
}
validateConfig(
CONFIG_KEYS.OCO_OPENAI_MAX_TOKENS,
value ? typeof value === 'number' : undefined,
typeof value === 'number',
'Must be a number'
);
@@ -117,8 +117,8 @@ export const configValidators = {
[CONFIG_KEYS.OCO_MODEL](value: any) {
validateConfig(
CONFIG_KEYS.OCO_MODEL,
['gpt-3.5-turbo', 'gpt-4'].includes(value),
CONFIG_KEYS.OCO_OPENAI_BASE_PATH,
value === 'gpt-3.5-turbo' || value === 'gpt-4',
`${value} is not supported yet, use 'gpt-4' or 'gpt-3.5-turbo' (default)`
);
return value;
@@ -134,12 +134,12 @@ 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: Number(process.env.OCO_OPENAI_MAX_TOKENS),
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_LANGUAGE: process.env.OCO_LANGUAGE || 'en'
OCO_MODEL: process.env.OCO_MODEL,
OCO_LANGUAGE: process.env.OCO_LANGUAGE
};
const configExists = existsSync(configPath);
@@ -149,10 +149,6 @@ export const getConfig = (): ConfigType | null => {
const config = iniParse(configFile);
for (const configKey of Object.keys(config)) {
if (!config[configKey] || ['null', 'undefined'].includes(config[configKey])) {
config[configKey] = undefined;
continue;
}
try {
const validator = configValidators[configKey as CONFIG_KEYS];
const validValue = validator(

View File

@@ -24,7 +24,7 @@ export const prepareCommitMessageHook = async (
if (changedFiles) await gitAdd({ files: changedFiles });
else {
outro('No changes detected, write some code and run `oco` again');
outro('No changes detected, write some code and run `oc` again');
process.exit(1);
}
}

View File

@@ -74,6 +74,9 @@ export enum GenerateCommitMessageErrorEnum {
emptyMessage = 'EMPTY_MESSAGE'
}
interface GenerateCommitMessageError {
error: GenerateCommitMessageErrorEnum;
}
const INIT_MESSAGES_PROMPT_LENGTH = INIT_MESSAGES_PROMPT.map(
(msg) => tokenCount(msg.content) + 4

View File

@@ -5,8 +5,8 @@
"module": "ESNext",
// "rootDir": "./src",
"resolveJsonModule": true,
"moduleResolution": "node",
"resolveJsonModule": true,
"allowJs": true,