mirror of
https://github.com/di-sukharev/opencommit.git
synced 2026-01-12 23:28:16 -05:00
Compare commits
23 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1c29b91408 | ||
|
|
425eeef732 | ||
|
|
52c396eb16 | ||
|
|
f5bcf58f7b | ||
|
|
4b53a08653 | ||
|
|
95d3d8b6c9 | ||
|
|
2c79bf22df | ||
|
|
e8c1a75a46 | ||
|
|
5d064ac873 | ||
|
|
8d01829a9b | ||
|
|
e9c66ae168 | ||
|
|
18b0004b81 | ||
|
|
4d4157087e | ||
|
|
3edb6e2fc1 | ||
|
|
d428102a67 | ||
|
|
9404f5d410 | ||
|
|
8c1eb4a5ad | ||
|
|
bafe7e9ede | ||
|
|
a4716b35a4 | ||
|
|
c1e9062ce0 | ||
|
|
c7efa6f935 | ||
|
|
1b70de1d20 | ||
|
|
853662acc4 |
10
package-lock.json
generated
10
package-lock.json
generated
@@ -1,16 +1,15 @@
|
||||
{
|
||||
"name": "opencommit",
|
||||
"version": "1.1.26",
|
||||
"version": "1.1.34",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "opencommit",
|
||||
"version": "1.1.26",
|
||||
"version": "1.1.34",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@clack/prompts": "^0.6.1",
|
||||
"@dqbd/tiktoken": "^1.0.2",
|
||||
"axios": "^1.3.4",
|
||||
"chalk": "^5.2.0",
|
||||
"cleye": "^1.3.2",
|
||||
@@ -84,11 +83,6 @@
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/@dqbd/tiktoken": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/@dqbd/tiktoken/-/tiktoken-1.0.2.tgz",
|
||||
"integrity": "sha512-AjGTBRWsMoVmVeN55NLyupyM8TNamOUBl6tj5t/leLDVup3CFGO9tVagNL1jf3GyZLkWZSTmYVbPQ/M2LEcNzw=="
|
||||
},
|
||||
"node_modules/@esbuild/android-arm": {
|
||||
"version": "0.15.18",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.15.18.tgz",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "opencommit",
|
||||
"version": "1.1.26",
|
||||
"version": "1.1.34",
|
||||
"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",
|
||||
|
||||
@@ -22,10 +22,9 @@ import {
|
||||
import chalk from 'chalk';
|
||||
import { trytm } from '../utils/trytm';
|
||||
|
||||
// Adding a function to get the list of remotes
|
||||
const getGitRemotes = async () => {
|
||||
const { stdout } = await execa('git', ['remote']);
|
||||
return stdout.split('\n').filter((remote) => remote.trim() !== '');
|
||||
return stdout.split('\n').filter((remote) => Boolean(remote.trim()));
|
||||
};
|
||||
|
||||
const generateCommitMessageFromGitDiff = async (
|
||||
@@ -77,6 +76,7 @@ ${chalk.grey('——————————————————')}`
|
||||
outro(`${chalk.green('✔')} successfully committed`);
|
||||
|
||||
outro(stdout);
|
||||
|
||||
const remotes = await getGitRemotes();
|
||||
|
||||
if (remotes.length === 1) {
|
||||
@@ -100,6 +100,9 @@ ${chalk.grey('——————————————————')}`
|
||||
);
|
||||
|
||||
if (stdout) outro(stdout);
|
||||
} else {
|
||||
outro('`git push` aborted');
|
||||
process.exit(0);
|
||||
}
|
||||
} else {
|
||||
const selectedRemote = (await select({
|
||||
@@ -207,5 +210,6 @@ export async function commit(
|
||||
outro(`${chalk.red('✖')} ${generateCommitError}`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
8
src/commands/githook.ts
Normal file → Executable file
8
src/commands/githook.ts
Normal file → Executable file
@@ -8,9 +8,9 @@ import { intro, outro } from '@clack/prompts';
|
||||
import { COMMANDS } from '../CommandsEnum.js';
|
||||
|
||||
const HOOK_NAME = 'prepare-commit-msg';
|
||||
const SYMLINK_URL = `.git/hooks/${HOOK_NAME}`;
|
||||
const SYMLINK_URL = path.join(path.sep, '.git', 'hooks', HOOK_NAME);
|
||||
|
||||
export const isHookCalled = process.argv[1].endsWith(`/${SYMLINK_URL}`);
|
||||
export const isHookCalled = process.argv[1].endsWith(`${SYMLINK_URL}`);
|
||||
|
||||
const isHookExists = existsSync(SYMLINK_URL);
|
||||
|
||||
@@ -28,7 +28,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 +40,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.`
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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.`
|
||||
},
|
||||
{
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
{
|
||||
"localLanguage": "spanish",
|
||||
"commitFix": "fix(server.ts): cambiar la variable port de minúsculas a mayúsculas PORT",
|
||||
"commitFeat": "feat(server.ts): añadir soporte para la variable de entorno process.env.PORT",
|
||||
"commitDescription": "La variable port ahora se llama PORT, lo que mejora la coherencia con las convenciones de nomenclatura, ya que PORT es una constante. El soporte para una variable de entorno permite que la aplicación sea más flexible, ya que ahora puede ejecutarse en cualquier puerto disponible especificado a través de la variable de entorno process.env.PORT."
|
||||
}
|
||||
|
||||
{
|
||||
"localLanguage": "spanish",
|
||||
"commitFix": "fix(server.ts): cambiar la variable port de minúsculas a mayúsculas PORT",
|
||||
"commitFeat": "feat(server.ts): añadir soporte para la variable de entorno process.env.PORT",
|
||||
"commitDescription": "La variable port ahora se llama PORT, lo que mejora la coherencia con las convenciones de nomenclatura, ya que PORT es una constante. El soporte para una variable de entorno permite que la aplicación sea más flexible, ya que ahora puede ejecutarse en cualquier puerto disponible especificado a través de la variable de entorno process.env.PORT."
|
||||
}
|
||||
|
||||
6
src/i18n/id_ID.json
Normal file
6
src/i18n/id_ID.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"localLanguage": "bahasa",
|
||||
"commitFix": "fix(server.ts): mengubah huruf port variable dari huruf kecil ke huruf besar PORT",
|
||||
"commitFeat": "feat(server.ts): menambahkan support di process.env.PORT environment variabel",
|
||||
"commitDescription": "Port variabel bernama PORT, yang membantu konsistensi dengan memberi nama yaitu PORT yang konstan. Bantuan environment variabel membantu aplikasi lebih fleksibel, dan dapat di jalankan di port manapun yang tertulis pada process.env.PORT"
|
||||
}
|
||||
@@ -10,6 +10,9 @@ 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 nl from '../i18n/nl.json' assert { type: 'json' };
|
||||
import ru from '../i18n/ru.json' assert { type: 'json' };
|
||||
import id_ID from '../i18n/id_ID.json' assert { type: 'json' };
|
||||
|
||||
export enum I18nLocals {
|
||||
'en' = 'en',
|
||||
@@ -18,12 +21,15 @@ export enum I18nLocals {
|
||||
'ja' = 'ja',
|
||||
'de' = 'de',
|
||||
'fr' = 'fr',
|
||||
'nl' = 'nl',
|
||||
'it' = 'it',
|
||||
'ko' = 'ko',
|
||||
'pt_br' = 'pt_br',
|
||||
'es_ES' = 'es_ES',
|
||||
'sv' = 'sv',
|
||||
};
|
||||
'ru' = 'ru',
|
||||
'id_ID' = 'id_ID'
|
||||
}
|
||||
|
||||
export const i18n = {
|
||||
en,
|
||||
@@ -37,7 +43,10 @@ export const i18n = {
|
||||
pt_br,
|
||||
vi_VN,
|
||||
es_ES,
|
||||
sv
|
||||
sv,
|
||||
id_ID,
|
||||
nl,
|
||||
ru
|
||||
};
|
||||
|
||||
export const I18N_CONFIG_ALIAS: { [key: string]: string[] } = {
|
||||
@@ -45,14 +54,17 @@ export const I18N_CONFIG_ALIAS: { [key: string]: string[] } = {
|
||||
zh_TW: ['zh_TW', '繁體中文', '繁體'],
|
||||
ja: ['ja', 'Japanese', 'にほんご'],
|
||||
ko: ['ko', 'Korean', '한국어'],
|
||||
de: ['de', 'German' ,'Deutsch'],
|
||||
de: ['de', 'German', 'Deutsch'],
|
||||
fr: ['fr', 'French', 'française'],
|
||||
it: ['it', 'Italian', 'italiano'],
|
||||
nl: ['nl', 'Dutch', 'Nederlands'],
|
||||
pt_br: ['pt_br', 'Portuguese', 'português'],
|
||||
vi_VN: ['vi_VN', 'Vietnamese', 'tiếng Việt'],
|
||||
en: ['en', 'English', 'english'],
|
||||
es_ES: ['es_ES', 'Spanish', 'español'],
|
||||
sv: ['sv', 'Swedish', 'Svenska'],
|
||||
ru: ['ru', 'Russian', 'русский'],
|
||||
id_ID: ['id_ID', 'Bahasa', 'bahasa']
|
||||
};
|
||||
|
||||
export function getI18nLocal(value: string): string | boolean {
|
||||
|
||||
6
src/i18n/nl.json
Normal file
6
src/i18n/nl.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"localLanguage": "Nederlands",
|
||||
"commitFix": "fix(server.ts): verander poortvariabele van kleine letters poort naar hoofdletters PORT",
|
||||
"commitFeat": "feat(server.ts): voeg ondersteuning toe voor process.env.PORT omgevingsvariabele",
|
||||
"commitDescription": "De poortvariabele heet nu PORT, wat de consistentie met de naamgevingsconventies verbetert omdat PORT een constante is. Ondersteuning voor een omgevingsvariabele maakt de applicatie flexibeler, omdat deze nu kan draaien op elke beschikbare poort die is gespecificeerd via de process.env.PORT omgevingsvariabele."
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
{
|
||||
"localLanguage": "português",
|
||||
"commitFix": "fix(server.ts): altera o caso da variável de porta de port minúscula para PORT maiúscula",
|
||||
"commitFeat": "feat(server.ts): adiciona suporte para a variável de ambiente process.env.PORT",
|
||||
"commitDescription": "A variável de porta agora é denominada PORT, o que melhora a consistência com as convenções de nomenclatura, pois PORT é uma constante. O suporte para uma variável de ambiente permite que o aplicativo seja mais flexível, pois agora pode ser executado em qualquer porta disponível especificada por meio da variável de ambiente process.env.PORT."
|
||||
"localLanguage": "português",
|
||||
"commitFix": "fix(server.ts): altera o caso da variável de porta de port minúscula para PORT maiúscula",
|
||||
"commitFeat": "feat(server.ts): adiciona suporte para a variável de ambiente process.env.PORT",
|
||||
"commitDescription": "A variável de porta agora é denominada PORT, o que melhora a consistência com as convenções de nomenclatura, pois PORT é uma constante. O suporte para uma variável de ambiente permite que o aplicativo seja mais flexível, pois agora pode ser executado em qualquer porta disponível especificada por meio da variável de ambiente process.env.PORT."
|
||||
}
|
||||
|
||||
6
src/i18n/ru.json
Normal file
6
src/i18n/ru.json
Normal 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."
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"localLanguage": "svenska",
|
||||
"commitFix": "fixa(server.ts): ändra variabelnamnet för port från små bokstäver till stora bokstäver PORT",
|
||||
"commitFeat": "nyhet(server.ts): lägg till stöd för process.env.PORT miljövariabel",
|
||||
"commitDescription": "Variabeln som innehåller portnumret heter nu PORT vilket förbättrar konsekvensen med namngivningskonventionerna eftersom PORT är en konstant. Stöd för en miljövariabel gör att applikationen kan vara mer flexibel då den nu kan köras på vilken port som helst som specificeras via miljövariabeln process.env.PORT."
|
||||
}
|
||||
"localLanguage": "svenska",
|
||||
"commitFix": "fixa(server.ts): ändra variabelnamnet för port från små bokstäver till stora bokstäver PORT",
|
||||
"commitFeat": "nyhet(server.ts): lägg till stöd för process.env.PORT miljövariabel",
|
||||
"commitDescription": "Variabeln som innehåller portnumret heter nu PORT vilket förbättrar konsekvensen med namngivningskonventionerna eftersom PORT är en konstant. Stöd för en miljövariabel gör att applikationen kan vara mer flexibel då den nu kan köras på vilken port som helst som specificeras via miljövariabeln process.env.PORT."
|
||||
}
|
||||
|
||||
@@ -26,16 +26,16 @@ export const getOpenCommitIgnore = (): Ignore => {
|
||||
};
|
||||
|
||||
export const getStagedFiles = async (): Promise<string[]> => {
|
||||
const { stdout: gitDir } = await execa("git", [
|
||||
"rev-parse",
|
||||
"--show-toplevel"
|
||||
const { stdout: gitDir } = await execa('git', [
|
||||
'rev-parse',
|
||||
'--show-toplevel'
|
||||
]);
|
||||
|
||||
const { stdout: files } = await execa("git", [
|
||||
"diff",
|
||||
"--name-only",
|
||||
"--cached",
|
||||
"--relative",
|
||||
const { stdout: files } = await execa('git', [
|
||||
'diff',
|
||||
'--name-only',
|
||||
'--cached',
|
||||
'--relative',
|
||||
gitDir
|
||||
]);
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2020",
|
||||
"target": "ESNext",
|
||||
"lib": ["ES5", "ES6"],
|
||||
|
||||
"module": "ESNext",
|
||||
|
||||
Reference in New Issue
Block a user