Skip to content

Commit 25c6a0d

Browse files
authored
Merge pull request #462 from jcppkkk/master
refactor(commitlint): update commitlint configuration and prompts
2 parents b277bf3 + 0ebff3b commit 25c6a0d

File tree

3 files changed

+42
-49
lines changed

3 files changed

+42
-49
lines changed

src/modules/commitlint/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export const configureCommitlintIntegration = async (force = false) => {
5353

5454
spin.start('Generating consistency with given @commitlint rules');
5555

56-
const prompts = inferPromptsFromCommitlintConfig(commitLintConfig);
56+
const prompts = inferPromptsFromCommitlintConfig(commitLintConfig as any);
5757

5858
const consistencyPrompts =
5959
commitlintPrompts.GEN_COMMITLINT_CONSISTENCY_PROMPT(prompts);

src/modules/commitlint/prompts.ts

Lines changed: 40 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -56,30 +56,28 @@ const llmReadableRules: {
5656
blankline: (key, applicable) =>
5757
`There should ${applicable} be a blank line at the beginning of the ${key}.`,
5858
caseRule: (key, applicable, value: string | Array<string>) =>
59-
`The ${key} should ${applicable} be in ${
60-
Array.isArray(value)
61-
? `one of the following case:
59+
`The ${key} should ${applicable} be in ${Array.isArray(value)
60+
? `one of the following case:
6261
- ${value.join('\n - ')}.`
63-
: `${value} case.`
62+
: `${value} case.`
6463
}`,
6564
emptyRule: (key, applicable) => `The ${key} should ${applicable} be empty.`,
6665
enumRule: (key, applicable, value: string | Array<string>) =>
67-
`The ${key} should ${applicable} be one of the following values:
66+
`The ${key} should ${applicable} be one of the following values:
6867
- ${Array.isArray(value) ? value.join('\n - ') : value}.`,
6968
enumTypeRule: (key, applicable, value: string | Array<string>, prompt) =>
70-
`The ${key} should ${applicable} be one of the following values:
71-
- ${
72-
Array.isArray(value)
69+
`The ${key} should ${applicable} be one of the following values:
70+
- ${Array.isArray(value)
7371
? value
74-
.map((v) => {
75-
const description = getTypeRuleExtraDescription(v, prompt);
76-
if (description) {
77-
return `${v} (${description})`;
78-
} else return v;
79-
})
80-
.join('\n - ')
72+
.map((v) => {
73+
const description = getTypeRuleExtraDescription(v, prompt);
74+
if (description) {
75+
return `${v} (${description})`;
76+
} else return v;
77+
})
78+
.join('\n - ')
8179
: value
82-
}.`,
80+
}.`,
8381
fullStopRule: (key, applicable, value: string) =>
8482
`The ${key} should ${applicable} end with '${value}'.`,
8583
maxLengthRule: (key, applicable, value: string) =>
@@ -216,15 +214,15 @@ const STRUCTURE_OF_COMMIT = config.OCO_OMIT_SCOPE
216214
const GEN_COMMITLINT_CONSISTENCY_PROMPT = (
217215
prompts: string[]
218216
): OpenAI.Chat.Completions.ChatCompletionMessageParam[] => [
219-
{
220-
role: 'system',
221-
content: `${IDENTITY} Your mission is to create clean and comprehensive commit messages for two different changes in a single codebase and output them in the provided JSON format: one for a bug fix and another for a new feature.
217+
{
218+
role: 'system',
219+
content: `${IDENTITY} Your mission is to create clean and comprehensive commit messages for two different changes in a single codebase and output them in the provided JSON format: one for a bug fix and another for a new feature.
222220
223221
Here are the specific requirements and conventions that should be strictly followed:
224222
225223
Commit Message Conventions:
226224
- The commit message consists of three parts: Header, Body, and Footer.
227-
- Header:
225+
- Header:
228226
- Format: ${config.OCO_OMIT_SCOPE ? '`<type>: <subject>`' : '`<type>(<scope>): <subject>`'}
229227
- ${prompts.join('\n- ')}
230228
@@ -240,17 +238,17 @@ JSON Output Format:
240238
"commitDescription": "<Description of commit for both the bug fix and the feature>"
241239
}
242240
\`\`\`
243-
- The "commitDescription" should not include the commit messages header, only the description.
241+
- The "commitDescription" should not include the commit message's header, only the description.
244242
- Description should not be more than 74 characters.
245243
246244
Additional Details:
247245
- Changing the variable 'port' to uppercase 'PORT' is considered a bug fix.
248246
- Allowing the server to listen on a port specified through the environment variable is considered a new feature.
249247
250248
Example Git Diff is to follow:`
251-
},
252-
INIT_DIFF_PROMPT
253-
];
249+
},
250+
INIT_DIFF_PROMPT
251+
];
254252

