Compare commits

..

5 Commits

Author SHA1 Message Date
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
8 changed files with 48 additions and 61 deletions

View File

@@ -13,7 +13,7 @@
## Examples
Look into [the commits](https://github.com/di-sukharev/opencommit/commit) to see how OpenCommit works. Emoji and long commit description text is configurable.
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

View File

@@ -1,8 +1,4 @@
# 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.22",
"version": "0.0.2",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "open-commit",
"version": "0.0.22",
"version": "0.0.2",
"license": "ISC",
"dependencies": {
"@clack/prompts": "^0.6.1",

View File

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

View File

@@ -1,4 +1,4 @@
import { intro, outro } from '@clack/prompts';
import { intro, outro, text } from '@clack/prompts';
import {
ChatCompletionRequestMessage,
ChatCompletionResponseMessage,
@@ -6,7 +6,7 @@ import {
OpenAIApi
} from 'openai';
import { getConfig } from './commands/config';
import { CONFIG_KEYS, getConfig, setConfig } from './commands/config';
const config = getConfig();
@@ -14,26 +14,15 @@ let apiKey = config?.OPENAI_API_KEY;
if (!apiKey) {
intro('opencommit');
const apiKey = await text({
message: 'input your OPENAI_API_KEY'
});
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'
);
setConfig([[CONFIG_KEYS.OPENAI_API_KEY as string, apiKey as any]]);
outro('OPENAI_API_KEY is set');
}
// 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

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

@@ -1,7 +1,7 @@
#!/usr/bin/env node
import { cli } from 'cleye';
import packageJSON from '../package.json';
import packageJSON from '../package.json' assert { type: 'json' };
import { configCommand } from './commands/config';
import { hookCommand, isHookCalled } from './commands/githook.js';

View File

@@ -20,7 +20,7 @@ export const hookCommand = command(
parameters: ['<set/unset>']
},
async (argv) => {
const HOOK_URL = __filename;
const HOOK_PATH = fileURLToPath(new URL('cli.mjs', import.meta.url));
try {
await assertGitRepo();
@@ -29,17 +29,10 @@ export const hookCommand = command(
if (mode === 'set') {
intro(`setting opencommit as '${HOOK_NAME}' hook`);
if (isHookExists) {
let realPath;
try {
realPath = await fs.realpath(SYMLINK_URL);
} catch (error) {
outro(error as string);
realPath = null;
}
const realPath = await fs.realpath(SYMLINK_URL);
if (realPath === HOOK_URL)
if (realPath === HOOK_PATH)
return outro(`opencommit is already set as '${HOOK_NAME}'`);
throw new Error(
@@ -48,7 +41,7 @@ export const hookCommand = command(
}
await fs.mkdir(path.dirname(SYMLINK_URL), { recursive: true });
await fs.symlink(HOOK_URL, SYMLINK_URL, 'file');
await fs.symlink(HOOK_PATH, SYMLINK_URL, 'file');
await fs.chmod(SYMLINK_URL, 0o755);
return outro(`${chalk.green('✔')} Hook set`);
@@ -56,7 +49,6 @@ 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`
@@ -64,7 +56,7 @@ export const hookCommand = command(
}
const realpath = await fs.realpath(SYMLINK_URL);
if (realpath !== HOOK_URL) {
if (realpath !== HOOK_PATH) {
return outro(
`opencommit wasn't previously set as '${HOOK_NAME}' hook, but different hook was, if you want to remove it — do it manually`
);

View File

@@ -1,25 +1,36 @@
{
"compilerOptions": {
"target": "ES2020",
"lib": ["ES5"],
/* Projects */
"module": "CommonJS",
// "rootDir": "./src",
"moduleResolution": "node",
"resolveJsonModule": true,
/* Language and Environment */
"target": "ESNext" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
"lib": [
"ESNext"
] /* Specify a set of bundled library declaration files that describe the target runtime environment. */,
"allowJs": true,
/* Modules */
"module": "ESNext" /* Specify what module code is generated. */,
// "rootDir": "./src" /* Specify the root folder within your source files. */,
"moduleResolution": "node" /* Specify how TypeScript looks up a file from a given module specifier. */,
"resolveJsonModule": true /* Enable importing .json files. */,
"outDir": "./out",
/* JavaScript Support */
"allowJs": true /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
/* Emit */
"outDir": "./out" /* Specify an output folder for all emitted files. */,
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
/* Interop Constraints */
"esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */,
"forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
"skipLibCheck": true
/* Type Checking */
"strict": true /* Enable all strict type-checking options. */,
"noUnusedLocals": true /* Enable error reporting when local variables aren't read. */,
"noUnusedParameters": true /* Raise an error when a function parameter isn't read. */,
/* Completeness */
"skipLibCheck": true /* Skip type checking all .d.ts files. */
},
"exclude": ["node_modules"],
"ts-node": {