Compare commits

...

31 Commits

Author SHA1 Message Date
di-sukharev
6126fad25c 0.0.16 2023-03-06 21:38:26 +08:00
di-sukharev
01cdd2f58d removed async iife 2023-03-06 21:36:37 +08:00
di-sukharev
acdf464d2e 0.0.15 2023-03-06 21:34:03 +08:00
di-sukharev
3705a66ada 0.0.14 2023-03-06 21:33:06 +08:00
di-sukharev
bdb8da49b7 * 🚀 chore(cli.ts): change file mode from 100644 to 100755
This commit changes the file mode of cli.ts from 100644 to 100755. This change allows the file to be executable.
2023-03-06 21:33:00 +08:00
di-sukharev
6e896ec428 * 🐛 fix(githook.ts): fix HOOK_PATH import path
The import path for HOOK_PATH was incorrect, causing the file to not be found. The path has been updated to correctly reference the cli.cjs file.
2023-03-06 21:07:03 +08:00
di-sukharev
9ce961ccc0 0.0.13 2023-03-06 21:03:28 +08:00
di-sukharev
1a2f6416cc * 🐛 fix(githook.ts): fix file path in URL constructor
The file path in the URL constructor was incorrect, causing the file to not be found. The file path has been corrected to point to the correct location.
2023-03-06 21:03:25 +08:00
di-sukharev
4fa438ab17 0.0.12 2023-03-06 21:00:50 +08:00
di-sukharev
4ad7a5f779 * 🐛 fix(githook.ts): fix HOOK_PATH import path
* 📝 docs(TODO.md): add tasks for adding tests and making hook work
The HOOK_PATH import path was incorrect and has been fixed. The TODO list has been updated to include tasks for adding tests and making the hook work.
2023-03-06 21:00:41 +08:00
di-sukharev
5c0b31600f 0.0.11 2023-03-06 19:27:34 +08:00
di-sukharev
d785b821ea * 📝 docs(README.md): comment out Git hook section
The Git hook section has been commented out as it is not currently relevant to the project.
2023-03-06 19:27:19 +08:00
di-sukharev
c50c416dfc 0.0.10 2023-03-06 19:22:34 +08:00
di-sukharev
f8720ff089 0.0.9 2023-03-06 19:22:14 +08:00
di-sukharev
afa5949c06 * 📦 chore(package.json): rename prepublish script to patch
The prepublish script has been renamed to patch to better reflect its purpose of incrementing the patch version of the package.
2023-03-06 19:22:11 +08:00
di-sukharev
b1ec69e4dd * 🐛 fix(githook.ts): change cli file extension from .mjs to .cjs
The file extension of the cli file was changed from .mjs to .cjs to ensure compatibility with Node.js versions that do not support ES modules.
2023-03-06 19:21:24 +08:00
di-sukharev
0061816b6a * 🐛 fix(TODO.md): add missing TODO item
* 🐛 fix(TODO.md): update existing TODO item
The first item is a fix for a missing TODO item. The second item is an update to an existing TODO item. The bundle size can be reduced by properly configuring esbuild. Additionally, small files can be batched together in a single request to further reduce the bundle size.
2023-03-06 19:20:42 +08:00
di-sukharev
352b81c6c6 * 🚀 chore(package.json): change 'publish' script to 'prepublish'
The 'publish' script has been changed to 'prepublish' to ensure that the version is updated before publishing the package. This is a best practice to ensure that the published package has the correct version number.
2023-03-06 19:09:27 +08:00
di-sukharev
430776af29 0.0.8 2023-03-06 19:09:04 +08:00
di-sukharev
c573edea97 0.0.7 2023-03-06 19:08:57 +08:00
di-sukharev
5282734583 * 🐛 fix(package.json): remove npm publish command from publish script
The npm publish command has been removed from the publish script. This is because the command should be run manually after bumping the version number.
2023-03-06 19:08:37 +08:00
di-sukharev
9c67a3774f 0.0.6 2023-03-06 19:08:01 +08:00
di-sukharev
deeb7cdf97 0.0.5 2023-03-06 19:07:58 +08:00
di-sukharev
fe819f0814 0.0.4 2023-03-06 19:07:56 +08:00
di-sukharev
578a30c330 0.0.3 2023-03-06 19:07:54 +08:00
di-sukharev
973a4a2843 * 🐛 fix(package.json): change cli file extension from .mjs to .cjs
*  feat(package.json): add publish script
The cli file extension has been changed from .mjs to .cjs to improve compatibility with Node.js. The publish script has been added to simplify the process of publishing a new version of the package to npm.

