Skip to content

Commit 1ebbdc5

Browse files
committed
♻️ リファクタ(prompts.ts): getContent関数をgetContentgetContentFixに分割しました
`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.
1 parent 96c6b3b commit 1ebbdc5

File tree

4 files changed

+143
-26
lines changed

4 files changed

+143
-26
lines changed

out/cli.cjs

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68628,34 +68628,54 @@ var INIT_DIFF_PROMPT = {
6862868628
};
6862968629
var getContent = (translation3) => {
6863068630
const config3 = getConfig();
68631-
const fix = config3.OCO_EMOJI ? `\u{1F41B} ${removeConventionalCommitWord(translation3.commitFix)}` : translation3.commitFix;
6863268631
const feat = config3.OCO_EMOJI ? `\u2728 ${removeConventionalCommitWord(translation3.commitFeat)}` : translation3.commitFeat;
6863368632
const description = config3.OCO_DESCRIPTION ? translation3.commitDescription : "";
68634-
let fixEn = "";
6863568633
let featEn = "";
6863668634
let descriptionEn = "";
68635+
if (translation3 !== i18n["en"]) {
68636+
featEn = config3.OCO_EMOJI ? `\u2728 ${removeConventionalCommitWord(i18n["en"].commitFeat)}
68637+
68638+
` : `${i18n["en"].commitFeat}
68639+
68640+
`;
68641+
descriptionEn = config3.OCO_DESCRIPTION ? `${i18n["en"].commitDescription}` : "";
68642+
}
68643+
return `${feat}
68644+
68645+
${description}${featEn}${descriptionEn}`;
68646+
};
68647+
var getContentFix = (translation3) => {
68648+
const config3 = getConfig();
68649+
const fix = config3.OCO_EMOJI ? `\u{1F41B} ${removeConventionalCommitWord(translation3.commitFix)}` : translation3.commitFix;
68650+
const description = config3.OCO_DESCRIPTION ? translation3.commitDescription : "";
68651+
let fixEn = "";
68652+
let descriptionEn = "";
6863768653
if (translation3 !== i18n["en"]) {
6863868654
fixEn = config3.OCO_EMOJI ? `
6863968655

6864068656
\u{1F41B} ${removeConventionalCommitWord(i18n["en"].commitFix)}
68657+
6864168658
` : `
6864268659

