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: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ OCO_OPENAI_MAX_TOKENS=<max response tokens from OpenAI API>
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_EMOJI_POSITION_BEFORE_DESCRIPTION=<boolean, add GitMoji before description>
OCO_MODEL=<either 'gpt-4', 'gpt-3.5-turbo-16k' (default), 'gpt-3.5-turbo-0613' or 'gpt-3.5-turbo'>
OCO_LANGUAGE=<locale, scroll to the bottom to see options>
OCO_MESSAGE_TEMPLATE_PLACEHOLDER=<message template placeholder, default: '$msg'>
Expand Down Expand Up @@ -109,6 +110,23 @@ To remove preface emojis:
oco config set OCO_EMOJI=false
```

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".


```sh
oco config set OCO_EMOJI_POSITION_BEFORE_DESCRIPTION=true
```


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".


```sh
oco config set OCO_EMOJI_POSITION_BEFORE_DESCRIPTION=false
```

### Switch to GPT-4 or other models

By default, OpenCommit uses `gpt-3.5-turbo-16k` model.
Expand Down Expand Up @@ -333,6 +351,7 @@ jobs:
OCO_OPENAI_BASE_PATH: ''
OCO_DESCRIPTION: false
OCO_EMOJI: false
OCO_EMOJI_POSITION_BEFORE_DESCRIPTION: false
OCO_MODEL: gpt-3.5-turbo-16k
OCO_LANGUAGE: en
OCO_PROMPT_MODULE: conventional-commit
Expand Down
16 changes: 13 additions & 3 deletions out/cli.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -18706,6 +18706,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 */,
Expand Down Expand Up @@ -18773,6 +18781,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",
Expand Down Expand Up @@ -22045,6 +22054,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.`
});
Expand Down Expand Up @@ -22077,9 +22087,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) {
Expand Down
16 changes: 13 additions & 3 deletions out/github-action.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -24201,6 +24201,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 */,
Expand Down Expand Up @@ -24268,6 +24276,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",
Expand Down Expand Up @@ -27540,6 +27549,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.`
});
Expand Down Expand Up @@ -27572,9 +27582,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) {
Expand Down
15 changes: 15 additions & 0 deletions src/commands/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -104,6 +105,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,
Expand Down Expand Up @@ -184,6 +195,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:
Expand Down
23 changes: 20 additions & 3 deletions src/prompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.'
Expand Down Expand Up @@ -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<
Expand Down