Skip to content

Commit 5136271

Browse files
author
octo-patch
committed
fix: handle missing prompts in commitlint config and OCO_ONE_LINE_COMMIT for split diffs
1 parent 695edf7 commit 5136271

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/generateCommitMessageFromGitDiff.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,15 @@ export const generateCommitMessageByDiff = async (
168168

169169
const commitMessages = await Promise.all(commitMessagePromises);
170170

171+
// When OCO_ONE_LINE_COMMIT is enabled, combine the first line of each
172+
// split-diff message into a single line instead of joining with '\n\n'.
173+
if (config.OCO_ONE_LINE_COMMIT) {
174+
return commitMessages
175+
.filter(Boolean)
176+
.map((msg) => msg!.split('\n')[0].trim())
177+
.join('; ');
178+
}
179+
171180
return commitMessages.join('\n\n');
172181
}
173182

src/prompts.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,17 @@ export const getMainCommitPrompt = async (
240240
}
241241

242242
// Replace example prompt with a prompt that's generated by OpenAI for the commitlint config.
243-
const commitLintConfig = await utils.getCommitlintLLMConfig();
243+
let commitLintConfig = await utils.getCommitlintLLMConfig();
244+
245+
// Guard against outdated or corrupted config files that are missing the
246+
// prompts field (e.g. generated by an older version of opencommit).
247+
if (!Array.isArray(commitLintConfig.prompts)) {
248+
note(
249+
'Commitlint LLM config is missing prompts, regenerating...'
250+
);
251+
await configureCommitlintIntegration(true);
252+
commitLintConfig = await utils.getCommitlintLLMConfig();
253+
}
244254

245255
return [
246256
commitlintPrompts.INIT_MAIN_PROMPT(

0 commit comments

Comments
 (0)