Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ✨ add OCO_EMOJI_POSITION_BEFORE_DESCRIPTION #288

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat(config.ts, prompts.ts): ✨ add OCO_EMOJI_POSITION_BEFORE_DESCRIPT…
…ION config key and implement its usage in prompts

The new configuration key OCO_EMOJI_POSITION_BEFORE_DESCRIPTION has been added to allow users to specify the position of the GitMoji in the commit message. This provides flexibility for users who may have different preferences for the placement of the GitMoji. The prompts have been updated to reflect this new configuration option and will now generate commit messages according to the user's preference.
  • Loading branch information
ThomasSanson committed Jan 4, 2024
commit 25074a6c5e729cbacdd955da4212fd4068d368c5
20 changes: 14 additions & 6 deletions out/cli.cjs
Original file line number Diff line number Diff line change
@@ -21524,6 +21524,14 @@ var configValidators = {
);
return value;
},
["OCO_EMOJI_POSITION_BEFORE_DESCRIPTION" /* OCO_EMOJI_POSITION_BEFORE_DESCRIPTION */](value) {
validateConfig(
"OCO_EMOJI_POSITION_BEFORE_DESCRIPTION" /* OCO_EMOJI_POSITION_BEFORE_DESCRIPTION */,
typeof value === "boolean",
"Must be true or false"
);
return value;
},
["OCO_LANGUAGE" /* OCO_LANGUAGE */](value) {
validateConfig(
"OCO_LANGUAGE" /* OCO_LANGUAGE */,
@@ -21578,6 +21586,7 @@ var getConfig = () => {
OCO_OPENAI_BASE_PATH: process.env.OCO_OPENAI_BASE_PATH,
OCO_DESCRIPTION: process.env.OCO_DESCRIPTION === "true" ? true : false,
OCO_EMOJI: process.env.OCO_EMOJI === "true" ? true : false,
OCO_EMOJI_POSITION_BEFORE_DESCRIPTION: process.env.OCO_EMOJI_POSITION_BEFORE_DESCRIPTION === "true" ? true : false,
OCO_MODEL: process.env.OCO_MODEL || "gpt-3.5-turbo-16k",
OCO_LANGUAGE: process.env.OCO_LANGUAGE || "en",
OCO_MESSAGE_TEMPLATE_PLACEHOLDER: process.env.OCO_MESSAGE_TEMPLATE_PLACEHOLDER || "$msg",
@@ -21601,9 +21610,7 @@ var getConfig = () => {
);
config8[configKey] = validValue;
} catch (error) {
ce(
`'${configKey}' name is invalid, it should be either 'OCO_${configKey.toUpperCase()}' or it doesn't exist.`
);
ce(`Unknown '${configKey}' config option.`);
ce(
`Manually fix the '.env' file or global '~/.opencommit' config file.`
);
@@ -22000,6 +22007,7 @@ var INIT_MAIN_PROMPT2 = (language) => ({
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.
${config5?.OCO_EMOJI ? "Use GitMoji convention to preface the commit." : "Do not preface the commit with anything."}
${config5?.OCO_EMOJI_POSITION_BEFORE_DESCRIPTION ? 'The GitMoji should be placed immediately before the description in the commit message. For example: "chore(ansible-lint.yml): \u{1F527} remove yaml[line-length] from skip_list".' : 'The GitMoji should be placed at the start of the commit message. For example: "\u{1F527} chore(ansible-lint.yml): remove yaml[line-length] from skip_list".'}
${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.`
});
@@ -22032,9 +22040,9 @@ var INIT_DIFF_PROMPT = {
};
var INIT_CONSISTENCY_PROMPT = (translation4) => ({
role: import_openai3.ChatCompletionRequestMessageRoleEnum.Assistant,
content: `${config5?.OCO_EMOJI ? "\u{1F41B} " : ""}${translation4.commitFix}
${config5?.OCO_EMOJI ? "\u2728 " : ""}${translation4.commitFeat}
${config5?.OCO_DESCRIPTION ? translation4.commitDescription : ""}`
content: `${config5?.OCO_EMOJI ? config5?.OCO_EMOJI_POSITION_BEFORE_DESCRIPTION ? "fix(server.ts): \u{1F41B} " : "\u{1F41B} fix(server.ts): " : "fix(server.ts): "}${translation4.commitFix}
${config5?.OCO_EMOJI ? config5?.OCO_EMOJI_POSITION_BEFORE_DESCRIPTION ? "feat(server.ts): \u2728 " : "\u2728 feat(server.ts): " : "feat(server.ts): "}${translation4.commitFeat}
${config5?.OCO_DESCRIPTION ? translation4.commitDescription : ""}`
});
var getMainCommitPrompt = async () => {
switch (config5?.OCO_PROMPT_MODULE) {
20 changes: 14 additions & 6 deletions out/github-action.cjs
Original file line number Diff line number Diff line change
@@ -27946,6 +27946,14 @@ var configValidators = {
);
return value;
},
["OCO_EMOJI_POSITION_BEFORE_DESCRIPTION" /* OCO_EMOJI_POSITION_BEFORE_DESCRIPTION */](value) {
validateConfig(
"OCO_EMOJI_POSITION_BEFORE_DESCRIPTION" /* OCO_EMOJI_POSITION_BEFORE_DESCRIPTION */,
typeof value === "boolean",
"Must be true or false"
);
return value;
},
["OCO_LANGUAGE" /* OCO_LANGUAGE */](value) {
validateConfig(
"OCO_LANGUAGE" /* OCO_LANGUAGE */,
@@ -28000,6 +28008,7 @@ var getConfig = () => {
OCO_OPENAI_BASE_PATH: process.env.OCO_OPENAI_BASE_PATH,
OCO_DESCRIPTION: process.env.OCO_DESCRIPTION === "true" ? true : false,
OCO_EMOJI: process.env.OCO_EMOJI === "true" ? true : false,
OCO_EMOJI_POSITION_BEFORE_DESCRIPTION: process.env.OCO_EMOJI_POSITION_BEFORE_DESCRIPTION === "true" ? true : false,
OCO_MODEL: process.env.OCO_MODEL || "gpt-3.5-turbo-16k",
OCO_LANGUAGE: process.env.OCO_LANGUAGE || "en",
OCO_MESSAGE_TEMPLATE_PLACEHOLDER: process.env.OCO_MESSAGE_TEMPLATE_PLACEHOLDER || "$msg",
@@ -28023,9 +28032,7 @@ var getConfig = () => {
);
config7[configKey] = validValue;
} catch (error) {
ce(
`'${configKey}' name is invalid, it should be either 'OCO_${configKey.toUpperCase()}' or it doesn't exist.`
);
ce(`Unknown '${configKey}' config option.`);
ce(
`Manually fix the '.env' file or global '~/.opencommit' config file.`
);
@@ -28413,6 +28420,7 @@ var INIT_MAIN_PROMPT2 = (language) => ({
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.
${config5?.OCO_EMOJI ? "Use GitMoji convention to preface the commit." : "Do not preface the commit with anything."}
${config5?.OCO_EMOJI_POSITION_BEFORE_DESCRIPTION ? 'The GitMoji should be placed immediately before the description in the commit message. For example: "chore(ansible-lint.yml): \u{1F527} remove yaml[line-length] from skip_list".' : 'The GitMoji should be placed at the start of the commit message. For example: "\u{1F527} chore(ansible-lint.yml): remove yaml[line-length] from skip_list".'}
${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.`
});
@@ -28445,9 +28453,9 @@ var INIT_DIFF_PROMPT = {
};
var INIT_CONSISTENCY_PROMPT = (translation4) => ({
role: import_openai3.ChatCompletionRequestMessageRoleEnum.Assistant,
content: `${config5?.OCO_EMOJI ? "\u{1F41B} " : ""}${translation4.commitFix}
${config5?.OCO_EMOJI ? "\u2728 " : ""}${translation4.commitFeat}
${config5?.OCO_DESCRIPTION ? translation4.commitDescription : ""}`
content: `${config5?.OCO_EMOJI ? config5?.OCO_EMOJI_POSITION_BEFORE_DESCRIPTION ? "fix(server.ts): \u{1F41B} " : "\u{1F41B} fix(server.ts): " : "fix(server.ts): "}${translation4.commitFix}
${config5?.OCO_EMOJI ? config5?.OCO_EMOJI_POSITION_BEFORE_DESCRIPTION ? "feat(server.ts): \u2728 " : "\u2728 feat(server.ts): " : "feat(server.ts): "}${translation4.commitFeat}
${config5?.OCO_DESCRIPTION ? translation4.commitDescription : ""}`
});
var getMainCommitPrompt = async () => {
switch (config5?.OCO_PROMPT_MODULE) {
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions src/commands/config.ts
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@ export enum CONFIG_KEYS {
OCO_OPENAI_BASE_PATH = 'OCO_OPENAI_BASE_PATH',
OCO_DESCRIPTION = 'OCO_DESCRIPTION',
OCO_EMOJI = 'OCO_EMOJI',
OCO_EMOJI_POSITION_BEFORE_DESCRIPTION = 'OCO_EMOJI_POSITION_BEFORE_DESCRIPTION',
OCO_MODEL = 'OCO_MODEL',
OCO_LANGUAGE = 'OCO_LANGUAGE',
OCO_MESSAGE_TEMPLATE_PLACEHOLDER = 'OCO_MESSAGE_TEMPLATE_PLACEHOLDER',
@@ -102,6 +103,16 @@ export const configValidators = {
return value;
},

[CONFIG_KEYS.OCO_EMOJI_POSITION_BEFORE_DESCRIPTION](value: any) {
validateConfig(
CONFIG_KEYS.OCO_EMOJI_POSITION_BEFORE_DESCRIPTION,
typeof value === 'boolean',
'Must be true or false'
);

return value;
},

[CONFIG_KEYS.OCO_LANGUAGE](value: any) {
validateConfig(
CONFIG_KEYS.OCO_LANGUAGE,
@@ -168,6 +179,10 @@ export const getConfig = (): ConfigType | null => {
OCO_OPENAI_BASE_PATH: process.env.OCO_OPENAI_BASE_PATH,
OCO_DESCRIPTION: process.env.OCO_DESCRIPTION === 'true' ? true : false,
OCO_EMOJI: process.env.OCO_EMOJI === 'true' ? true : false,
OCO_EMOJI_POSITION_BEFORE_DESCRIPTION:
process.env.OCO_EMOJI_POSITION_BEFORE_DESCRIPTION === 'true'
? true
: false,
OCO_MODEL: process.env.OCO_MODEL || 'gpt-3.5-turbo-16k',
OCO_LANGUAGE: process.env.OCO_LANGUAGE || 'en',
OCO_MESSAGE_TEMPLATE_PLACEHOLDER:
23 changes: 20 additions & 3 deletions src/prompts.ts
Original file line number Diff line number Diff line change
@@ -26,6 +26,11 @@ const INIT_MAIN_PROMPT = (language: string): ChatCompletionRequestMessage => ({
? 'Use GitMoji convention to preface the commit.'
: 'Do not preface the commit with anything.'
}
${
config?.OCO_EMOJI_POSITION_BEFORE_DESCRIPTION
? 'The GitMoji should be placed immediately before the description in the commit message. For example: "chore(ansible-lint.yml): 🔧 remove yaml[line-length] from skip_list".'
: 'The GitMoji should be placed at the start of the commit message. For example: "🔧 chore(ansible-lint.yml): remove yaml[line-length] from skip_list".'
}
${
config?.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.'
@@ -66,9 +71,21 @@ const INIT_CONSISTENCY_PROMPT = (
translation: ConsistencyPrompt
): ChatCompletionRequestMessage => ({
role: ChatCompletionRequestMessageRoleEnum.Assistant,
content: `${config?.OCO_EMOJI ? '🐛 ' : ''}${translation.commitFix}
${config?.OCO_EMOJI ? '✨ ' : ''}${translation.commitFeat}
${config?.OCO_DESCRIPTION ? translation.commitDescription : ''}`
content: `${
config?.OCO_EMOJI
? config?.OCO_EMOJI_POSITION_BEFORE_DESCRIPTION
? 'fix(server.ts): 🐛 '
: '🐛 fix(server.ts): '
: 'fix(server.ts): '
}${translation.commitFix}
${
config?.OCO_EMOJI
? config?.OCO_EMOJI_POSITION_BEFORE_DESCRIPTION
? 'feat(server.ts): ✨ '
: '✨ feat(server.ts): '
: 'feat(server.ts): '
}${translation.commitFeat}
${config?.OCO_DESCRIPTION ? translation.commitDescription : ''}`
});

export const getMainCommitPrompt = async (): Promise<