From 45dc2c45352b99ee9118a0362a115d6e1dba86ae Mon Sep 17 00:00:00 2001 From: Mouadh HSOUMI Date: Sat, 9 Mar 2024 05:44:12 +0100 Subject: [PATCH] feat: add OCO_ONE_LINE_COMMIT config for enabling one line commit message (#307) --- README.md | 1 + src/commands/config.ts | 14 +++++++++++++- src/modules/commitlint/prompts.ts | 1 + src/prompts.ts | 5 +++++ 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 02e3516..4f0ff37 100644 --- a/README.md +++ b/README.md @@ -101,6 +101,7 @@ OCO_MODEL= OCO_MESSAGE_TEMPLATE_PLACEHOLDER= OCO_PROMPT_MODULE= +OCO_ONE_LINE_COMMIT= ``` ### Global config for all repos diff --git a/src/commands/config.ts b/src/commands/config.ts index 21e4062..9bc2e3e 100644 --- a/src/commands/config.ts +++ b/src/commands/config.ts @@ -25,6 +25,7 @@ export enum CONFIG_KEYS { OCO_MESSAGE_TEMPLATE_PLACEHOLDER = 'OCO_MESSAGE_TEMPLATE_PLACEHOLDER', OCO_PROMPT_MODULE = 'OCO_PROMPT_MODULE', OCO_AI_PROVIDER = 'OCO_AI_PROVIDER', + OCO_ONE_LINE_COMMIT = 'OCO_ONE_LINE_COMMIT' } export enum CONFIG_MODES { @@ -195,6 +196,16 @@ export const configValidators = { ); return value; }, + + [CONFIG_KEYS.OCO_ONE_LINE_COMMIT](value: any) { + validateConfig( + CONFIG_KEYS.OCO_ONE_LINE_COMMIT, + typeof value === 'boolean', + 'Must be true or false' + ); + + return value; + }, }; export type ConfigType = { @@ -220,7 +231,8 @@ export const getConfig = (): ConfigType | null => { OCO_MESSAGE_TEMPLATE_PLACEHOLDER: process.env.OCO_MESSAGE_TEMPLATE_PLACEHOLDER || '$msg', OCO_PROMPT_MODULE: process.env.OCO_PROMPT_MODULE || 'conventional-commit', - OCO_AI_PROVIDER: process.env.OCO_AI_PROVIDER || 'openai' + OCO_AI_PROVIDER: process.env.OCO_AI_PROVIDER || 'openai', + OCO_ONE_LINE_COMMIT: process.env.OCO_ONE_LINE_COMMIT === 'true' ? true : false }; const configExists = existsSync(configPath); diff --git a/src/modules/commitlint/prompts.ts b/src/modules/commitlint/prompts.ts index f69de36..b172790 100644 --- a/src/modules/commitlint/prompts.ts +++ b/src/modules/commitlint/prompts.ts @@ -267,6 +267,7 @@ const INIT_MAIN_PROMPT = ( ${config?.OCO_EMOJI ? 'Use GitMoji convention to preface the commit.' : 'Do not preface the commit with anything.'} ${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.' : "Don't add any descriptions to the commit, only commit message."} Use the present tense. Use ${language} to answer. +${ config?.OCO_ONE_LINE_COMMIT ? 'Craft a concise commit message that encapsulates all changes made, with an emphasis on the primary updates. If the modifications share a common theme or scope, mention it succinctly; otherwise, leave the scope out to maintain focus. The goal is to provide a clear and unified overview of the changes in a one single message, without diverging into a list of commit per file change.' : ""} You will strictly follow the following conventions to generate the content of the commit message: - ${prompts.join('\n- ')} diff --git a/src/prompts.ts b/src/prompts.ts index f2d35fc..74f5913 100644 --- a/src/prompts.ts +++ b/src/prompts.ts @@ -115,6 +115,11 @@ const INIT_MAIN_PROMPT = ( ? '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." } + ${ + config?.OCO_ONE_LINE_COMMIT + ? 'Craft a concise commit message that encapsulates all changes made, with an emphasis on the primary updates. If the modifications share a common theme or scope, mention it succinctly; otherwise, leave the scope out to maintain focus. The goal is to provide a clear and unified overview of the changes in a one single message, without diverging into a list of commit per file change.' + : "" + } Use the present tense. Lines must not be longer than 74 characters. Use ${language} for the commit message.` });