build
This commit is contained in:
+39
-27
@@ -22064,14 +22064,19 @@ var configureCommitlintIntegration = async (force = false) => {
|
|||||||
spin.stop(`Done - please review contents of ${COMMITLINT_LLM_CONFIG_PATH}`);
|
spin.stop(`Done - please review contents of ${COMMITLINT_LLM_CONFIG_PATH}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// src/utils/removeConventionalCommitWord.ts
|
||||||
|
function removeConventionalCommitWord(message) {
|
||||||
|
return message.replace(/^(fix|feat)\((.+?)\):/, "($2):");
|
||||||
|
}
|
||||||
|
|
||||||
// src/prompts.ts
|
// src/prompts.ts
|
||||||
var config5 = getConfig();
|
var config5 = getConfig();
|
||||||
var translation3 = i18n[config5?.OCO_LANGUAGE || "en"];
|
var translation3 = i18n[config5?.OCO_LANGUAGE || "en"];
|
||||||
var IDENTITY = "You are to act as the author of a commit message in git.";
|
var IDENTITY = "You are to act as the author of a commit message in git.";
|
||||||
var INIT_MAIN_PROMPT2 = (language) => ({
|
var INIT_MAIN_PROMPT2 = (language, fullGitMojiSpec) => ({
|
||||||
role: import_openai3.ChatCompletionRequestMessageRoleEnum.System,
|
role: import_openai3.ChatCompletionRequestMessageRoleEnum.System,
|
||||||
content: `${IDENTITY} Your mission is to create clean and comprehensive commit messages as per the conventional commit convention and explain WHAT were the changes and mainly WHY the changes were done. I'll send you an output of 'git diff --staged' command, and you are to convert it into a commit message.
|
content: `${IDENTITY} Your mission is to create clean and comprehensive commit messages as per the ${fullGitMojiSpec ? "GitMoji specification" : "conventional commit convention"} and explain WHAT were the changes and mainly WHY the changes were done. I'll send you an output of 'git diff --staged' command, and you are to convert it into a commit message.
|
||||||
${config5?.OCO_EMOJI ? "Use GitMoji convention to preface the commit." : "Do not preface the commit with anything."}
|
${config5?.OCO_EMOJI ? `Use GitMoji convention to preface the commit. Here are some help to choose the right emoji (emoji, description): \u{1F41B}, Fix a bug; \u2728, Introduce new features; \u{1F4DD}, Add or update documentation; \u{1F680}, Deploy stuff; \u2705, Add, update, or pass tests; \u267B\uFE0F, Refactor code; \u2B06\uFE0F, Upgrade dependencies; \u{1F527}, Add or update configuration files; \u{1F310}, Internationalization and localization; \u{1F4A1}, Add or update comments in source code; ${fullGitMojiSpec ? "\u{1F3A8}, Improve structure / format of the code; \u26A1\uFE0F, Improve performance; \u{1F525}, Remove code or files; \u{1F691}\uFE0F, Critical hotfix; \u{1F484}, Add or update the UI and style files; \u{1F389}, Begin a project; \u{1F512}\uFE0F, Fix security issues; \u{1F510}, Add or update secrets; \u{1F516}, Release / Version tags; \u{1F6A8}, Fix compiler / linter warnings; \u{1F6A7}, Work in progress; \u{1F49A}, Fix CI Build; \u2B07\uFE0F, Downgrade dependencies; \u{1F4CC}, Pin dependencies to specific versions; \u{1F477}, Add or update CI build system; \u{1F4C8}, Add or update analytics or track code; \u2795, Add a dependency; \u2796, Remove a dependency; \u{1F528}, Add or update development scripts; \u270F\uFE0F, Fix typos; \u{1F4A9}, Write bad code that needs to be improved; \u23EA\uFE0F, Revert changes; \u{1F500}, Merge branches; \u{1F4E6}\uFE0F, Add or update compiled files or packages; \u{1F47D}\uFE0F, Update code due to external API changes; \u{1F69A}, Move or rename resources (e.g.: files, paths, routes); \u{1F4C4}, Add or update license; \u{1F4A5}, Introduce breaking changes; \u{1F371}, Add or update assets; \u267F\uFE0F, Improve accessibility; \u{1F37B}, Write code drunkenly; \u{1F4AC}, Add or update text and literals; \u{1F5C3}\uFE0F, Perform database related changes; \u{1F50A}, Add or update logs; \u{1F507}, Remove logs; \u{1F465}, Add or update contributor(s); \u{1F6B8}, Improve user experience / usability; \u{1F3D7}\uFE0F, Make architectural changes; \u{1F4F1}, Work on responsive design; \u{1F921}, Mock things; \u{1F95A}, Add or update an easter egg; \u{1F648}, Add or update a .gitignore file; \u{1F4F8}, Add or update snapshots; \u2697\uFE0F, Perform experiments; \u{1F50D}\uFE0F, Improve SEO; \u{1F3F7}\uFE0F, Add or update types; \u{1F331}, Add or update seed files; \u{1F6A9}, Add, update, or remove feature flags; \u{1F945}, Catch errors; \u{1F4AB}, Add or update animations and transitions; \u{1F5D1}\uFE0F, Deprecate code that needs to be cleaned up; \u{1F6C2}, Work on code related to authorization, roles and permissions; \u{1FA79}, Simple fix for a non-critical issue; \u{1F9D0}, Data exploration/inspection; \u26B0\uFE0F, Remove dead code; \u{1F9EA}, Add a failing test; \u{1F454}, Add or update business logic; \u{1FA7A}, Add or update healthcheck; \u{1F9F1}, Infrastructure related changes; \u{1F9D1}\u200D\u{1F4BB}, Improve developer experience; \u{1F4B8}, Add sponsorships or money related infrastructure; \u{1F9F5}, Add or update code related to multithreading or concurrency; \u{1F9BA}, Add or update code related to validation." : ""}` : "Do not preface the commit with anything. Conventional commit keywords:fix, feat, build, chore, ci, docs, style, refactor, perf, test."}
|
||||||
${config5?.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."}
|
${config5?.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. Lines must not be longer than 74 characters. Use ${language} for the commit message.`
|
Use the present tense. Lines must not be longer than 74 characters. Use ${language} for the commit message.`
|
||||||
});
|
});
|
||||||
@@ -22104,11 +22109,11 @@ var INIT_DIFF_PROMPT = {
|
|||||||
};
|
};
|
||||||
var INIT_CONSISTENCY_PROMPT = (translation4) => ({
|
var INIT_CONSISTENCY_PROMPT = (translation4) => ({
|
||||||
role: import_openai3.ChatCompletionRequestMessageRoleEnum.Assistant,
|
role: import_openai3.ChatCompletionRequestMessageRoleEnum.Assistant,
|
||||||
content: `${config5?.OCO_EMOJI ? "\u{1F41B} " : ""}${translation4.commitFix}
|
content: `${config5?.OCO_EMOJI ? `\u{1F41B} ${removeConventionalCommitWord(translation4.commitFix)}` : translation4.commitFix}
|
||||||
${config5?.OCO_EMOJI ? "\u2728 " : ""}${translation4.commitFeat}
|
${config5?.OCO_EMOJI ? `\u2728 ${removeConventionalCommitWord(translation4.commitFeat)}` : translation4.commitFeat}
|
||||||
${config5?.OCO_DESCRIPTION ? translation4.commitDescription : ""}`
|
${config5?.OCO_DESCRIPTION ? translation4.commitDescription : ""}`
|
||||||
});
|
});
|
||||||
var getMainCommitPrompt = async () => {
|
var getMainCommitPrompt = async (fullGitMojiSpec) => {
|
||||||
switch (config5?.OCO_PROMPT_MODULE) {
|
switch (config5?.OCO_PROMPT_MODULE) {
|
||||||
case "@commitlint":
|
case "@commitlint":
|
||||||
if (!await commitlintLLMConfigExists()) {
|
if (!await commitlintLLMConfigExists()) {
|
||||||
@@ -22130,7 +22135,7 @@ var getMainCommitPrompt = async () => {
|
|||||||
];
|
];
|
||||||
default:
|
default:
|
||||||
return [
|
return [
|
||||||
INIT_MAIN_PROMPT2(translation3.localLanguage),
|
INIT_MAIN_PROMPT2(translation3.localLanguage, fullGitMojiSpec),
|
||||||
INIT_DIFF_PROMPT,
|
INIT_DIFF_PROMPT,
|
||||||
INIT_CONSISTENCY_PROMPT(translation3)
|
INIT_CONSISTENCY_PROMPT(translation3)
|
||||||
];
|
];
|
||||||
@@ -22157,8 +22162,8 @@ function mergeDiffs(arr, maxStringLength) {
|
|||||||
var config6 = getConfig();
|
var config6 = getConfig();
|
||||||
var MAX_TOKENS_INPUT2 = config6?.OCO_TOKENS_MAX_INPUT || 4096 /* DEFAULT_MAX_TOKENS_INPUT */;
|
var MAX_TOKENS_INPUT2 = config6?.OCO_TOKENS_MAX_INPUT || 4096 /* DEFAULT_MAX_TOKENS_INPUT */;
|
||||||
var MAX_TOKENS_OUTPUT2 = config6?.OCO_TOKENS_MAX_OUTPUT || 500 /* DEFAULT_MAX_TOKENS_OUTPUT */;
|
var MAX_TOKENS_OUTPUT2 = config6?.OCO_TOKENS_MAX_OUTPUT || 500 /* DEFAULT_MAX_TOKENS_OUTPUT */;
|
||||||
var generateCommitMessageChatCompletionPrompt = async (diff) => {
|
var generateCommitMessageChatCompletionPrompt = async (diff, fullGitMojiSpec) => {
|
||||||
const INIT_MESSAGES_PROMPT = await getMainCommitPrompt();
|
const INIT_MESSAGES_PROMPT = await getMainCommitPrompt(fullGitMojiSpec);
|
||||||
const chatContextAsCompletionRequest = [...INIT_MESSAGES_PROMPT];
|
const chatContextAsCompletionRequest = [...INIT_MESSAGES_PROMPT];
|
||||||
chatContextAsCompletionRequest.push({
|
chatContextAsCompletionRequest.push({
|
||||||
role: import_openai4.ChatCompletionRequestMessageRoleEnum.User,
|
role: import_openai4.ChatCompletionRequestMessageRoleEnum.User,
|
||||||
@@ -22174,9 +22179,9 @@ var GenerateCommitMessageErrorEnum = ((GenerateCommitMessageErrorEnum2) => {
|
|||||||
return GenerateCommitMessageErrorEnum2;
|
return GenerateCommitMessageErrorEnum2;
|
||||||
})(GenerateCommitMessageErrorEnum || {});
|
})(GenerateCommitMessageErrorEnum || {});
|
||||||
var ADJUSTMENT_FACTOR = 20;
|
var ADJUSTMENT_FACTOR = 20;
|
||||||
var generateCommitMessageByDiff = async (diff) => {
|
var generateCommitMessageByDiff = async (diff, fullGitMojiSpec) => {
|
||||||
try {
|
try {
|
||||||
const INIT_MESSAGES_PROMPT = await getMainCommitPrompt();
|
const INIT_MESSAGES_PROMPT = await getMainCommitPrompt(fullGitMojiSpec);
|
||||||
const INIT_MESSAGES_PROMPT_LENGTH = INIT_MESSAGES_PROMPT.map(
|
const INIT_MESSAGES_PROMPT_LENGTH = INIT_MESSAGES_PROMPT.map(
|
||||||
(msg) => tokenCount(msg.content) + 4
|
(msg) => tokenCount(msg.content) + 4
|
||||||
).reduce((a2, b6) => a2 + b6, 0);
|
).reduce((a2, b6) => a2 + b6, 0);
|
||||||
@@ -22184,7 +22189,8 @@ var generateCommitMessageByDiff = async (diff) => {
|
|||||||
if (tokenCount(diff) >= MAX_REQUEST_TOKENS) {
|
if (tokenCount(diff) >= MAX_REQUEST_TOKENS) {
|
||||||
const commitMessagePromises = await getCommitMsgsPromisesFromFileDiffs(
|
const commitMessagePromises = await getCommitMsgsPromisesFromFileDiffs(
|
||||||
diff,
|
diff,
|
||||||
MAX_REQUEST_TOKENS
|
MAX_REQUEST_TOKENS,
|
||||||
|
fullGitMojiSpec
|
||||||
);
|
);
|
||||||
const commitMessages = [];
|
const commitMessages = [];
|
||||||
for (const promise of commitMessagePromises) {
|
for (const promise of commitMessagePromises) {
|
||||||
@@ -22193,7 +22199,7 @@ var generateCommitMessageByDiff = async (diff) => {
|
|||||||
}
|
}
|
||||||
return commitMessages.join("\n\n");
|
return commitMessages.join("\n\n");
|
||||||
}
|
}
|
||||||
const messages = await generateCommitMessageChatCompletionPrompt(diff);
|
const messages = await generateCommitMessageChatCompletionPrompt(diff, fullGitMojiSpec);
|
||||||
const engine = getEngine();
|
const engine = getEngine();
|
||||||
const commitMessage = await engine.generateCommitMessage(messages);
|
const commitMessage = await engine.generateCommitMessage(messages);
|
||||||
if (!commitMessage)
|
if (!commitMessage)
|
||||||
@@ -22203,7 +22209,7 @@ var generateCommitMessageByDiff = async (diff) => {
|
|||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
function getMessagesPromisesByChangesInFile(fileDiff, separator, maxChangeLength) {
|
function getMessagesPromisesByChangesInFile(fileDiff, separator, maxChangeLength, fullGitMojiSpec) {
|
||||||
const hunkHeaderSeparator = "@@ ";
|
const hunkHeaderSeparator = "@@ ";
|
||||||
const [fileHeader, ...fileDiffByLines] = fileDiff.split(hunkHeaderSeparator);
|
const [fileHeader, ...fileDiffByLines] = fileDiff.split(hunkHeaderSeparator);
|
||||||
const mergedChanges = mergeDiffs(
|
const mergedChanges = mergeDiffs(
|
||||||
@@ -22224,7 +22230,8 @@ function getMessagesPromisesByChangesInFile(fileDiff, separator, maxChangeLength
|
|||||||
const commitMsgsFromFileLineDiffs = lineDiffsWithHeader.map(
|
const commitMsgsFromFileLineDiffs = lineDiffsWithHeader.map(
|
||||||
async (lineDiff) => {
|
async (lineDiff) => {
|
||||||
const messages = await generateCommitMessageChatCompletionPrompt(
|
const messages = await generateCommitMessageChatCompletionPrompt(
|
||||||
separator + lineDiff
|
separator + lineDiff,
|
||||||
|
fullGitMojiSpec
|
||||||
);
|
);
|
||||||
return engine.generateCommitMessage(messages);
|
return engine.generateCommitMessage(messages);
|
||||||
}
|
}
|
||||||
@@ -22256,7 +22263,7 @@ function splitDiff(diff, maxChangeLength) {
|
|||||||
}
|
}
|
||||||
return splitDiffs;
|
return splitDiffs;
|
||||||
}
|
}
|
||||||
var getCommitMsgsPromisesFromFileDiffs = async (diff, maxDiffLength) => {
|
var getCommitMsgsPromisesFromFileDiffs = async (diff, maxDiffLength, fullGitMojiSpec) => {
|
||||||
const separator = "diff --git ";
|
const separator = "diff --git ";
|
||||||
const diffByFiles = diff.split(separator).slice(1);
|
const diffByFiles = diff.split(separator).slice(1);
|
||||||
const mergedFilesDiffs = mergeDiffs(diffByFiles, maxDiffLength);
|
const mergedFilesDiffs = mergeDiffs(diffByFiles, maxDiffLength);
|
||||||
@@ -22266,12 +22273,14 @@ var getCommitMsgsPromisesFromFileDiffs = async (diff, maxDiffLength) => {
|
|||||||
const messagesPromises = getMessagesPromisesByChangesInFile(
|
const messagesPromises = getMessagesPromisesByChangesInFile(
|
||||||
fileDiff,
|
fileDiff,
|
||||||
separator,
|
separator,
|
||||||
maxDiffLength
|
maxDiffLength,
|
||||||
|
fullGitMojiSpec
|
||||||
);
|
);
|
||||||
commitMessagePromises.push(...messagesPromises);
|
commitMessagePromises.push(...messagesPromises);
|
||||||
} else {
|
} else {
|
||||||
const messages = await generateCommitMessageChatCompletionPrompt(
|
const messages = await generateCommitMessageChatCompletionPrompt(
|
||||||
separator + fileDiff
|
separator + fileDiff,
|
||||||
|
fullGitMojiSpec
|
||||||
);
|
);
|
||||||
const engine = getEngine();
|
const engine = getEngine();
|
||||||
commitMessagePromises.push(engine.generateCommitMessage(messages));
|
commitMessagePromises.push(engine.generateCommitMessage(messages));
|
||||||
@@ -22393,12 +22402,12 @@ var checkMessageTemplate = (extraArgs2) => {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
var generateCommitMessageFromGitDiff = async (diff, extraArgs2) => {
|
var generateCommitMessageFromGitDiff = async (diff, extraArgs2, fullGitMojiSpec) => {
|
||||||
await assertGitRepo();
|
await assertGitRepo();
|
||||||
const commitSpinner = le();
|
const commitSpinner = le();
|
||||||
commitSpinner.start("Generating the commit message");
|
commitSpinner.start("Generating the commit message");
|
||||||
try {
|
try {
|
||||||
let commitMessage = await generateCommitMessageByDiff(diff);
|
let commitMessage = await generateCommitMessageByDiff(diff, fullGitMojiSpec);
|
||||||
const messageTemplate = checkMessageTemplate(extraArgs2);
|
const messageTemplate = checkMessageTemplate(extraArgs2);
|
||||||
if (config7?.OCO_MESSAGE_TEMPLATE_PLACEHOLDER && typeof messageTemplate === "string") {
|
if (config7?.OCO_MESSAGE_TEMPLATE_PLACEHOLDER && typeof messageTemplate === "string") {
|
||||||
commitMessage = messageTemplate.replace(
|
commitMessage = messageTemplate.replace(
|
||||||
@@ -22480,7 +22489,7 @@ ${source_default.grey("\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2
|
|||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
async function commit(extraArgs2 = [], isStageAllFlag = false) {
|
async function commit(extraArgs2 = [], fullGitMojiSpec = false, isStageAllFlag = false) {
|
||||||
if (isStageAllFlag) {
|
if (isStageAllFlag) {
|
||||||
const changedFiles2 = await getChangedFiles();
|
const changedFiles2 = await getChangedFiles();
|
||||||
if (changedFiles2)
|
if (changedFiles2)
|
||||||
@@ -22509,7 +22518,7 @@ async function commit(extraArgs2 = [], isStageAllFlag = false) {
|
|||||||
message: "Do you want to stage all files and generate commit message?"
|
message: "Do you want to stage all files and generate commit message?"
|
||||||
});
|
});
|
||||||
if (isStageAllAndCommitConfirmedByUser && !eD2(isStageAllAndCommitConfirmedByUser)) {
|
if (isStageAllAndCommitConfirmedByUser && !eD2(isStageAllAndCommitConfirmedByUser)) {
|
||||||
await commit(extraArgs2, true);
|
await commit(extraArgs2, true, fullGitMojiSpec);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
if (stagedFiles.length === 0 && changedFiles.length > 0) {
|
if (stagedFiles.length === 0 && changedFiles.length > 0) {
|
||||||
@@ -22524,7 +22533,7 @@ async function commit(extraArgs2 = [], isStageAllFlag = false) {
|
|||||||
process.exit(1);
|
process.exit(1);
|
||||||
await gitAdd({ files });
|
await gitAdd({ files });
|
||||||
}
|
}
|
||||||
await commit(extraArgs2, false);
|
await commit(extraArgs2, false, fullGitMojiSpec);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
stagedFilesSpinner.stop(
|
stagedFilesSpinner.stop(
|
||||||
@@ -22534,7 +22543,8 @@ ${stagedFiles.map((file) => ` ${file}`).join("\n")}`
|
|||||||
const [, generateCommitError] = await trytm(
|
const [, generateCommitError] = await trytm(
|
||||||
generateCommitMessageFromGitDiff(
|
generateCommitMessageFromGitDiff(
|
||||||
await getDiff({ files: stagedFiles }),
|
await getDiff({ files: stagedFiles }),
|
||||||
extraArgs2
|
extraArgs2,
|
||||||
|
fullGitMojiSpec
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
if (generateCommitError) {
|
if (generateCommitError) {
|
||||||
@@ -22740,16 +22750,18 @@ Z2(
|
|||||||
version: package_default.version,
|
version: package_default.version,
|
||||||
name: "opencommit",
|
name: "opencommit",
|
||||||
commands: [configCommand, hookCommand, commitlintConfigCommand],
|
commands: [configCommand, hookCommand, commitlintConfigCommand],
|
||||||
flags: {},
|
flags: {
|
||||||
|
fgm: Boolean
|
||||||
|
},
|
||||||
ignoreArgv: (type) => type === "unknown-flag" || type === "argument",
|
ignoreArgv: (type) => type === "unknown-flag" || type === "argument",
|
||||||
help: { description: package_default.description }
|
help: { description: package_default.description }
|
||||||
},
|
},
|
||||||
async () => {
|
async ({ flags }) => {
|
||||||
await checkIsLatestVersion();
|
await checkIsLatestVersion();
|
||||||
if (await isHookCalled()) {
|
if (await isHookCalled()) {
|
||||||
prepareCommitMessageHook();
|
prepareCommitMessageHook();
|
||||||
} else {
|
} else {
|
||||||
commit(extraArgs);
|
commit(extraArgs, flags.fgm);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
extraArgs
|
extraArgs
|
||||||
|
|||||||
+27
-18
@@ -27559,14 +27559,19 @@ var configureCommitlintIntegration = async (force = false) => {
|
|||||||
spin.stop(`Done - please review contents of ${COMMITLINT_LLM_CONFIG_PATH}`);
|
spin.stop(`Done - please review contents of ${COMMITLINT_LLM_CONFIG_PATH}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// src/utils/removeConventionalCommitWord.ts
|
||||||
|
function removeConventionalCommitWord(message) {
|
||||||
|
return message.replace(/^(fix|feat)\((.+?)\):/, "($2):");
|
||||||
|
}
|
||||||
|
|
||||||
// src/prompts.ts
|
// src/prompts.ts
|
||||||
var config5 = getConfig();
|
var config5 = getConfig();
|
||||||
var translation3 = i18n[config5?.OCO_LANGUAGE || "en"];
|
var translation3 = i18n[config5?.OCO_LANGUAGE || "en"];
|
||||||
var IDENTITY = "You are to act as the author of a commit message in git.";
|
var IDENTITY = "You are to act as the author of a commit message in git.";
|
||||||
var INIT_MAIN_PROMPT2 = (language) => ({
|
var INIT_MAIN_PROMPT2 = (language, fullGitMojiSpec) => ({
|
||||||
role: import_openai3.ChatCompletionRequestMessageRoleEnum.System,
|
role: import_openai3.ChatCompletionRequestMessageRoleEnum.System,
|
||||||
content: `${IDENTITY} Your mission is to create clean and comprehensive commit messages as per the conventional commit convention and explain WHAT were the changes and mainly WHY the changes were done. I'll send you an output of 'git diff --staged' command, and you are to convert it into a commit message.
|
content: `${IDENTITY} Your mission is to create clean and comprehensive commit messages as per the ${fullGitMojiSpec ? "GitMoji specification" : "conventional commit convention"} and explain WHAT were the changes and mainly WHY the changes were done. I'll send you an output of 'git diff --staged' command, and you are to convert it into a commit message.
|
||||||
${config5?.OCO_EMOJI ? "Use GitMoji convention to preface the commit." : "Do not preface the commit with anything."}
|
${config5?.OCO_EMOJI ? `Use GitMoji convention to preface the commit. Here are some help to choose the right emoji (emoji, description): \u{1F41B}, Fix a bug; \u2728, Introduce new features; \u{1F4DD}, Add or update documentation; \u{1F680}, Deploy stuff; \u2705, Add, update, or pass tests; \u267B\uFE0F, Refactor code; \u2B06\uFE0F, Upgrade dependencies; \u{1F527}, Add or update configuration files; \u{1F310}, Internationalization and localization; \u{1F4A1}, Add or update comments in source code; ${fullGitMojiSpec ? "\u{1F3A8}, Improve structure / format of the code; \u26A1\uFE0F, Improve performance; \u{1F525}, Remove code or files; \u{1F691}\uFE0F, Critical hotfix; \u{1F484}, Add or update the UI and style files; \u{1F389}, Begin a project; \u{1F512}\uFE0F, Fix security issues; \u{1F510}, Add or update secrets; \u{1F516}, Release / Version tags; \u{1F6A8}, Fix compiler / linter warnings; \u{1F6A7}, Work in progress; \u{1F49A}, Fix CI Build; \u2B07\uFE0F, Downgrade dependencies; \u{1F4CC}, Pin dependencies to specific versions; \u{1F477}, Add or update CI build system; \u{1F4C8}, Add or update analytics or track code; \u2795, Add a dependency; \u2796, Remove a dependency; \u{1F528}, Add or update development scripts; \u270F\uFE0F, Fix typos; \u{1F4A9}, Write bad code that needs to be improved; \u23EA\uFE0F, Revert changes; \u{1F500}, Merge branches; \u{1F4E6}\uFE0F, Add or update compiled files or packages; \u{1F47D}\uFE0F, Update code due to external API changes; \u{1F69A}, Move or rename resources (e.g.: files, paths, routes); \u{1F4C4}, Add or update license; \u{1F4A5}, Introduce breaking changes; \u{1F371}, Add or update assets; \u267F\uFE0F, Improve accessibility; \u{1F37B}, Write code drunkenly; \u{1F4AC}, Add or update text and literals; \u{1F5C3}\uFE0F, Perform database related changes; \u{1F50A}, Add or update logs; \u{1F507}, Remove logs; \u{1F465}, Add or update contributor(s); \u{1F6B8}, Improve user experience / usability; \u{1F3D7}\uFE0F, Make architectural changes; \u{1F4F1}, Work on responsive design; \u{1F921}, Mock things; \u{1F95A}, Add or update an easter egg; \u{1F648}, Add or update a .gitignore file; \u{1F4F8}, Add or update snapshots; \u2697\uFE0F, Perform experiments; \u{1F50D}\uFE0F, Improve SEO; \u{1F3F7}\uFE0F, Add or update types; \u{1F331}, Add or update seed files; \u{1F6A9}, Add, update, or remove feature flags; \u{1F945}, Catch errors; \u{1F4AB}, Add or update animations and transitions; \u{1F5D1}\uFE0F, Deprecate code that needs to be cleaned up; \u{1F6C2}, Work on code related to authorization, roles and permissions; \u{1FA79}, Simple fix for a non-critical issue; \u{1F9D0}, Data exploration/inspection; \u26B0\uFE0F, Remove dead code; \u{1F9EA}, Add a failing test; \u{1F454}, Add or update business logic; \u{1FA7A}, Add or update healthcheck; \u{1F9F1}, Infrastructure related changes; \u{1F9D1}\u200D\u{1F4BB}, Improve developer experience; \u{1F4B8}, Add sponsorships or money related infrastructure; \u{1F9F5}, Add or update code related to multithreading or concurrency; \u{1F9BA}, Add or update code related to validation." : ""}` : "Do not preface the commit with anything. Conventional commit keywords:fix, feat, build, chore, ci, docs, style, refactor, perf, test."}
|
||||||
${config5?.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."}
|
${config5?.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. Lines must not be longer than 74 characters. Use ${language} for the commit message.`
|
Use the present tense. Lines must not be longer than 74 characters. Use ${language} for the commit message.`
|
||||||
});
|
});
|
||||||
@@ -27599,11 +27604,11 @@ var INIT_DIFF_PROMPT = {
|
|||||||
};
|
};
|
||||||
var INIT_CONSISTENCY_PROMPT = (translation4) => ({
|
var INIT_CONSISTENCY_PROMPT = (translation4) => ({
|
||||||
role: import_openai3.ChatCompletionRequestMessageRoleEnum.Assistant,
|
role: import_openai3.ChatCompletionRequestMessageRoleEnum.Assistant,
|
||||||
content: `${config5?.OCO_EMOJI ? "\u{1F41B} " : ""}${translation4.commitFix}
|
content: `${config5?.OCO_EMOJI ? `\u{1F41B} ${removeConventionalCommitWord(translation4.commitFix)}` : translation4.commitFix}
|
||||||
${config5?.OCO_EMOJI ? "\u2728 " : ""}${translation4.commitFeat}
|
${config5?.OCO_EMOJI ? `\u2728 ${removeConventionalCommitWord(translation4.commitFeat)}` : translation4.commitFeat}
|
||||||
${config5?.OCO_DESCRIPTION ? translation4.commitDescription : ""}`
|
${config5?.OCO_DESCRIPTION ? translation4.commitDescription : ""}`
|
||||||
});
|
});
|
||||||
var getMainCommitPrompt = async () => {
|
var getMainCommitPrompt = async (fullGitMojiSpec) => {
|
||||||
switch (config5?.OCO_PROMPT_MODULE) {
|
switch (config5?.OCO_PROMPT_MODULE) {
|
||||||
case "@commitlint":
|
case "@commitlint":
|
||||||
if (!await commitlintLLMConfigExists()) {
|
if (!await commitlintLLMConfigExists()) {
|
||||||
@@ -27625,7 +27630,7 @@ var getMainCommitPrompt = async () => {
|
|||||||
];
|
];
|
||||||
default:
|
default:
|
||||||
return [
|
return [
|
||||||
INIT_MAIN_PROMPT2(translation3.localLanguage),
|
INIT_MAIN_PROMPT2(translation3.localLanguage, fullGitMojiSpec),
|
||||||
INIT_DIFF_PROMPT,
|
INIT_DIFF_PROMPT,
|
||||||
INIT_CONSISTENCY_PROMPT(translation3)
|
INIT_CONSISTENCY_PROMPT(translation3)
|
||||||
];
|
];
|
||||||
@@ -27652,8 +27657,8 @@ function mergeDiffs(arr, maxStringLength) {
|
|||||||
var config6 = getConfig();
|
var config6 = getConfig();
|
||||||
var MAX_TOKENS_INPUT2 = config6?.OCO_TOKENS_MAX_INPUT || 4096 /* DEFAULT_MAX_TOKENS_INPUT */;
|
var MAX_TOKENS_INPUT2 = config6?.OCO_TOKENS_MAX_INPUT || 4096 /* DEFAULT_MAX_TOKENS_INPUT */;
|
||||||
var MAX_TOKENS_OUTPUT2 = config6?.OCO_TOKENS_MAX_OUTPUT || 500 /* DEFAULT_MAX_TOKENS_OUTPUT */;
|
var MAX_TOKENS_OUTPUT2 = config6?.OCO_TOKENS_MAX_OUTPUT || 500 /* DEFAULT_MAX_TOKENS_OUTPUT */;
|
||||||
var generateCommitMessageChatCompletionPrompt = async (diff) => {
|
var generateCommitMessageChatCompletionPrompt = async (diff, fullGitMojiSpec) => {
|
||||||
const INIT_MESSAGES_PROMPT = await getMainCommitPrompt();
|
const INIT_MESSAGES_PROMPT = await getMainCommitPrompt(fullGitMojiSpec);
|
||||||
const chatContextAsCompletionRequest = [...INIT_MESSAGES_PROMPT];
|
const chatContextAsCompletionRequest = [...INIT_MESSAGES_PROMPT];
|
||||||
chatContextAsCompletionRequest.push({
|
chatContextAsCompletionRequest.push({
|
||||||
role: import_openai4.ChatCompletionRequestMessageRoleEnum.User,
|
role: import_openai4.ChatCompletionRequestMessageRoleEnum.User,
|
||||||
@@ -27669,9 +27674,9 @@ var GenerateCommitMessageErrorEnum = ((GenerateCommitMessageErrorEnum2) => {
|
|||||||
return GenerateCommitMessageErrorEnum2;
|
return GenerateCommitMessageErrorEnum2;
|
||||||
})(GenerateCommitMessageErrorEnum || {});
|
})(GenerateCommitMessageErrorEnum || {});
|
||||||
var ADJUSTMENT_FACTOR = 20;
|
var ADJUSTMENT_FACTOR = 20;
|
||||||
var generateCommitMessageByDiff = async (diff) => {
|
var generateCommitMessageByDiff = async (diff, fullGitMojiSpec) => {
|
||||||
try {
|
try {
|
||||||
const INIT_MESSAGES_PROMPT = await getMainCommitPrompt();
|
const INIT_MESSAGES_PROMPT = await getMainCommitPrompt(fullGitMojiSpec);
|
||||||
const INIT_MESSAGES_PROMPT_LENGTH = INIT_MESSAGES_PROMPT.map(
|
const INIT_MESSAGES_PROMPT_LENGTH = INIT_MESSAGES_PROMPT.map(
|
||||||
(msg) => tokenCount(msg.content) + 4
|
(msg) => tokenCount(msg.content) + 4
|
||||||
).reduce((a2, b2) => a2 + b2, 0);
|
).reduce((a2, b2) => a2 + b2, 0);
|
||||||
@@ -27679,7 +27684,8 @@ var generateCommitMessageByDiff = async (diff) => {
|
|||||||
if (tokenCount(diff) >= MAX_REQUEST_TOKENS) {
|
if (tokenCount(diff) >= MAX_REQUEST_TOKENS) {
|
||||||
const commitMessagePromises = await getCommitMsgsPromisesFromFileDiffs(
|
const commitMessagePromises = await getCommitMsgsPromisesFromFileDiffs(
|
||||||
diff,
|
diff,
|
||||||
MAX_REQUEST_TOKENS
|
MAX_REQUEST_TOKENS,
|
||||||
|
fullGitMojiSpec
|
||||||
);
|
);
|
||||||
const commitMessages = [];
|
const commitMessages = [];
|
||||||
for (const promise of commitMessagePromises) {
|
for (const promise of commitMessagePromises) {
|
||||||
@@ -27688,7 +27694,7 @@ var generateCommitMessageByDiff = async (diff) => {
|
|||||||
}
|
}
|
||||||
return commitMessages.join("\n\n");
|
return commitMessages.join("\n\n");
|
||||||
}
|
}
|
||||||
const messages = await generateCommitMessageChatCompletionPrompt(diff);
|
const messages = await generateCommitMessageChatCompletionPrompt(diff, fullGitMojiSpec);
|
||||||
const engine = getEngine();
|
const engine = getEngine();
|
||||||
const commitMessage = await engine.generateCommitMessage(messages);
|
const commitMessage = await engine.generateCommitMessage(messages);
|
||||||
if (!commitMessage)
|
if (!commitMessage)
|
||||||
@@ -27698,7 +27704,7 @@ var generateCommitMessageByDiff = async (diff) => {
|
|||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
function getMessagesPromisesByChangesInFile(fileDiff, separator, maxChangeLength) {
|
function getMessagesPromisesByChangesInFile(fileDiff, separator, maxChangeLength, fullGitMojiSpec) {
|
||||||
const hunkHeaderSeparator = "@@ ";
|
const hunkHeaderSeparator = "@@ ";
|
||||||
const [fileHeader, ...fileDiffByLines] = fileDiff.split(hunkHeaderSeparator);
|
const [fileHeader, ...fileDiffByLines] = fileDiff.split(hunkHeaderSeparator);
|
||||||
const mergedChanges = mergeDiffs(
|
const mergedChanges = mergeDiffs(
|
||||||
@@ -27719,7 +27725,8 @@ function getMessagesPromisesByChangesInFile(fileDiff, separator, maxChangeLength
|
|||||||
const commitMsgsFromFileLineDiffs = lineDiffsWithHeader.map(
|
const commitMsgsFromFileLineDiffs = lineDiffsWithHeader.map(
|
||||||
async (lineDiff) => {
|
async (lineDiff) => {
|
||||||
const messages = await generateCommitMessageChatCompletionPrompt(
|
const messages = await generateCommitMessageChatCompletionPrompt(
|
||||||
separator + lineDiff
|
separator + lineDiff,
|
||||||
|
fullGitMojiSpec
|
||||||
);
|
);
|
||||||
return engine.generateCommitMessage(messages);
|
return engine.generateCommitMessage(messages);
|
||||||
}
|
}
|
||||||
@@ -27751,7 +27758,7 @@ function splitDiff(diff, maxChangeLength) {
|
|||||||
}
|
}
|
||||||
return splitDiffs;
|
return splitDiffs;
|
||||||
}
|
}
|
||||||
var getCommitMsgsPromisesFromFileDiffs = async (diff, maxDiffLength) => {
|
var getCommitMsgsPromisesFromFileDiffs = async (diff, maxDiffLength, fullGitMojiSpec) => {
|
||||||
const separator = "diff --git ";
|
const separator = "diff --git ";
|
||||||
const diffByFiles = diff.split(separator).slice(1);
|
const diffByFiles = diff.split(separator).slice(1);
|
||||||
const mergedFilesDiffs = mergeDiffs(diffByFiles, maxDiffLength);
|
const mergedFilesDiffs = mergeDiffs(diffByFiles, maxDiffLength);
|
||||||
@@ -27761,12 +27768,14 @@ var getCommitMsgsPromisesFromFileDiffs = async (diff, maxDiffLength) => {
|
|||||||
const messagesPromises = getMessagesPromisesByChangesInFile(
|
const messagesPromises = getMessagesPromisesByChangesInFile(
|
||||||
fileDiff,
|
fileDiff,
|
||||||
separator,
|
separator,
|
||||||
maxDiffLength
|
maxDiffLength,
|
||||||
|
fullGitMojiSpec
|
||||||
);
|
);
|
||||||
commitMessagePromises.push(...messagesPromises);
|
commitMessagePromises.push(...messagesPromises);
|
||||||
} else {
|
} else {
|
||||||
const messages = await generateCommitMessageChatCompletionPrompt(
|
const messages = await generateCommitMessageChatCompletionPrompt(
|
||||||
separator + fileDiff
|
separator + fileDiff,
|
||||||
|
fullGitMojiSpec
|
||||||
);
|
);
|
||||||
const engine = getEngine();
|
const engine = getEngine();
|
||||||
commitMessagePromises.push(engine.generateCommitMessage(messages));
|
commitMessagePromises.push(engine.generateCommitMessage(messages));
|
||||||
|
|||||||
Reference in New Issue
Block a user