From 0727329a8bc30a51cc97ea929a45d55519779fa1 Mon Sep 17 00:00:00 2001 From: Jethro Yu Date: Thu, 30 Oct 2025 11:39:59 +0800 Subject: [PATCH] fixing(commitlint): add translation parameter to consistency prompt function Add a translation parameter to the GEN_COMMITLINT_CONSISTENCY_PROMPT function to support localization of commit messages. This change enhances the flexibility of the commitlint integration by allowing prompts to be generated in different languages, improving usability for non-English speakers. --- src/modules/commitlint/config.ts | 2 +- src/modules/commitlint/prompts.ts | 21 ++++++++++++--------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/modules/commitlint/config.ts b/src/modules/commitlint/config.ts index 96a6f162..d77456a8 100644 --- a/src/modules/commitlint/config.ts +++ b/src/modules/commitlint/config.ts @@ -56,7 +56,7 @@ export const configureCommitlintIntegration = async (force = false) => { const prompts = inferPromptsFromCommitlintConfig(commitLintConfig as any); const consistencyPrompts = - commitlintPrompts.GEN_COMMITLINT_CONSISTENCY_PROMPT(prompts); + commitlintPrompts.GEN_COMMITLINT_CONSISTENCY_PROMPT(prompts, translation); // debug prompt which will generate a consistency // await fs.writeFile( diff --git a/src/modules/commitlint/prompts.ts b/src/modules/commitlint/prompts.ts index 127838fc..79d40bb6 100644 --- a/src/modules/commitlint/prompts.ts +++ b/src/modules/commitlint/prompts.ts @@ -12,9 +12,9 @@ import { import { getConfig } from '../../commands/config'; import { i18n, I18nLocals } from '../../i18n'; import { IDENTITY, INIT_DIFF_PROMPT } from '../../prompts'; +import { ConsistencyPrompt } from './types'; const config = getConfig(); -const translation = i18n[(config.OCO_LANGUAGE as I18nLocals) || 'en']; type DeepPartial = { [P in keyof T]?: { @@ -214,7 +214,8 @@ const STRUCTURE_OF_COMMIT = config.OCO_OMIT_SCOPE // Prompt to generate LLM-readable rules based on @commitlint rules. const GEN_COMMITLINT_CONSISTENCY_PROMPT = ( - prompts: string[] + prompts: string[], + translation: ConsistencyPrompt ): OpenAI.Chat.Completions.ChatCompletionMessageParam[] => [ { role: 'system', @@ -233,15 +234,17 @@ Commit Message Conventions: - ${prompts.join('\n- ')} JSON Output Format: -- The JSON output should contain the commit messages for a bug fix and a new feature in the following format: +- You MUST write all commit messages and descriptions in ${ + translation.localLanguage + } and output them in the following JSON format. Use the exact language and writing style as shown in the example: \`\`\`json { - "localLanguage": "${translation.localLanguage}", - "commitFix": "
", - "commitFeat": "
", - "commitFixOmitScope": "
", - "commitFeatOmitScope": "
", - "commitDescription": "" + "localLanguage": ${JSON.stringify(translation.localLanguage)}, + "commitFix": ${JSON.stringify(translation.commitFix)}, + "commitFeat": ${JSON.stringify(translation.commitFeat)}, + "commitFixOmitScope": ${JSON.stringify(translation.commitFixOmitScope)}, + "commitFeatOmitScope": ${JSON.stringify(translation.commitFeatOmitScope)}, + "commitDescription": ${JSON.stringify(translation.commitDescription)} } \`\`\` - The "commitDescription" should not include the commit message's header, only the description.