From 25074a6c5e729cbacdd955da4212fd4068d368c5 Mon Sep 17 00:00:00 2001 From: Sanson Thomas Date: Thu, 4 Jan 2024 14:53:46 +0000 Subject: [PATCH 1/3] =?UTF-8?q?feat(config.ts,=20prompts.ts):=20=E2=9C=A8?= =?UTF-8?q?=20add=20OCO=5FEMOJI=5FPOSITION=5FBEFORE=5FDESCRIPTION=20config?= =?UTF-8?q?=20key=20and=20implement=20its=20usage=20in=20prompts=20The=20n?= =?UTF-8?q?ew=20configuration=20key=20OCO=5FEMOJI=5FPOSITION=5FBEFORE=5FDE?= =?UTF-8?q?SCRIPTION=20has=20been=20added=20to=20allow=20users=20to=20spec?= =?UTF-8?q?ify=20the=20position=20of=20the=20GitMoji=20in=20the=20commit?= =?UTF-8?q?=20message.=20This=20provides=20flexibility=20for=20users=20who?= =?UTF-8?q?=20may=20have=20different=20preferences=20for=20the=20placement?= =?UTF-8?q?=20of=20the=20GitMoji.=20The=20prompts=20have=20been=20updated?= =?UTF-8?q?=20to=20reflect=20this=20new=20configuration=20option=20and=20w?= =?UTF-8?q?ill=20now=20generate=20commit=20messages=20according=20to=20the?= =?UTF-8?q?=20user's=20preference.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- out/cli.cjs | 20 ++++++++++++++------ out/github-action.cjs | 20 ++++++++++++++------ package-lock.json | 4 ++-- src/commands/config.ts | 15 +++++++++++++++ src/prompts.ts | 23 ++++++++++++++++++++--- 5 files changed, 65 insertions(+), 17 deletions(-) diff --git a/out/cli.cjs b/out/cli.cjs index b35a11ab..3f577615 100755 --- a/out/cli.cjs +++ b/out/cli.cjs @@ -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) { diff --git a/out/github-action.cjs b/out/github-action.cjs index 4e3b0ab2..03c4dca1 100644 --- a/out/github-action.cjs +++ b/out/github-action.cjs @@ -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) { diff --git a/package-lock.json b/package-lock.json index 1c9e0536..d65b18ee 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "opencommit", - "version": "2.4.2", + "version": "3.0.4", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "opencommit", - "version": "2.4.2", + "version": "3.0.4", "license": "MIT", "dependencies": { "@actions/core": "^1.10.0", diff --git a/src/commands/config.ts b/src/commands/config.ts index 106940f9..0322d7c3 100644 --- a/src/commands/config.ts +++ b/src/commands/config.ts @@ -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: diff --git a/src/prompts.ts b/src/prompts.ts index 243ee86f..8814e7e5 100644 --- a/src/prompts.ts +++ b/src/prompts.ts @@ -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< From db0b0ae4685c14f261c6c1be778bd11ab384da93 Mon Sep 17 00:00:00 2001 From: Sanson Thomas Date: Thu, 29 Feb 2024 10:51:12 +0000 Subject: [PATCH 2/3] build --- out/cli.cjs | 9 +++++++++ out/github-action.cjs | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/out/cli.cjs b/out/cli.cjs index e0c69dc6..8d24a2ed 100755 --- a/out/cli.cjs +++ b/out/cli.cjs @@ -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 */, @@ -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", diff --git a/out/github-action.cjs b/out/github-action.cjs index 818052ef..a4c4fc52 100644 --- a/out/github-action.cjs +++ b/out/github-action.cjs @@ -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 */, @@ -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", From 07165ca7f0a741c0ff376a7bca6d0b2530d8cd7c Mon Sep 17 00:00:00 2001 From: Sanson Thomas Date: Thu, 29 Feb 2024 11:00:59 +0000 Subject: [PATCH 3/3] docs(README.md): add instructions for configuring GitMoji position in commit messages This update provides users with the ability to customize the placement of GitMoji in their commit messages. It includes examples and command line instructions for setting the GitMoji position either before the description or at the start of the commit message. --- README.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/README.md b/README.md index 3302f11e..2ecbf975 100644 --- a/README.md +++ b/README.md @@ -81,6 +81,7 @@ OCO_OPENAI_MAX_TOKENS= OCO_OPENAI_BASE_PATH= OCO_DESCRIPTION= OCO_EMOJI= +OCO_EMOJI_POSITION_BEFORE_DESCRIPTION= OCO_MODEL= OCO_LANGUAGE= OCO_MESSAGE_TEMPLATE_PLACEHOLDER= @@ -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. @@ -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