Skip to content

Commit

Permalink
♻️ リファクタ(prompts.ts): getContent関数をgetContentgetContentFixに分割しました
Browse files Browse the repository at this point in the history
`getContent`関数は、フィーチャーコミットメッセージの生成に特化し、`getContentFix`関数は、修正コミットメッセージの生成に特化しました。これにより、コードの可読性と保守性が向上し、各関数の責任が明確になりました。

♻️ Refactor(prompts.ts): Split `getContent` function into `getContent` and `getContentFix`

The `getContent` function is now specialized for generating feature commit messages, and the `getContentFix` function is specialized for generating fix commit messages. This improves code readability and maintainability, and clarifies the responsibilities of each function.
  • Loading branch information
takuya-o committed Jan 4, 2025
1 parent 96c6b3b commit 1ebbdc5
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 26 deletions.
38 changes: 31 additions & 7 deletions out/cli.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -68628,34 +68628,54 @@ var INIT_DIFF_PROMPT = {
};
var getContent = (translation3) => {
const config3 = getConfig();
const fix = config3.OCO_EMOJI ? `\u{1F41B} ${removeConventionalCommitWord(translation3.commitFix)}` : translation3.commitFix;
const feat = config3.OCO_EMOJI ? `\u2728 ${removeConventionalCommitWord(translation3.commitFeat)}` : translation3.commitFeat;
const description = config3.OCO_DESCRIPTION ? translation3.commitDescription : "";
let fixEn = "";
let featEn = "";
let descriptionEn = "";
if (translation3 !== i18n["en"]) {
featEn = config3.OCO_EMOJI ? `\u2728 ${removeConventionalCommitWord(i18n["en"].commitFeat)}

` : `${i18n["en"].commitFeat}

`;
descriptionEn = config3.OCO_DESCRIPTION ? `${i18n["en"].commitDescription}` : "";
}
return `${feat}

${description}${featEn}${descriptionEn}`;
};
var getContentFix = (translation3) => {
const config3 = getConfig();
const fix = config3.OCO_EMOJI ? `\u{1F41B} ${removeConventionalCommitWord(translation3.commitFix)}` : translation3.commitFix;
const description = config3.OCO_DESCRIPTION ? translation3.commitDescription : "";
let fixEn = "";
let descriptionEn = "";
if (translation3 !== i18n["en"]) {
fixEn = config3.OCO_EMOJI ? `

\u{1F41B} ${removeConventionalCommitWord(i18n["en"].commitFix)}

` : `

${i18n["en"].commitFix}
`;
featEn = config3.OCO_EMOJI ? `\u2728 ${removeConventionalCommitWord(i18n["en"].commitFeat)}
` : `${i18n["en"].commitFeat}

`;
descriptionEn = config3.OCO_DESCRIPTION ? `${i18n["en"].commitDescription}` : "";
}
return `${fix}
${feat}
${description}${fixEn}${featEn}${descriptionEn}`;

${description}${fixEn}${descriptionEn}`;
};
var INIT_CONSISTENCY_PROMPT = (translation3) => ({
role: "assistant",
//ChatCompletionRequestMessageRoleEnum.Assistant,
content: getContent(translation3)
});
var INIT_FIX_CONSISTENCY_PROMPT = (translation3) => ({
role: "assistant",
//ChatCompletionRequestMessageRoleEnum.Assistant,
content: getContentFix(translation3)
});
var getMainCommitPrompt = async (fullGitMojiSpec, context) => {
const config3 = getConfig();
switch (config3.OCO_PROMPT_MODULE) {
Expand All @@ -68673,6 +68693,9 @@ var getMainCommitPrompt = async (fullGitMojiSpec, context) => {
commitLintConfig.prompts
),
INIT_DIFF_PROMPT,
INIT_FIX_CONSISTENCY_PROMPT(
commitLintConfig.consistency[translation2.localLanguage]
),
INIT_CONSISTENCY_PROMPT(
commitLintConfig.consistency[translation2.localLanguage]
)
Expand All @@ -68681,6 +68704,7 @@ var getMainCommitPrompt = async (fullGitMojiSpec, context) => {
return [
INIT_MAIN_PROMPT(translation2.localLanguage, fullGitMojiSpec, context),
INIT_DIFF_PROMPT,
INIT_FIX_CONSISTENCY_PROMPT(translation2),
INIT_CONSISTENCY_PROMPT(translation2)
];
}
Expand Down
38 changes: 31 additions & 7 deletions out/github-action.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -82056,34 +82056,54 @@ var INIT_DIFF_PROMPT = {
};
var getContent = (translation3) => {
const config3 = getConfig();
const fix = config3.OCO_EMOJI ? `\u{1F41B} ${removeConventionalCommitWord(translation3.commitFix)}` : translation3.commitFix;
const feat = config3.OCO_EMOJI ? `\u2728 ${removeConventionalCommitWord(translation3.commitFeat)}` : translation3.commitFeat;
const description = config3.OCO_DESCRIPTION ? translation3.commitDescription : "";
let fixEn = "";
let featEn = "";
let descriptionEn = "";
if (translation3 !== i18n["en"]) {
featEn = config3.OCO_EMOJI ? `\u2728 ${removeConventionalCommitWord(i18n["en"].commitFeat)}

` : `${i18n["en"].commitFeat}

`;
descriptionEn = config3.OCO_DESCRIPTION ? `${i18n["en"].commitDescription}` : "";
}
return `${feat}

${description}${featEn}${descriptionEn}`;
};
var getContentFix = (translation3) => {
const config3 = getConfig();
const fix = config3.OCO_EMOJI ? `\u{1F41B} ${removeConventionalCommitWord(translation3.commitFix)}` : translation3.commitFix;
const description = config3.OCO_DESCRIPTION ? translation3.commitDescription : "";
let fixEn = "";
let descriptionEn = "";
if (translation3 !== i18n["en"]) {
fixEn = config3.OCO_EMOJI ? `

\u{1F41B} ${removeConventionalCommitWord(i18n["en"].commitFix)}

` : `

${i18n["en"].commitFix}
`;
featEn = config3.OCO_EMOJI ? `\u2728 ${removeConventionalCommitWord(i18n["en"].commitFeat)}
` : `${i18n["en"].commitFeat}

`;
descriptionEn = config3.OCO_DESCRIPTION ? `${i18n["en"].commitDescription}` : "";
}
return `${fix}
${feat}
${description}${fixEn}${featEn}${descriptionEn}`;

${description}${fixEn}${descriptionEn}`;
};
var INIT_CONSISTENCY_PROMPT = (translation3) => ({
role: "assistant",
//ChatCompletionRequestMessageRoleEnum.Assistant,
content: getContent(translation3)
});
var INIT_FIX_CONSISTENCY_PROMPT = (translation3) => ({
role: "assistant",
//ChatCompletionRequestMessageRoleEnum.Assistant,
content: getContentFix(translation3)
});
var getMainCommitPrompt = async (fullGitMojiSpec, context2) => {
const config3 = getConfig();
switch (config3.OCO_PROMPT_MODULE) {
Expand All @@ -82101,6 +82121,9 @@ var getMainCommitPrompt = async (fullGitMojiSpec, context2) => {
commitLintConfig.prompts
),
INIT_DIFF_PROMPT,
INIT_FIX_CONSISTENCY_PROMPT(
commitLintConfig.consistency[translation2.localLanguage]
),
INIT_CONSISTENCY_PROMPT(
commitLintConfig.consistency[translation2.localLanguage]
)
Expand All @@ -82109,6 +82132,7 @@ var getMainCommitPrompt = async (fullGitMojiSpec, context2) => {
return [
INIT_MAIN_PROMPT(translation2.localLanguage, fullGitMojiSpec, context2),
INIT_DIFF_PROMPT,
INIT_FIX_CONSISTENCY_PROMPT(translation2),
INIT_CONSISTENCY_PROMPT(translation2)
];
}
Expand Down
45 changes: 45 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 36 additions & 12 deletions src/prompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,34 +187,46 @@ export const INIT_DIFF_PROMPT: OpenAI.Chat.Completions.ChatCompletionMessagePara

const getContent = (translation: ConsistencyPrompt) => {
const config = getConfig()
const fix = config.OCO_EMOJI
? `🐛 ${removeConventionalCommitWord(translation.commitFix)}`
: translation.commitFix

const feat = config.OCO_EMOJI
? `✨ ${removeConventionalCommitWord(translation.commitFeat)}`
: translation.commitFeat

const description = config.OCO_DESCRIPTION
? translation.commitDescription
: ''
// English translation
let fixEn = ''
let featEn = ''
let descriptionEn = ''
if (translation !== i18n['en']) {
fixEn = config.OCO_EMOJI
? `\n\n🐛 ${removeConventionalCommitWord(i18n['en'].commitFix)}\n`
: `\n\n${i18n['en'].commitFix}\n`
featEn = config.OCO_EMOJI
? `✨ ${removeConventionalCommitWord(i18n['en'].commitFeat)}\n`
: `${i18n['en'].commitFeat}\n`
? `✨ ${removeConventionalCommitWord(i18n['en'].commitFeat)}\n\n`
: `${i18n['en'].commitFeat}\n\n`
descriptionEn = config.OCO_DESCRIPTION
? `${i18n['en'].commitDescription}`
: ''
}
return `${feat}\n\n${description}${featEn}${descriptionEn}`
}

return `${fix}\n${feat}\n${description}${fixEn}${featEn}${descriptionEn}`
const getContentFix = (translation: ConsistencyPrompt) => {
const config = getConfig()
const fix = config.OCO_EMOJI
? `🐛 ${removeConventionalCommitWord(translation.commitFix)}`
: translation.commitFix
const description = config.OCO_DESCRIPTION
? translation.commitDescription
: ''
// English translation
let fixEn = ''
let descriptionEn = ''
if (translation !== i18n['en']) {
fixEn = config.OCO_EMOJI
? `\n\n🐛 ${removeConventionalCommitWord(i18n['en'].commitFix)}\n\n`
: `\n\n${i18n['en'].commitFix}\n\n`
descriptionEn = config.OCO_DESCRIPTION
? `${i18n['en'].commitDescription}`
: ''
}
return `${fix}\n\n${description}${fixEn}${descriptionEn}`
}

const INIT_CONSISTENCY_PROMPT = (
Expand All @@ -223,6 +235,12 @@ const INIT_CONSISTENCY_PROMPT = (
role: 'assistant', //ChatCompletionRequestMessageRoleEnum.Assistant,
content: getContent(translation),
})
const INIT_FIX_CONSISTENCY_PROMPT = (
translation: ConsistencyPrompt,
): OpenAI.Chat.Completions.ChatCompletionMessageParam => ({
role: 'assistant', //ChatCompletionRequestMessageRoleEnum.Assistant,
content: getContentFix(translation),
})

export const getMainCommitPrompt = async (
fullGitMojiSpec: boolean,
Expand All @@ -248,6 +266,11 @@ export const getMainCommitPrompt = async (
commitLintConfig.prompts,
),
INIT_DIFF_PROMPT,
INIT_FIX_CONSISTENCY_PROMPT(
commitLintConfig.consistency[
translation.localLanguage
] as ConsistencyPrompt,
),
INIT_CONSISTENCY_PROMPT(
commitLintConfig.consistency[
translation.localLanguage
Expand All @@ -259,6 +282,7 @@ export const getMainCommitPrompt = async (
return [
INIT_MAIN_PROMPT(translation.localLanguage, fullGitMojiSpec, context),
INIT_DIFF_PROMPT,
INIT_FIX_CONSISTENCY_PROMPT(translation),
INIT_CONSISTENCY_PROMPT(translation),
]
}
Expand Down

0 comments on commit 1ebbdc5

Please sign in to comment.