* 🎨 style(api.ts): remove unused import statement
* 🐛 fix(api.ts): remove setConfig function call
* 🚧 chore(api.ts): add comment to explain apiKey variable initialization
* 🚧 chore(api.ts): comment out code block that prompts user for OPENAI_API_KEY
The unused import statement for `text` function from `@clack/prompts` has been removed. The `setConfig` function call has been removed as it is not needed and was causing an error. A comment has been added to explain the initialization of the `apiKey` variable. The code block that prompts the user for `OPENAI_API_KEY` has been commented out as it is not needed and was causing an error.

* 🐛 fix(tsconfig.json): change target to ES6
The target was previously set to ESNext, which is not supported by all browsers. Changing it to ES6 ensures that the emitted JavaScript is compatible with a wider range of browsers.
2023-03-06 19:07:48 +08:00
di-sukharev
144f6b4499 0.0.2 2023-03-06 18:52:08 +08:00
di-sukharev
4b7cb77ea4 * 📦 chore(package.json): add repository and author fields
The repository field is added to specify the URL of the project's repository. The author field is updated to include the author's GitHub profile URL.
2023-03-06 18:47:22 +08:00
di-sukharev
58d2eb1b09 * 🎨 style(README.md): update OpenCommit logo filename
The logo filename has been updated to match the new filename of the logo file.
2023-03-06 18:41:36 +08:00
di-sukharev
9897d2ff5f * 📝 docs(README.md): add examples section
Added an examples section to the README.md file to showcase how OpenCommit works. The section includes a link to the relevant commit and a brief description of the configurable options.
2023-03-06 18:40:31 +08:00
di-sukharev
17a28d697b * 🐛 fix(generateCommitMessageFromGitDiff.ts): add length of initial messages prompt to check for maximum request tokens
*  feat(generateCommitMessageFromGitDiff.ts): add support for generating commit messages with chat completion
The length of the initial messages prompt is now added to the check for maximum request tokens to ensure that the request does not exceed the maximum allowed tokens. Support for generating commit messages with chat completion has been added, which allows for more efficient and streamlined commit message generation.
2023-03-06 18:38:33 +08:00
9 changed files with 62 additions and 25 deletions

View File