6864368660
${i18n["en"].commitFix}
68644-
`;
68645-
featEn = config3.OCO_EMOJI ? `\u2728 ${removeConventionalCommitWord(i18n["en"].commitFeat)}
68646-
` : `${i18n["en"].commitFeat}
68661+
6864768662
`;
6864868663
descriptionEn = config3.OCO_DESCRIPTION ? `${i18n["en"].commitDescription}` : "";
6864968664
}
6865068665
return `${fix}
68651-
${feat}
68652-
${description}${fixEn}${featEn}${descriptionEn}`;
68666+
68667+
${description}${fixEn}${descriptionEn}`;
6865368668
};
6865468669
var INIT_CONSISTENCY_PROMPT = (translation3) => ({
6865568670
role: "assistant",
6865668671
//ChatCompletionRequestMessageRoleEnum.Assistant,
6865768672
content: getContent(translation3)
6865868673
});
68674+
var INIT_FIX_CONSISTENCY_PROMPT = (translation3) => ({
68675+
role: "assistant",
68676+
//ChatCompletionRequestMessageRoleEnum.Assistant,
68677+
content: getContentFix(translation3)
68678+
});
6865968679
var getMainCommitPrompt = async (fullGitMojiSpec, context) => {
6866068680
const config3 = getConfig();
6866168681
switch (config3.OCO_PROMPT_MODULE) {
@@ -68673,6 +68693,9 @@ var getMainCommitPrompt = async (fullGitMojiSpec, context) => {
6867368693
commitLintConfig.prompts
6867468694
),
6867568695
INIT_DIFF_PROMPT,
68696+
INIT_FIX_CONSISTENCY_PROMPT(
68697+
commitLintConfig.consistency[translation2.localLanguage]
68698+
),
6867668699
INIT_CONSISTENCY_PROMPT(
6867768700
commitLintConfig.consistency[translation2.localLanguage]
6867868701
)
@@ -68681,6 +68704,7 @@ var getMainCommitPrompt = async (fullGitMojiSpec, context) => {
6868168704
return [
6868268705
INIT_MAIN_PROMPT(translation2.localLanguage, fullGitMojiSpec, context),
6868368706
INIT_DIFF_PROMPT,
68707+
INIT_FIX_CONSISTENCY_PROMPT(translation2),
6868468708
INIT_CONSISTENCY_PROMPT(translation2)
6868568709
];
6868668710
}

out/github-action.cjs

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82056,34 +82056,54 @@ var INIT_DIFF_PROMPT = {
8205682056
};
8205782057
var getContent = (translation3) => {
8205882058
const config3 = getConfig();
82059-
const fix = config3.OCO_EMOJI ? `\u{1F41B} ${removeConventionalCommitWord(translation3.commitFix)}` : translation3.commitFix;
8206082059
const feat = config3.OCO_EMOJI ? `\u2728 ${removeConventionalCommitWord(translation3.commitFeat)}` : translation3.commitFeat;
8206182060
const description = config3.OCO_DESCRIPTION ? translation3.commitDescription : "";
82062-
let fixEn = "";
8206382061
let featEn = "";
8206482062
let descriptionEn = "";
82063+
if (translation3 !== i18n["en"]) {
82064+
featEn = config3.OCO_EMOJI ? `\u2728 ${removeConventionalCommitWord(i18n["en"].commitFeat)}
82065+
82066+
` : `${i18n["en"].commitFeat}
82067+
82068+
`;
82069+
descriptionEn = config3.OCO_DESCRIPTION ? `${i18n["en"].commitDescription}` : "";
82070+
}
82071+
return `${feat}
82072+
82073+
${description}${featEn}${descriptionEn}`;
82074+
};
82075+
var getContentFix = (translation3) => {
82076+
const config3 = getConfig();
82077+
const fix = config3.OCO_EMOJI ? `\u{1F41B} ${removeConventionalCommitWord(translation3.commitFix)}` : translation3.commitFix;
82078+
const description = config3.OCO_DESCRIPTION ? translation3.commitDescription : "";
82079+
let fixEn = "";
82080+
let descriptionEn = "";
8206582081
if (translation3 !== i18n["en"]) {
8206682082
fixEn = config3.OCO_EMOJI ? `
8206782083

8206882084
\u{1F41B} ${removeConventionalCommitWord(i18n["en"].commitFix)}
82085+
8206982086
` : `
8207082087

8207182088
${i18n["en"].commitFix}
82072-
`;
82073-
featEn = config3.OCO_EMOJI ? `\u2728 ${removeConventionalCommitWord(i18n["en"].commitFeat)}
82074-
` : `${i18n["en"].commitFeat}
82089+
8207582090
`;
8207682091
descriptionEn = config3.OCO_DESCRIPTION ? `${i18n["en"].commitDescription}` : "";
8207782092
}
8207882093
return `${fix}
82079-
${feat}
82080-
${description}${fixEn}${featEn}${descriptionEn}`;
82094+
82095+
${description}${fixEn}${descriptionEn}`;
8208182096
};
8208282097
var INIT_CONSISTENCY_PROMPT = (translation3) => ({
8208382098
role: "assistant",
8208482099
//ChatCompletionRequestMessageRoleEnum.Assistant,
8208582100
content: getContent(translation3)
8208682101
});
82102+
var INIT_FIX_CONSISTENCY_PROMPT = (translation3) => ({
82103+
role: "assistant",
82104+
//ChatCompletionRequestMessageRoleEnum.Assistant,
82105+
content: getContentFix(translation3)
82106+
});
8208782107
var getMainCommitPrompt = async (fullGitMojiSpec, context2) => {
8208882108
const config3 = getConfig();
8208982109
switch (config3.OCO_PROMPT_MODULE) {
@@ -82101,6 +82121,9 @@ var getMainCommitPrompt = async (fullGitMojiSpec, context2) => {
8210182121
commitLintConfig.prompts
8210282122
),
8210382123
INIT_DIFF_PROMPT,
82124+
INIT_FIX_CONSISTENCY_PROMPT(
82125+
commitLintConfig.consistency[translation2.localLanguage]
82126+
),
8210482127
INIT_CONSISTENCY_PROMPT(
8210582128
commitLintConfig.consistency[translation2.localLanguage]
8210682129
)
@@ -82109,6 +82132,7 @@ var getMainCommitPrompt = async (fullGitMojiSpec, context2) => {
8210982132
return [
8211082133
INIT_MAIN_PROMPT(translation2.localLanguage, fullGitMojiSpec, context2),
8211182134
INIT_DIFF_PROMPT,
82135+
INIT_FIX_CONSISTENCY_PROMPT(translation2),
8211282136
INIT_CONSISTENCY_PROMPT(translation2)
8211382137
];
8211482138
}

package-lock.json

Lines changed: 45 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/prompts.ts

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -187,34 +187,46 @@ export const INIT_DIFF_PROMPT: OpenAI.Chat.Completions.ChatCompletionMessagePara
187187

188188
const getContent = (translation: ConsistencyPrompt) => {
189189
const config = getConfig()
190-
const fix = config.OCO_EMOJI
191-
? `🐛 ${removeConventionalCommitWord(translation.commitFix)}`
192-
: translation.commitFix
193-
194190
const feat = config.OCO_EMOJI
195191
? `✨ ${removeConventionalCommitWord(translation.commitFeat)}`
196192
: translation.commitFeat
197-
198193
const description = config.OCO_DESCRIPTION
199194
? translation.commitDescription
200195
: ''
201196
// English translation
202-
let fixEn = ''
203197
let featEn = ''
204198
let descriptionEn = ''
205199
if (translation !== i18n['en']) {
206-
fixEn = config.OCO_EMOJI
207-
? `\n\n🐛 ${removeConventionalCommitWord(i18n['en'].commitFix)}\n`
208-
: `\n\n${i18n['en'].commitFix}\n`
209200
featEn = config.OCO_EMOJI
210-
? `✨ ${removeConventionalCommitWord(i18n['en'].commitFeat)}\n`
211-
: `${i18n['en'].commitFeat}\n`
201+
? `✨ ${removeConventionalCommitWord(i18n['en'].commitFeat)}\n\n`
202+
: `${i18n['en'].commitFeat}\n\n`
212203
descriptionEn = config.OCO_DESCRIPTION
213204
? `${i18n['en'].commitDescription}`
214205
: ''
215206
}
207+
return `${feat}\n\n${description}${featEn}${descriptionEn}`
208+
}
216209

217-
return `${fix}\n${feat}\n${description}${fixEn}${featEn}${descriptionEn}`
210+
const getContentFix = (translation: ConsistencyPrompt) => {
211+
const config = getConfig()
212+
const fix = config.OCO_EMOJI
213+
? `🐛 ${removeConventionalCommitWord(translation.commitFix)}`
214+
: translation.commitFix
215+
const description = config.OCO_DESCRIPTION
216+
? translation.commitDescription
217+
: ''
218+
// English translation
219+
let fixEn = ''
220+
let descriptionEn = ''
221+
if (translation !== i18n['en']) {
222+
fixEn = config.OCO_EMOJI
223+
? `\n\n🐛 ${removeConventionalCommitWord(i18n['en'].commitFix)}\n\n`
224+
: `\n\n${i18n['en'].commitFix}\n\n`
225+
descriptionEn = config.OCO_DESCRIPTION
226+
? `${i18n['en'].commitDescription}`
227+
: ''
228+
}
229+
return `${fix}\n\n${description}${fixEn}${descriptionEn}`
218230
}
219231

220232
const INIT_CONSISTENCY_PROMPT = (
@@ -223,6 +235,12 @@ const INIT_CONSISTENCY_PROMPT = (
223235
role: 'assistant', //ChatCompletionRequestMessageRoleEnum.Assistant,
224236
content: getContent(translation),
225237
})
238+
const INIT_FIX_CONSISTENCY_PROMPT = (
239+
translation: ConsistencyPrompt,
240+
): OpenAI.Chat.Completions.ChatCompletionMessageParam => ({
241+
role: 'assistant', //ChatCompletionRequestMessageRoleEnum.Assistant,
242+
content: getContentFix(translation),
243+
})
226244

227245
export const getMainCommitPrompt = async (
228246
fullGitMojiSpec: boolean,
@@ -248,6 +266,11 @@ export const getMainCommitPrompt = async (
248266
commitLintConfig.prompts,
249267
),
250268
INIT_DIFF_PROMPT,
269+
INIT_FIX_CONSISTENCY_PROMPT(
270+
commitLintConfig.consistency[
271+
translation.localLanguage
272+
] as ConsistencyPrompt,
273+
),
251274
INIT_CONSISTENCY_PROMPT(
252275
commitLintConfig.consistency[
253276
translation.localLanguage
@@ -259,6 +282,7 @@ export const getMainCommitPrompt = async (
259282
return [
260283
INIT_MAIN_PROMPT(translation.localLanguage, fullGitMojiSpec, context),
261284
INIT_DIFF_PROMPT,
285+
INIT_FIX_CONSISTENCY_PROMPT(translation),
262286
INIT_CONSISTENCY_PROMPT(translation),
263287
]
264288
}

0 commit comments

Comments
 (0)