255253
/**
256254
* Prompt to have LLM generate a message using @commitlint rules.
@@ -264,30 +262,25 @@ const INIT_MAIN_PROMPT = (
264262
prompts: string[]
265263
): OpenAI.Chat.Completions.ChatCompletionMessageParam => ({
266264
role: 'system',
267-
content: `${IDENTITY} Your mission is to create clean and comprehensive commit messages in the given @commitlint convention and explain WHAT were the changes ${
268-
config.OCO_WHY ? 'and WHY the changes were done' : ''
269-
}. I'll send you an output of 'git diff --staged' command, and you convert it into a commit message.
270-
${
271-
config.OCO_EMOJI
272-
? 'Use GitMoji convention to preface the commit.'
273-
: 'Do not preface the commit with anything.'
274-
}
275-
${
276-
config.OCO_DESCRIPTION
277-
? 'Add a short description of WHY the changes are done after the commit message. Don\'t start it with "This commit", just describe the changes.'
278-
: "Don't add any descriptions to the commit, only commit message."
279-
}
265+
content: `${IDENTITY} Your mission is to create clean and comprehensive commit messages in the given @commitlint convention and explain WHAT were the changes ${config.OCO_WHY ? 'and WHY the changes were done' : ''
266+
}. I'll send you an output of 'git diff --staged' command, and you convert it into a commit message.
267+
${config.OCO_EMOJI
268+
? 'Use GitMoji convention to preface the commit.'
269+
: 'Do not preface the commit with anything.'
270+
}
271+
${config.OCO_DESCRIPTION
272+
? 'Add a short description of WHY the changes are done after the commit message. Don\'t start it with "This commit", just describe the changes.'
273+
: "Don't add any descriptions to the commit, only commit message."
274+
}
280275
Use the present tense. Use ${language} to answer.
281-
${
282-
config.OCO_ONE_LINE_COMMIT
283-
? 'Craft a concise commit message that encapsulates all changes made, with an emphasis on the primary updates. If the modifications share a common theme or scope, mention it succinctly; otherwise, leave the scope out to maintain focus. The goal is to provide a clear and unified overview of the changes in a one single message, without diverging into a list of commit per file change.'
284-
: ''
285-
}
286-
${
287-
config.OCO_OMIT_SCOPE
288-
? 'Do not include a scope in the commit message format. Use the format: <type>: <subject>'
289-
: ''
290-
}
276+
${config.OCO_ONE_LINE_COMMIT
277+
? 'Craft a concise commit message that encapsulates all changes made, with an emphasis on the primary updates. If the modifications share a common theme or scope, mention it succinctly; otherwise, leave the scope out to maintain focus. The goal is to provide a clear and unified overview of the changes in a one single message, without diverging into a list of commit per file change.'
278+
: ''
279+
}
280+
${config.OCO_OMIT_SCOPE
281+
? 'Do not include a scope in the commit message format. Use the format: <type>: <subject>'
282+
: ''
283+
}
291284
You will strictly follow the following conventions to generate the content of the commit message:
292285
- ${prompts.join('\n- ')}
293286

src/modules/commitlint/pwd-commitlint.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export const getCommitLintPWDConfig =
6060
* ES Module (commitlint@v19.x.x. <= )
6161
* Directory import is not supported in ES Module resolution, so import the file directly
6262
*/
63-
modulePath = await findModulePath('@commitlint/load/lib/load.js');
63+
modulePath = findModulePath('@commitlint/load/lib/load.js');
6464
load = (await import(modulePath)).default;
6565
break;
6666
}

0 commit comments

Comments
 (0)