refactor(commitlint): update commitlint configuration and prompts for improved clarity and consistency
The commitlint configuration and prompts have been refactored to enhance clarity and maintain consistency throughout the codebase. The type assertion for commitLintConfig is updated to use 'as any' for better type handling. Additionally, formatting adjustments are made in the prompts to ensure proper readability and alignment with the defined conventions. These changes aim to streamline the commit message generation process and improve overall code maintainability.
This commit is contained in:
@@ -53,7 +53,7 @@ export const configureCommitlintIntegration = async (force = false) => {
|
|||||||
|
|
||||||
spin.start('Generating consistency with given @commitlint rules');
|
spin.start('Generating consistency with given @commitlint rules');
|
||||||
|
|
||||||
const prompts = inferPromptsFromCommitlintConfig(commitLintConfig);
|
const prompts = inferPromptsFromCommitlintConfig(commitLintConfig as any);
|
||||||
|
|
||||||
const consistencyPrompts =
|
const consistencyPrompts =
|
||||||
commitlintPrompts.GEN_COMMITLINT_CONSISTENCY_PROMPT(prompts);
|
commitlintPrompts.GEN_COMMITLINT_CONSISTENCY_PROMPT(prompts);
|
||||||
|
|||||||
@@ -56,8 +56,7 @@ const llmReadableRules: {
|
|||||||
blankline: (key, applicable) =>
|
blankline: (key, applicable) =>
|
||||||
`There should ${applicable} be a blank line at the beginning of the ${key}.`,
|
`There should ${applicable} be a blank line at the beginning of the ${key}.`,
|
||||||
caseRule: (key, applicable, value: string | Array<string>) =>
|
caseRule: (key, applicable, value: string | Array<string>) =>
|
||||||
`The ${key} should ${applicable} be in ${
|
`The ${key} should ${applicable} be in ${Array.isArray(value)
|
||||||
Array.isArray(value)
|
|
||||||
? `one of the following case:
|
? `one of the following case:
|
||||||
- ${value.join('\n - ')}.`
|
- ${value.join('\n - ')}.`
|
||||||
: `${value} case.`
|
: `${value} case.`
|
||||||
@@ -68,8 +67,7 @@ const llmReadableRules: {
|
|||||||
- ${Array.isArray(value) ? value.join('\n - ') : value}.`,
|
- ${Array.isArray(value) ? value.join('\n - ') : value}.`,
|
||||||
enumTypeRule: (key, applicable, value: string | Array<string>, prompt) =>
|
enumTypeRule: (key, applicable, value: string | Array<string>, prompt) =>
|
||||||
`The ${key} should ${applicable} be one of the following values:
|
`The ${key} should ${applicable} be one of the following values:
|
||||||
- ${
|
- ${Array.isArray(value)
|
||||||
Array.isArray(value)
|
|
||||||
? value
|
? value
|
||||||
.map((v) => {
|
.map((v) => {
|
||||||
const description = getTypeRuleExtraDescription(v, prompt);
|
const description = getTypeRuleExtraDescription(v, prompt);
|
||||||
@@ -240,7 +238,7 @@ JSON Output Format:
|
|||||||
"commitDescription": "<Description of commit for both the bug fix and the feature>"
|
"commitDescription": "<Description of commit for both the bug fix and the feature>"
|
||||||
}
|
}
|
||||||
\`\`\`
|
\`\`\`
|
||||||
- The "commitDescription" should not include the commit message’s header, only the description.
|
- The "commitDescription" should not include the commit message's header, only the description.
|
||||||
- Description should not be more than 74 characters.
|
- Description should not be more than 74 characters.
|
||||||
|
|
||||||
Additional Details:
|
Additional Details:
|
||||||
@@ -264,27 +262,22 @@ const INIT_MAIN_PROMPT = (
|
|||||||
prompts: string[]
|
prompts: string[]
|
||||||
): OpenAI.Chat.Completions.ChatCompletionMessageParam => ({
|
): OpenAI.Chat.Completions.ChatCompletionMessageParam => ({
|
||||||
role: 'system',
|
role: 'system',
|
||||||
content: `${IDENTITY} Your mission is to create clean and comprehensive commit messages in the given @commitlint convention and explain WHAT were the changes ${
|
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' : ''
|
||||||
config.OCO_WHY ? 'and WHY the changes were done' : ''
|
|
||||||
}. I'll send you an output of 'git diff --staged' command, and you convert it into a commit message.
|
}. I'll send you an output of 'git diff --staged' command, and you convert it into a commit message.
|
||||||
${
|
${config.OCO_EMOJI
|
||||||
config.OCO_EMOJI
|
|
||||||
? 'Use GitMoji convention to preface the commit.'
|
? 'Use GitMoji convention to preface the commit.'
|
||||||
: 'Do not preface the commit with anything.'
|
: 'Do not preface the commit with anything.'
|
||||||
}
|
}
|
||||||
${
|
${config.OCO_DESCRIPTION
|
||||||
config.OCO_DESCRIPTION
|
|
||||||
? '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.'
|
? '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.'
|
||||||
: "Don't add any descriptions to the commit, only commit message."
|
: "Don't add any descriptions to the commit, only commit message."
|
||||||
}
|
}
|
||||||
Use the present tense. Use ${language} to answer.
|
Use the present tense. Use ${language} to answer.
|
||||||
${
|
${config.OCO_ONE_LINE_COMMIT
|
||||||
config.OCO_ONE_LINE_COMMIT
|
|
||||||
? '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.'
|
? '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.'
|
||||||
: ''
|
: ''
|
||||||
}
|
}
|
||||||
${
|
${config.OCO_OMIT_SCOPE
|
||||||
config.OCO_OMIT_SCOPE
|
|
||||||
? 'Do not include a scope in the commit message format. Use the format: <type>: <subject>'
|
? 'Do not include a scope in the commit message format. Use the format: <type>: <subject>'
|
||||||
: ''
|
: ''
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ export const getCommitLintPWDConfig =
|
|||||||
* ES Module (commitlint@v19.x.x. <= )
|
* ES Module (commitlint@v19.x.x. <= )
|
||||||
* Directory import is not supported in ES Module resolution, so import the file directly
|
* Directory import is not supported in ES Module resolution, so import the file directly
|
||||||
*/
|
*/
|
||||||
modulePath = await findModulePath('@commitlint/load/lib/load.js');
|
modulePath = findModulePath('@commitlint/load/lib/load.js');
|
||||||
load = (await import(modulePath)).default;
|
load = (await import(modulePath)).default;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user