Files
aicommits/src/utils/prompt.ts
史悦 8e1f3d8259
Some checks failed
Test / Test (ubuntu-latest) (push) Has been cancelled
Test / Test (windows-latest) (push) Has been cancelled
优化 generatePrompt 函数,通过注释添加提示,以确保仅输出Git提交信息。
2025-10-21 10:12:03 +08:00

51 lines
2.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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');