Merge pull request #457 from jcppkkk/feat/commitlint-improve-consistency-handling

refactor(prompts): streamline commit message generation logic
This commit is contained in:
GPT8
2025-04-12 10:40:30 +03:00
committed by GitHub
+24 -22
View File
@@ -183,43 +183,45 @@ export const INIT_DIFF_PROMPT: OpenAI.Chat.Completions.ChatCompletionMessagePara
});` });`
}; };
const getContent = (translation: ConsistencyPrompt) => { const COMMIT_TYPES = {
const getCommitString = (commitWithScope: string, commitWithoutScope?: string) => { fix: '🐛',
if (config.OCO_OMIT_SCOPE && commitWithoutScope) { feat: '✨'
} as const;
const generateCommitString = (
type: keyof typeof COMMIT_TYPES,
message: string
): string => {
const cleanMessage = removeConventionalCommitWord(message);
return config.OCO_EMOJI return config.OCO_EMOJI
? `🐛 ${removeConventionalCommitWord(commitWithoutScope)}` ? `${COMMIT_TYPES[type]} ${cleanMessage}`
: commitWithoutScope; : message;
}
return config.OCO_EMOJI
? `🐛 ${removeConventionalCommitWord(commitWithScope)}`
: commitWithScope;
}; };
const fix = getCommitString( const getConsistencyContent = (translation: ConsistencyPrompt) => {
translation.commitFix, const fixMessage = config.OCO_OMIT_SCOPE && translation.commitFixOmitScope
translation.commitFixOmitScope ? translation.commitFixOmitScope
); : translation.commitFix;
const feat = config.OCO_OMIT_SCOPE && translation.commitFeatOmitScope const featMessage = config.OCO_OMIT_SCOPE && translation.commitFeatOmitScope
? (config.OCO_EMOJI ? translation.commitFeatOmitScope
? `${removeConventionalCommitWord(translation.commitFeatOmitScope)}` : translation.commitFeat;
: translation.commitFeatOmitScope)
: (config.OCO_EMOJI const fix = generateCommitString('fix', fixMessage);
? `${removeConventionalCommitWord(translation.commitFeat)}` const feat = generateCommitString('feat', featMessage);
: translation.commitFeat);
const description = config.OCO_DESCRIPTION const description = config.OCO_DESCRIPTION
? translation.commitDescription ? translation.commitDescription
: ''; : '';
return `${fix}\n${feat}\n${description}`; return [fix, feat, description].filter(Boolean).join('\n');
}; };
const INIT_CONSISTENCY_PROMPT = ( const INIT_CONSISTENCY_PROMPT = (
translation: ConsistencyPrompt translation: ConsistencyPrompt
): OpenAI.Chat.Completions.ChatCompletionMessageParam => ({ ): OpenAI.Chat.Completions.ChatCompletionMessageParam => ({
role: 'assistant', role: 'assistant',
content: getContent(translation) content: getConsistencyContent(translation)
}); });
export const getMainCommitPrompt = async ( export const getMainCommitPrompt = async (