mirror of
https://github.com/di-sukharev/opencommit.git
synced 2026-01-13 07:38:01 -05:00
Compare commits
4 Commits
update_oll
...
390-add_co
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
68dc9c36eb | ||
|
|
e063faa491 | ||
|
|
c7b1a5bcdc | ||
|
|
92943d3da8 |
17
README.md
17
README.md
@@ -76,8 +76,7 @@ oco config set OCO_AI_PROVIDER='ollama'
|
||||
If you want to use a model other than mistral (default), you can do so by setting the `OCO_AI_PROVIDER` environment variable as follows:
|
||||
|
||||
```sh
|
||||
oco config set OCO_AI_PROVIDER='ollama'
|
||||
oco config set OCO_MODEL='llama3:8b'
|
||||
oco config set OCO_AI_PROVIDER='ollama/llama3:8b'
|
||||
```
|
||||
|
||||
If you have ollama that is set up in docker/ on another machine with GPUs (not locally), you can change the default endpoint url.
|
||||
@@ -128,12 +127,12 @@ OCO_TOKENS_MAX_OUTPUT=<max response tokens (default: 500)>
|
||||
OCO_OPENAI_BASE_PATH=<may be used to set proxy path to OpenAI api>
|
||||
OCO_DESCRIPTION=<postface a message with ~3 sentences description of the changes>
|
||||
OCO_EMOJI=<boolean, add GitMoji>
|
||||
OCO_MODEL=<either 'gpt-4o', 'gpt-4', 'gpt-4-turbo', 'gpt-3.5-turbo' (default), 'gpt-3.5-turbo-0125', 'gpt-4-1106-preview', 'gpt-4-turbo-preview' or 'gpt-4-0125-preview' or any Anthropic or Ollama model or any string basically, but it should be a valid model name>
|
||||
OCO_MODEL=<either 'gpt-4o', 'gpt-4', 'gpt-4-turbo', 'gpt-3.5-turbo' (default), 'gpt-3.5-turbo-0125', 'gpt-4-1106-preview', 'gpt-4-turbo-preview' or 'gpt-4-0125-preview' or any string basically, but it should be a valid model name>
|
||||
OCO_LANGUAGE=<locale, scroll to the bottom to see options>
|
||||
OCO_MESSAGE_TEMPLATE_PLACEHOLDER=<message template placeholder, default: '$msg'>
|
||||
OCO_PROMPT_MODULE=<either conventional-commit or @commitlint, default: conventional-commit>
|
||||
OCO_ONE_LINE_COMMIT=<one line commit message, default: false>
|
||||
OCO_AI_PROVIDER=<openai (default), anthropic, azure, ollama>
|
||||
OCO_AI_PROVIDER=<openai (default), anthropic, azure, ollama or ollama/model>
|
||||
...
|
||||
```
|
||||
|
||||
@@ -163,16 +162,6 @@ oco config set OCO_EMOJI=false
|
||||
|
||||
Other config options are behaving the same.
|
||||
|
||||
### Output WHY the changes were done (WIP)
|
||||
|
||||
You can set the `OCO_WHY` config to `true` to have OpenCommit output a short description of WHY the changes were done after the commit message. Default is `false`.
|
||||
|
||||
To make this perform accurate we must store 'what files do' in some kind of an index or embedding and perform a lookup (kinda RAG) for the accurate git commit message. If you feel like building this comment on this ticket https://github.com/di-sukharev/opencommit/issues/398 and let's go from there together.
|
||||
|
||||
```sh
|
||||
oco config set OCO_WHY=true
|
||||
```
|
||||
|
||||
### Switch to GPT-4 or other models
|
||||
|
||||
By default, OpenCommit uses `gpt-4o-mini` model.
|
||||
|
||||
10625
out/cli.cjs
10625
out/cli.cjs
File diff suppressed because one or more lines are too long
@@ -46564,7 +46564,6 @@ var CONFIG_KEYS = /* @__PURE__ */ ((CONFIG_KEYS2) => {
|
||||
CONFIG_KEYS2["OCO_EMOJI"] = "OCO_EMOJI";
|
||||
CONFIG_KEYS2["OCO_MODEL"] = "OCO_MODEL";
|
||||
CONFIG_KEYS2["OCO_LANGUAGE"] = "OCO_LANGUAGE";
|
||||
CONFIG_KEYS2["OCO_WHY"] = "OCO_WHY";
|
||||
CONFIG_KEYS2["OCO_MESSAGE_TEMPLATE_PLACEHOLDER"] = "OCO_MESSAGE_TEMPLATE_PLACEHOLDER";
|
||||
CONFIG_KEYS2["OCO_PROMPT_MODULE"] = "OCO_PROMPT_MODULE";
|
||||
CONFIG_KEYS2["OCO_AI_PROVIDER"] = "OCO_AI_PROVIDER";
|
||||
@@ -46855,7 +46854,6 @@ var DEFAULT_CONFIG = {
|
||||
OCO_ONE_LINE_COMMIT: false,
|
||||
OCO_TEST_MOCK_TYPE: "commit-message",
|
||||
OCO_FLOWISE_ENDPOINT: ":",
|
||||
OCO_WHY: false,
|
||||
OCO_GITPUSH: true
|
||||
};
|
||||
var initGlobalConfig = (configPath = defaultConfigPath) => {
|
||||
@@ -56902,10 +56900,7 @@ var OllamaAi = class {
|
||||
stream: false
|
||||
};
|
||||
try {
|
||||
const response = await this.client.post(
|
||||
this.client.getUri(this.config),
|
||||
params
|
||||
);
|
||||
const response = await this.client.post("", params);
|
||||
const message = response.data.message;
|
||||
return message?.content;
|
||||
} catch (err) {
|
||||
@@ -61385,7 +61380,7 @@ Example Git Diff is to follow:`
|
||||
];
|
||||
var INIT_MAIN_PROMPT = (language, prompts) => ({
|
||||
role: "system",
|
||||
content: `${IDENTITY} Your mission is to create clean and comprehensive commit messages in the given @commitlint convention and explain WHAT were the changes ${config2.OCO_WHY ? "and WHY the changes were done" : ""}. I'll send you an output of 'git diff --staged' command, and you convert it into a commit message.
|
||||
content: `${IDENTITY} Your mission is to create clean and comprehensive commit messages in the given @commitlint convention and explain WHAT were the changes and WHY the changes were done. I'll send you an output of 'git diff --staged' command, and you convert it into a commit message.
|
||||
${config2.OCO_EMOJI ? "Use GitMoji convention to preface the commit." : "Do not preface the commit with anything."}
|
||||
${config2.OCO_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. Use ${language} to answer.
|
||||
@@ -61405,23 +61400,12 @@ var commitlintPrompts = {
|
||||
// src/modules/commitlint/pwd-commitlint.ts
|
||||
var import_promises = __toESM(require("fs/promises"), 1);
|
||||
var import_path3 = __toESM(require("path"), 1);
|
||||
var findModulePath = (moduleName) => {
|
||||
const searchPaths = [
|
||||
import_path3.default.join("node_modules", moduleName),
|
||||
import_path3.default.join("node_modules", ".pnpm")
|
||||
];
|
||||
for (const basePath of searchPaths) {
|
||||
try {
|
||||
const resolvedPath = require.resolve(moduleName, { paths: [basePath] });
|
||||
return resolvedPath;
|
||||
} catch {
|
||||
}
|
||||
}
|
||||
throw new Error(`Cannot find module ${moduleName}`);
|
||||
};
|
||||
var getCommitLintModuleType = async () => {
|
||||
const packageFile = "@commitlint/load/package.json";
|
||||
const packageJsonPath = findModulePath(packageFile);
|
||||
const packageFile = "node_modules/@commitlint/load/package.json";
|
||||
const packageJsonPath = import_path3.default.join(
|
||||
process.env.PWD || process.cwd(),
|
||||
packageFile
|
||||
);
|
||||
const packageJson = JSON.parse(await import_promises.default.readFile(packageJsonPath, "utf8"));
|
||||
if (!packageJson) {
|
||||
throw new Error(`Failed to parse ${packageFile}`);
|
||||
@@ -61429,15 +61413,21 @@ var getCommitLintModuleType = async () => {
|
||||
return packageJson.type === "module" ? "esm" : "cjs";
|
||||
};
|
||||
var getCommitLintPWDConfig = async () => {
|
||||
let load, modulePath;
|
||||
let load, nodeModulesPath;
|
||||
switch (await getCommitLintModuleType()) {
|
||||
case "cjs":
|
||||
modulePath = findModulePath("@commitlint/load");
|
||||
load = require(modulePath).default;
|
||||
nodeModulesPath = import_path3.default.join(
|
||||
process.env.PWD || process.cwd(),
|
||||
"node_modules/@commitlint/load"
|
||||
);
|
||||
load = require(nodeModulesPath).default;
|
||||
break;
|
||||
case "esm":
|
||||
modulePath = await findModulePath("@commitlint/load/lib/load.js");
|
||||
load = (await import(modulePath)).default;
|
||||
nodeModulesPath = import_path3.default.join(
|
||||
process.env.PWD || process.cwd(),
|
||||
"node_modules/@commitlint/load/lib/load.js"
|
||||
);
|
||||
load = (await import(nodeModulesPath)).default;
|
||||
break;
|
||||
}
|
||||
if (load && typeof load === "function") {
|
||||
|
||||
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "opencommit",
|
||||
"version": "3.1.2",
|
||||
"version": "3.0.20",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "opencommit",
|
||||
"version": "3.1.2",
|
||||
"version": "3.0.20",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.10.0",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "opencommit",
|
||||
"version": "3.1.2",
|
||||
"version": "3.1.0",
|
||||
"description": "Auto-generate impressive commits in 1 second. Killing lame commits with AI 🤯🔫",
|
||||
"keywords": [
|
||||
"git",
|
||||
|
||||
@@ -23,7 +23,7 @@ export const commitlintConfigCommand = command(
|
||||
if (mode === CONFIG_MODES.get) {
|
||||
const commitLintConfig = await getCommitlintLLMConfig();
|
||||
|
||||
outro(JSON.stringify(commitLintConfig, null, 2));
|
||||
outro(commitLintConfig.toString());
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -23,7 +23,6 @@ export enum CONFIG_KEYS {
|
||||
OCO_EMOJI = 'OCO_EMOJI',
|
||||
OCO_MODEL = 'OCO_MODEL',
|
||||
OCO_LANGUAGE = 'OCO_LANGUAGE',
|
||||
OCO_WHY = 'OCO_WHY',
|
||||
OCO_MESSAGE_TEMPLATE_PLACEHOLDER = 'OCO_MESSAGE_TEMPLATE_PLACEHOLDER',
|
||||
OCO_PROMPT_MODULE = 'OCO_PROMPT_MODULE',
|
||||
OCO_AI_PROVIDER = 'OCO_AI_PROVIDER',
|
||||
@@ -377,7 +376,6 @@ export type ConfigType = {
|
||||
[CONFIG_KEYS.OCO_OPENAI_BASE_PATH]?: string;
|
||||
[CONFIG_KEYS.OCO_DESCRIPTION]: boolean;
|
||||
[CONFIG_KEYS.OCO_EMOJI]: boolean;
|
||||
[CONFIG_KEYS.OCO_WHY]: boolean;
|
||||
[CONFIG_KEYS.OCO_MODEL]: string;
|
||||
[CONFIG_KEYS.OCO_LANGUAGE]: string;
|
||||
[CONFIG_KEYS.OCO_MESSAGE_TEMPLATE_PLACEHOLDER]: string;
|
||||
@@ -437,7 +435,6 @@ export const DEFAULT_CONFIG = {
|
||||
OCO_ONE_LINE_COMMIT: false,
|
||||
OCO_TEST_MOCK_TYPE: 'commit-message',
|
||||
OCO_FLOWISE_ENDPOINT: ':',
|
||||
OCO_WHY: false,
|
||||
OCO_GITPUSH: true // todo: deprecate
|
||||
};
|
||||
|
||||
|
||||
@@ -28,10 +28,7 @@ export class OllamaAi implements AiEngine {
|
||||
stream: false
|
||||
};
|
||||
try {
|
||||
const response = await this.client.post(
|
||||
this.client.getUri(this.config),
|
||||
params
|
||||
);
|
||||
const response = await this.client.post('', params);
|
||||
|
||||
const message = response.data.message;
|
||||
|
||||
|
||||
@@ -258,9 +258,7 @@ const INIT_MAIN_PROMPT = (
|
||||
prompts: string[]
|
||||
): OpenAI.Chat.Completions.ChatCompletionMessageParam => ({
|
||||
role: 'system',
|
||||
content: `${IDENTITY} Your mission is to create clean and comprehensive commit messages in the given @commitlint convention and explain WHAT were the changes ${
|
||||
config.OCO_WHY ? 'and WHY the changes were done' : ''
|
||||
}. I'll send you an output of 'git diff --staged' command, and you convert it into a commit message.
|
||||
content: `${IDENTITY} Your mission is to create clean and comprehensive commit messages in the given @commitlint convention and explain WHAT were the changes and WHY the changes were done. I'll send you an output of 'git diff --staged' command, and you convert it into a commit message.
|
||||
${
|
||||
config.OCO_EMOJI
|
||||
? 'Use GitMoji convention to preface the commit.'
|
||||
|
||||
@@ -1,29 +1,13 @@
|
||||
import fs from 'fs/promises';
|
||||
import path from 'path';
|
||||
|
||||
const findModulePath = (moduleName: string) => {
|
||||
const searchPaths = [
|
||||
path.join('node_modules', moduleName),
|
||||
path.join('node_modules', '.pnpm')
|
||||
];
|
||||
|
||||
for (const basePath of searchPaths) {
|
||||
try {
|
||||
const resolvedPath = require.resolve(moduleName, { paths: [basePath] });
|
||||
return resolvedPath;
|
||||
} catch {
|
||||
// Continue to the next search path if the module is not found
|
||||
}
|
||||
}
|
||||
|
||||
throw new Error(`Cannot find module ${moduleName}`);
|
||||
};
|
||||
|
||||
const getCommitLintModuleType = async (): Promise<'cjs' | 'esm'> => {
|
||||
const packageFile = '@commitlint/load/package.json';
|
||||
const packageJsonPath = findModulePath(packageFile);
|
||||
const packageFile = 'node_modules/@commitlint/load/package.json';
|
||||
const packageJsonPath = path.join(
|
||||
process.env.PWD || process.cwd(),
|
||||
packageFile,
|
||||
);
|
||||
const packageJson = JSON.parse(await fs.readFile(packageJsonPath, 'utf8'));
|
||||
|
||||
if (!packageJson) {
|
||||
throw new Error(`Failed to parse ${packageFile}`);
|
||||
}
|
||||
@@ -35,7 +19,7 @@ const getCommitLintModuleType = async (): Promise<'cjs' | 'esm'> => {
|
||||
* QualifiedConfig from any version of @commitlint/types
|
||||
* @see https://github.com/conventional-changelog/commitlint/blob/master/@commitlint/types/src/load.ts
|
||||
*/
|
||||
type QualifiedConfigOnAnyVersion = { [key: string]: unknown };
|
||||
type QualifiedConfigOnAnyVersion = { [key:string]: unknown };
|
||||
|
||||
/**
|
||||
* This code is loading the configuration for the `@commitlint` package from the current working
|
||||
@@ -43,31 +27,36 @@ type QualifiedConfigOnAnyVersion = { [key: string]: unknown };
|
||||
*
|
||||
* @returns
|
||||
*/
|
||||
export const getCommitLintPWDConfig =
|
||||
async (): Promise<QualifiedConfigOnAnyVersion | null> => {
|
||||
let load: Function, modulePath: string;
|
||||
switch (await getCommitLintModuleType()) {
|
||||
case 'cjs':
|
||||
/**
|
||||
* CommonJS (<= commitlint@v18.x.x.)
|
||||
*/
|
||||
modulePath = findModulePath('@commitlint/load');
|
||||
load = require(modulePath).default;
|
||||
break;
|
||||
case 'esm':
|
||||
/**
|
||||
* ES Module (commitlint@v19.x.x. <= )
|
||||
* Directory import is not supported in ES Module resolution, so import the file directly
|
||||
*/
|
||||
modulePath = await findModulePath('@commitlint/load/lib/load.js');
|
||||
load = (await import(modulePath)).default;
|
||||
break;
|
||||
}
|
||||
export const getCommitLintPWDConfig = async (): Promise<QualifiedConfigOnAnyVersion | null> => {
|
||||
let load, nodeModulesPath;
|
||||
switch (await getCommitLintModuleType()) {
|
||||
case 'cjs':
|
||||
/**
|
||||
* CommonJS (<= commitlint@v18.x.x.)
|
||||
*/
|
||||
nodeModulesPath = path.join(
|
||||
process.env.PWD || process.cwd(),
|
||||
'node_modules/@commitlint/load',
|
||||
);
|
||||
load = require(nodeModulesPath).default;
|
||||
break;
|
||||
case 'esm':
|
||||
/**
|
||||
* ES Module (commitlint@v19.x.x. <= )
|
||||
* Directory import is not supported in ES Module resolution, so import the file directly
|
||||
*/
|
||||
nodeModulesPath = path.join(
|
||||
process.env.PWD || process.cwd(),
|
||||
'node_modules/@commitlint/load/lib/load.js',
|
||||
);
|
||||
load = (await import(nodeModulesPath)).default;
|
||||
break;
|
||||
}
|
||||
|
||||
if (load && typeof load === 'function') {
|
||||
return await load();
|
||||
}
|
||||
if (load && typeof load === 'function') {
|
||||
return await load();
|
||||
}
|
||||
|
||||
// @commitlint/load is not a function
|
||||
return null;
|
||||
};
|
||||
// @commitlint/load is not a function
|
||||
return null;
|
||||
};
|
||||
|
||||
@@ -181,7 +181,9 @@ describe('cli flow to generate commit message using @commitlint prompt-module',
|
||||
[],
|
||||
{ cwd: gitDir }
|
||||
);
|
||||
expect(await commitlintGet.findByText('consistency')).toBeInTheConsole();
|
||||
expect(
|
||||
await commitlintGet.findByText('[object Object]')
|
||||
).toBeInTheConsole();
|
||||
|
||||
// Run 'oco' using .opencommit-commitlint
|
||||
await render('echo', [`'console.log("Hello World");' > index.ts`], {
|
||||
|
||||
Reference in New Issue
Block a user