Compare commits

..

14 Commits

Author SHA1 Message Date
di-sukharev
e9c66ae168 1.1.32 2023-03-29 18:24:18 +08:00
di-sukharev
18b0004b81 1.1.31 2023-03-29 18:24:14 +08:00
di-sukharev
4d4157087e Merge branch 'dev' of github.com:di-sukharev/opencommit into dev 2023-03-29 18:23:46 +08:00
di-sukharev
3edb6e2fc1 chore(generateCommitMessageFromGitDiff.ts): fix typo in GitMoji convention 2023-03-29 18:23:25 +08:00
Andrew
d428102a67 [FEAT](i18n): Add support for Russian language (ru) (#75) 2023-03-29 14:11:18 +08:00
di-sukharev
9404f5d410 1.1.30 2023-03-29 11:31:38 +08:00
di-sukharev
8c1eb4a5ad 1.1.29 2023-03-29 11:31:35 +08:00
di-sukharev
bafe7e9ede refactor(prepare-commit-msg-hook.ts): simplify conditional statements
The conditional statements in the prepareCommitMessageHook function have been simplified to improve readability. The first conditional statement now checks if there are no staged files and no changed files, and if so, it will output a message and exit the process. The second conditional statement now checks if there are no staged files but there are changed files, and if so, it will add the changed files to the staging area.
2023-03-29 11:31:27 +08:00
di-sukharev
a4716b35a4 1.1.28 2023-03-29 11:26:59 +08:00
di-sukharev
c1e9062ce0 1.1.27 2023-03-29 11:26:51 +08:00
di-sukharev
c7efa6f935 refactor: remove @dqbd/tiktoken dependency
chore(tsconfig.json): change target to ESNext
The @dqbd/tiktoken dependency was removed from the package.json file. This dependency was not being used in the project and was therefore removed to reduce the size of the project. The target in the tsconfig.json file was changed from ES2020 to ESNext to allow for the use of the latest ECMAScript features.
2023-03-29 11:26:19 +08:00
di-sukharev
1b70de1d20 fix(githook.ts): capitalize OpenCommit in console output
chore(githook.ts): remove unused import
refactor(tokenCount.ts): simplify token count calculation
The console output now correctly capitalizes OpenCommit for consistency with the project name. The unused import of fileURLToPath is removed. The tokenCount function is refactored to simplify the calculation of the token count. The Tiktoken library is no longer used, and the token count is now calculated based on the length of the content divided by an average token length of 2.7 characters.
2023-03-29 11:26:05 +08:00
di-sukharev
853662acc4 refactor(tokenCount.ts): format code with consistent indentation and quotes
The code has been reformatted to use consistent indentation and quotes. This improves the readability and maintainability of the code. No functionality has been changed.
2023-03-29 11:25:48 +08:00
di-sukharev
0e1ad33179 1.1.26 2023-03-29 10:45:35 +08:00
9 changed files with 33 additions and 22 deletions

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{
"name": "opencommit",
"version": "1.1.25",
"version": "1.1.32",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "opencommit",
"version": "1.1.25",
"version": "1.1.32",
"license": "MIT",
"dependencies": {
"@clack/prompts": "^0.6.1",

View File

@@ -1,6 +1,6 @@
{
"name": "opencommit",
"version": "1.1.25",
"version": "1.1.32",
"description": "GPT CLI to auto-generate impressive commits in 1 second. Killing lame commits with AI 🤯🔫",
"keywords": [
"git",
@@ -60,7 +60,6 @@
},
"dependencies": {
"@clack/prompts": "^0.6.1",
"@dqbd/tiktoken": "^1.0.2",
"axios": "^1.3.4",
"chalk": "^5.2.0",
"cleye": "^1.3.2",

5
src/commands/githook.ts Normal file → Executable file
View File

@@ -6,6 +6,7 @@ import { existsSync } from 'fs';
import chalk from 'chalk';
import { intro, outro } from '@clack/prompts';
import { COMMANDS } from '../CommandsEnum.js';
import { fileURLToPath } from 'url';
const HOOK_NAME = 'prepare-commit-msg';
const SYMLINK_URL = `.git/hooks/${HOOK_NAME}`;
@@ -28,7 +29,7 @@ export const hookCommand = command(
const { setUnset: mode } = argv._;
if (mode === 'set') {
intro(`setting opencommit as '${HOOK_NAME}' hook`);
intro(`setting OpenCommit as '${HOOK_NAME}' hook`);
if (isHookExists) {
let realPath;
@@ -40,7 +41,7 @@ export const hookCommand = command(
}
if (realPath === HOOK_URL)
return outro(`opencommit is already set as '${HOOK_NAME}'`);
return outro(`OpenCommit is already set as '${HOOK_NAME}'`);
throw new Error(
`Different ${HOOK_NAME} is already set. Remove it before setting opencommit as '${HOOK_NAME}' hook.`

View File

@@ -20,12 +20,13 @@ export const prepareCommitMessageHook = async () => {
const stagedFiles = await getStagedFiles();
const changedFiles = await getChangedFiles();
if (!stagedFiles && changedFiles) await gitAdd({ files: changedFiles });
else {
if (!stagedFiles && !changedFiles) {
outro('No changes detected, write some code and run `oc` again');
process.exit(1);
}
if (!stagedFiles && changedFiles) await gitAdd({ files: changedFiles });
const staged = await getStagedFiles();
if (!staged) return;

View File

@@ -16,8 +16,8 @@ const INIT_MESSAGES_PROMPT: Array<ChatCompletionRequestMessage> = [
role: ChatCompletionRequestMessageRoleEnum.System,
// prettier-ignore
content: `You are to act as the author of a commit message in git. Your mission is to create clean and comprehensive commit messages in the conventional commit convention and explain why a change was done. I'll send you an output of 'git diff --staged' command, and you convert it into a commit message.
${config?.emoji? 'Use Gitmoji convention to preface the commit.': 'Do not preface the commit with anything.'}
${config?.description ? 'Add a short description of why the commit is done after the commit message. Don\'t start it with "This commit", just describe the changes.': "Don't add any descriptions to the commit, only commit message."}
${config?.emoji? 'Use GitMoji convention to preface the commit.': 'Do not preface the commit with anything.'}
${config?.description ? 'Add a short description of WHY the changes are done after the commit message. Don\'t start it with "This commit", just describe the changes.': "Don't add any descriptions to the commit, only commit message."}
Use the present tense. Lines must not be longer than 74 characters. Use ${translation.localLanguage} to answer.`
},
{

View File

@@ -10,6 +10,7 @@ import pt_br from '../i18n/pt_br.json' assert { type: 'json' };
import vi_VN from '../i18n/vi_VN.json' assert { type: 'json' };
import es_ES from '../i18n/es_ES.json' assert { type: 'json' };
import sv from '../i18n/sv.json' assert { type: 'json' };
import ru from '../i18n/ru.json' assert { type: 'json' };
export enum I18nLocals {
'en' = 'en',
@@ -23,6 +24,7 @@ export enum I18nLocals {
'pt_br' = 'pt_br',
'es_ES' = 'es_ES',
'sv' = 'sv',
'ru' = 'ru',
};
export const i18n = {
@@ -37,7 +39,8 @@ export const i18n = {
pt_br,
vi_VN,
es_ES,
sv
sv,
ru,
};
export const I18N_CONFIG_ALIAS: { [key: string]: string[] } = {
@@ -53,6 +56,7 @@ export const I18N_CONFIG_ALIAS: { [key: string]: string[] } = {
en: ['en', 'English', 'english'],
es_ES: ['es_ES', 'Spanish', 'español'],
sv: ['sv', 'Swedish', 'Svenska'],
ru: ['ru', 'Russian', 'русский'],
};
export function getI18nLocal(value: string): string | boolean {

6
src/i18n/ru.json Normal file
View File

@@ -0,0 +1,6 @@
{
"localLanguage": "русский",
"commitFix": "fix(server.ts): изменение регистра переменной порта с нижнего регистра port на верхний регистр PORT",
"commitFeat": "feat(server.ts): добавлена поддержка переменной окружения process.env.PORT",
"commitDescription": "Переменная port теперь называется PORT, что улучшает согласованность с соглашениями об именовании констант. Поддержка переменной окружения позволяет приложению быть более гибким, запускаясь на любом доступном порту, указанном с помощью переменной окружения process.env.PORT."
}

View File

@@ -1,14 +1,14 @@
import { Tiktoken } from "@dqbd/tiktoken/lite"
import cl100k_base from "@dqbd/tiktoken/encoders/cl100k_base.json" assert{type: "json"}
// import { Tiktoken } from '@dqbd/tiktoken/lite';
// import cl100k_base from '@dqbd/tiktoken/encoders/cl100k_base.json' assert { type: 'json' };
export function tokenCount(content: string): number {
const encoding = new Tiktoken(
cl100k_base.bpe_ranks,
cl100k_base.special_tokens,
cl100k_base.pat_str
);
const tokens = encoding.encode(content);
encoding.free();
// const encoding = new Tiktoken(
// cl100k_base.bpe_ranks,
// cl100k_base.special_tokens,
// cl100k_base.pat_str
// );
// const tokens = encoding.encode(content);
// encoding.free();
return tokens.length;
return content.length / 2.7;
}

View File

@@ -1,6 +1,6 @@
{
"compilerOptions": {
"target": "ES2020",
"target": "ESNext",
"lib": ["ES5", "ES6"],
"module": "ESNext",