From 51362711b2a11bf10b8b2acb3c394acf911c5b4a Mon Sep 17 00:00:00 2001 From: octo-patch Date: Mon, 20 Apr 2026 12:10:04 +0800 Subject: [PATCH 1/2] fix: handle missing prompts in commitlint config and OCO_ONE_LINE_COMMIT for split diffs --- src/generateCommitMessageFromGitDiff.ts | 9 +++++++++ src/prompts.ts | 12 +++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/generateCommitMessageFromGitDiff.ts b/src/generateCommitMessageFromGitDiff.ts index 01f04a67..f46d6e53 100644 --- a/src/generateCommitMessageFromGitDiff.ts +++ b/src/generateCommitMessageFromGitDiff.ts @@ -168,6 +168,15 @@ export const generateCommitMessageByDiff = async ( const commitMessages = await Promise.all(commitMessagePromises); + // When OCO_ONE_LINE_COMMIT is enabled, combine the first line of each + // split-diff message into a single line instead of joining with '\n\n'. + if (config.OCO_ONE_LINE_COMMIT) { + return commitMessages + .filter(Boolean) + .map((msg) => msg!.split('\n')[0].trim()) + .join('; '); + } + return commitMessages.join('\n\n'); } diff --git a/src/prompts.ts b/src/prompts.ts index 0f2f7281..9dd55ec0 100644 --- a/src/prompts.ts +++ b/src/prompts.ts @@ -240,7 +240,17 @@ export const getMainCommitPrompt = async ( } // Replace example prompt with a prompt that's generated by OpenAI for the commitlint config. - const commitLintConfig = await utils.getCommitlintLLMConfig(); + let commitLintConfig = await utils.getCommitlintLLMConfig(); + + // Guard against outdated or corrupted config files that are missing the + // prompts field (e.g. generated by an older version of opencommit). + if (!Array.isArray(commitLintConfig.prompts)) { + note( + 'Commitlint LLM config is missing prompts, regenerating...' + ); + await configureCommitlintIntegration(true); + commitLintConfig = await utils.getCommitlintLLMConfig(); + } return [ commitlintPrompts.INIT_MAIN_PROMPT( From c10f12ba20fb377fd8b7c9e9eb51e96984363e88 Mon Sep 17 00:00:00 2001 From: octo-patch Date: Wed, 22 Apr 2026 13:37:21 +0800 Subject: [PATCH 2/2] style: apply prettier formatting to prepare-commit-msg-hook and prompts Fixes the linux-tests CI failure on the format:check step. The lint and typecheck steps already pass; only prettier reported style issues in the two files touched by this PR. --- src/commands/prepare-commit-msg-hook.ts | 2 +- src/prompts.ts | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/commands/prepare-commit-msg-hook.ts b/src/commands/prepare-commit-msg-hook.ts index e1f7348b..561427d6 100644 --- a/src/commands/prepare-commit-msg-hook.ts +++ b/src/commands/prepare-commit-msg-hook.ts @@ -77,7 +77,7 @@ export const prepareCommitMessageHook = async ( const fileContent = await fs.readFile(messageFilePath); const commentedError = String(error).replace(new RegExp('^', 'gm'), '# '); - const message = `\n\n# ---------- [OpenCommit] ---------- #\n# Failed to generate the commit message.\n# To cancel the commit, just close this window without making any changes.\n\n${commentedError}\n\n${fileContent.toString()}` + const message = `\n\n# ---------- [OpenCommit] ---------- #\n# Failed to generate the commit message.\n# To cancel the commit, just close this window without making any changes.\n\n${commentedError}\n\n${fileContent.toString()}`; await fs.writeFile(messageFilePath, message); } catch (error) { diff --git a/src/prompts.ts b/src/prompts.ts index 9dd55ec0..d860a151 100644 --- a/src/prompts.ts +++ b/src/prompts.ts @@ -245,9 +245,7 @@ export const getMainCommitPrompt = async ( // Guard against outdated or corrupted config files that are missing the // prompts field (e.g. generated by an older version of opencommit). if (!Array.isArray(commitLintConfig.prompts)) { - note( - 'Commitlint LLM config is missing prompts, regenerating...' - ); + note('Commitlint LLM config is missing prompts, regenerating...'); await configureCommitlintIntegration(true); commitLintConfig = await utils.getCommitlintLLMConfig(); }