@@ -1,6 +1,6 @@
<div align="center">
<div>
<img src=".github/OC-grad.svg" alt="OpenCommit logo"/>
<img src=".github/logo-grad.svg" alt="OpenCommit logo"/>
<h1 align="center">OpenCommit</h1>
<h4 align="center">Author <a href="https://github.com/di-sukharev">@di-sukharev</a> <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>
@@ -11,6 +11,10 @@
---
## Examples
Look into [the commits](https://github.com/di-sukharev/opencommit/commit/4795a695800686c42e7c72fca7569103d21cd510) to see how OpenCommit works. Emoji and long commit description text is configurable.
## Setup
> The minimum supported version of Node.js is the latest v14. Check your Node.js version with `node --version`.
@@ -79,7 +83,7 @@ To remove description:
opencommit config set description=false
```
## Git hook
<!-- ## Git hook
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.
@@ -102,7 +106,7 @@ To use the hook:
git commit
```
Or follow the process of your IDE Source Control feature, when it calls `git commit` command — OpenCommit will integrate into the flow.
Or follow the process of your IDE Source Control feature, when it calls `git commit` command — OpenCommit will integrate into the flow. -->
## Payments

View File

@@ -1,4 +1,8 @@
# TODOs
- [] [build for both mjs and cjs](https://snyk.io/blog/best-practices-create-modern-npm-package/)
- []
- [] make bundle smaller by properly configuring esbuild
- [] do // TODOs in the code
- [] batch small files in one request
- [] add tests
- [] make hook work

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{
"name": "open-commit",
"version": "0.0.1",
"version": "0.0.16",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "open-commit",
"version": "0.0.1",
"version": "0.0.16",
"license": "ISC",
"dependencies": {
"@clack/prompts": "^0.6.1",

View File

@@ -1,6 +1,6 @@
{
"name": "opencommit",
"version": "0.0.1",
"version": "0.0.16",
"description": "AI generates conventional commits with mind-blowing accuracy.",
"keywords": [
"git",
@@ -12,11 +12,14 @@
],
"main": "cli.js",
"bin": {
"opencommit": "./out/cli.mjs",
"oc": "./out/cli.mjs"
"opencommit": "./out/cli.cjs",
"oc": "./out/cli.cjs"
},
"repository": {
"url": "https://github.com/di-sukharev/opencommit"
},
"type": "module",
"author": "",
"author": "https://github.com/di-sukharev",
"license": "ISC",
"files": [
"out/**/*"
@@ -31,9 +34,10 @@
},
"scripts": {
"watch": "npm run -S build -- --sourcemap --watch",
"start": "node ./out/cli.mjs",
"start": "node ./out/cli.cjs",
"dev": "ts-node ./src/cli.ts",
"build": "rimraf out && esbuild ./src/cli.ts --bundle --outfile=out/cli.mjs --format=esm --platform=node",
"build": "rimraf out && esbuild ./src/cli.ts --bundle --outfile=out/cli.cjs --format=cjs --platform=node",
"patch": "npm version patch",
"lint": "eslint src --ext ts && tsc --noEmit"
},
"devDependencies": {

View File

@@ -1,4 +1,4 @@
import { intro, outro, text } from '@clack/prompts';
import { intro, outro } from '@clack/prompts';
import {
ChatCompletionRequestMessage,
ChatCompletionResponseMessage,
@@ -6,7 +6,7 @@ import {
OpenAIApi
} from 'openai';
import { CONFIG_KEYS, getConfig, setConfig } from './commands/config';
import { getConfig } from './commands/config';
const config = getConfig();
@@ -14,15 +14,26 @@ let apiKey = config?.OPENAI_API_KEY;
if (!apiKey) {
intro('opencommit');
const apiKey = await text({
message: 'input your OPENAI_API_KEY'
});
setConfig([[CONFIG_KEYS.OPENAI_API_KEY as string, apiKey as any]]);
outro('OPENAI_API_KEY is set');
outro(
'OPENAI_API_KEY is not set, please run `oc config set OPENAI_API_KEY=<your token>`'
);
outro(
'For help Look into README https://github.com/di-sukharev/opencommit#setup'
);
}
// if (!apiKey) {
// intro('opencommit');
// const apiKey = await text({
// message: 'input your OPENAI_API_KEY'
// });
// setConfig([[CONFIG_KEYS.OPENAI_API_KEY as string, apiKey as any]]);
// outro('OPENAI_API_KEY is set');
// }
class OpenAi {
private openAiApiConfiguration = new OpenAiApiConfiguration({
apiKey: apiKey

0
src/cli.ts Normal file → Executable file
View File

View File

@@ -20,7 +20,7 @@ export const hookCommand = command(
parameters: ['<set/unset>']
},
async (argv) => {
const HOOK_PATH = fileURLToPath(new URL('cli.mjs', import.meta.url));
const HOOK_PATH = fileURLToPath(new URL('cli.cjs', import.meta.url));
try {
await assertGitRepo();
@@ -29,8 +29,15 @@ export const hookCommand = command(
if (mode === 'set') {
intro(`setting opencommit as '${HOOK_NAME}' hook`);
if (isHookExists) {
const realPath = await fs.realpath(SYMLINK_URL);
let realPath;
try {
realPath = await fs.realpath(SYMLINK_URL);
} catch (error) {
outro(error as string);
realPath = null;
}
if (realPath === HOOK_PATH)
return outro(`opencommit is already set as '${HOOK_NAME}'`);
@@ -49,6 +56,7 @@ export const hookCommand = command(
if (mode === 'unset') {
intro(`unsetting opencommit as '${HOOK_NAME}' hook`);
if (!isHookExists) {
return outro(
`opencommit wasn't previously set as '${HOOK_NAME}' hook, nothing to remove`

View File

@@ -77,13 +77,17 @@ interface GenerateCommitMessageError {
error: GenerateCommitMessageErrorEnum;
}
const INIT_MESSAGES_PROMPT_LENGTH = INIT_MESSAGES_PROMPT.map(
(msg) => msg.content
).join('').length;
export const generateCommitMessageWithChatCompletion = async (
diff: string
): Promise<string | GenerateCommitMessageError> => {
try {
const MAX_REQ_TOKENS = 3900;
if (diff.length >= MAX_REQ_TOKENS) {
if (INIT_MESSAGES_PROMPT_LENGTH + diff.length >= MAX_REQ_TOKENS) {
const separator = 'diff --git ';
const diffByFiles = diff.split(separator).slice(1);
@@ -91,11 +95,13 @@ export const generateCommitMessageWithChatCompletion = async (
const commitMessages = [];
for (const diffFile of diffByFiles) {
if (diffFile.length >= MAX_REQ_TOKENS) continue;
if (INIT_MESSAGES_PROMPT_LENGTH + diffFile.length >= MAX_REQ_TOKENS)
continue;
const messages = generateCommitMessageChatCompletionPrompt(
separator + diffFile
);
const commitMessage = await api.generateCommitMessage(messages);
// TODO: handle this edge case

View File

@@ -5,7 +5,7 @@
/* Language and Environment */
"target": "ESNext" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
"lib": [
"ESNext"
"ES6"
] /* Specify a set of bundled library declaration files that describe the target runtime environment. */,
/* Modules */