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
+26 -24
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: '✨'
return config.OCO_EMOJI } as const;
? `🐛 ${removeConventionalCommitWord(commitWithoutScope)}`
: commitWithoutScope;
}
return config.OCO_EMOJI
? `🐛 ${removeConventionalCommitWord(commitWithScope)}`
: commitWithScope;
};
const fix = getCommitString( const generateCommitString = (
translation.commitFix, type: keyof typeof COMMIT_TYPES,
translation.commitFixOmitScope message: string
); ): string => {
const cleanMessage = removeConventionalCommitWord(message);
return config.OCO_EMOJI
? `${COMMIT_TYPES[type]} ${cleanMessage}`
: message;
};
const feat = config.OCO_OMIT_SCOPE && translation.commitFeatOmitScope const getConsistencyContent = (translation: ConsistencyPrompt) => {
? (config.OCO_EMOJI const fixMessage = config.OCO_OMIT_SCOPE && translation.commitFixOmitScope
? `${removeConventionalCommitWord(translation.commitFeatOmitScope)}` ? translation.commitFixOmitScope
: translation.commitFeatOmitScope) : translation.commitFix;
: (config.OCO_EMOJI
? `${removeConventionalCommitWord(translation.commitFeat)}` const featMessage = config.OCO_OMIT_SCOPE && translation.commitFeatOmitScope
: translation.commitFeat); ? translation.commitFeatOmitScope
: translation.commitFeat;
const fix = generateCommitString('fix', fixMessage);
const feat = generateCommitString('feat', featMessage);
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 (