51 lines
2.1 KiB
TypeScript
51 lines
2.1 KiB
TypeScript
import type { CommitType } from './config.js';
|
||
|
||
const commitTypeFormats: Record<CommitType, string> = {
|
||
'': '<commit message>',
|
||
conventional: '<type>(<optional scope>): <commit message>',
|
||
};
|
||
const specifyCommitFormat = (type: CommitType) =>
|
||
`输出响应必须使用以下格式:\n${commitTypeFormats[type]}`;
|
||
|
||
const commitTypes: Record<CommitType, string> = {
|
||
'': '',
|
||
|
||
/**
|
||
* References:
|
||
* Commitlint:
|
||
* https://github.com/conventional-changelog/commitlint/blob/18fbed7ea86ac0ec9d5449b4979b762ec4305a92/%40commitlint/config-conventional/index.js#L40-L100
|
||
*
|
||
* Conventional Changelog:
|
||
* https://github.com/conventional-changelog/conventional-changelog/blob/d0e5d5926c8addba74bc962553dd8bcfba90e228/packages/conventional-changelog-conventionalcommits/writer-opts.js#L182-L193
|
||
*/
|
||
conventional: `从下面的类型到描述的JSON中选择最能描述git差异的类型(中文即可,注意后面加冒号):\n
|
||
\n- feat: 新功能
|
||
\n- fix: 修复 bug
|
||
\n- docs: 更新文档
|
||
\n- style: 格式调整(不影响代码执行)
|
||
\n- refactor: 重构(非功能更新)
|
||
\n- test: 测试相关内容
|
||
\n- chore: 构建或工具变更`,
|
||
};
|
||
|
||
export const generatePrompt = (
|
||
locale: string,
|
||
maxLength: number,
|
||
type: CommitType
|
||
) =>
|
||
[
|
||
'为以下代码差异生成一个简洁的、使用现在时态的中文git提交消息,并遵循以下规范:',
|
||
`- 提交消息使用中文编写。`,
|
||
`- 提交消息最多${maxLength}个字符。`,
|
||
`- 使用动词作开头(祈使句形式)`,
|
||
'- 提交消息包含具体的类名、方法名或其他关键信息,不能过于笼统。',
|
||
'- 对于功能添加,应该指明具体的类或模块,如"在UserController中添加了用户权限验证功能"。',
|
||
'- 对于代码重构,应该指明重构的具体类或方法,如"重构了PaymentProcessor类的金额计算逻辑"。',
|
||
'- 排除任何不必要的内容,如翻译。您的整个响应将直接传递到git提交中。',
|
||
commitTypes[type],
|
||
specifyCommitFormat(type),
|
||
//`只输出Git的提交信息即可,不要输出其他任何信息`,
|
||
]
|
||
.filter(Boolean)
|
||
.join('\n');
|