@@ -15,6 +15,115 @@ const ENGLISH_PROMPT_TEMPLATE: &str = r#"Please analyze the git diff content and
15151. First line: type: message (under 50 characters)
16162. Empty line after the title
17173. Detailed explanation in English (what was changed and why)
18+ 4. Empty line after explanation
19+ 5. Testing Suggestions section with black-box testing recommendations
20+ 6. Type must be one of: feat/fix/docs/style/refactor/test/chore
21+ 7. Focus on both WHAT changed and WHY it was necessary
22+ 8. Include any important technical details or context
23+ 9. DO NOT include any Chinese content
24+ 10. DO NOT wrap the response in any markdown or code block markers
25+
26+ Example response format:
27+ feat: add user authentication module
28+
29+ 1. Implement JWT-based authentication system
30+ 2. Add user login and registration endpoints
31+ 3. Include password hashing with bcrypt
32+ 4. Set up token refresh mechanism
33+
34+ Testing Suggestions:
35+ - Test user registration with valid and invalid inputs
36+ - Verify login functionality with correct and incorrect credentials
37+ - Test JWT token generation and validation
38+ - Verify password security and hashing
39+ - Test token refresh mechanism and expiration handling
40+ - Verify access control for protected endpoints
41+
42+ Please respond with ONLY the commit message following this format,
43+ DO NOT end commit titles with any punctuation."# ;
44+
45+ const CHINESE_PROMPT_TEMPLATE : & str = r#"请分析以下 git diff 内容,并按照以下格式生成提交信息:
46+ 1. 第一行为标题:type: message(不超过50个字符)
47+ 2. 标题下方空一行
48+ 3. 详细的中文说明(解释做了什么改动以及为什么需要这些改动)
49+ 4. 说明下方空一行
50+ 5. 测试建议部分,提供黑盒测试的重点和范围
51+ 6. type 必须是以下之一:feat/fix/docs/style/refactor/test/chore
52+ 7. 关注点:变更内容(做了什么)和变更原因(为什么)
53+ 8. 包含重要的技术细节或上下文
54+ 9. 不要使用任何 markdown 或代码块标记
55+ 10. 标题结尾不要使用标点符号
56+
57+ 示例格式:
58+ feat: 添加用户认证模块
59+
60+ 1. 实现基于 JWT 的认证系统
61+ 2. 添加用户登录和注册端点
62+ 3. 包含使用 bcrypt 的密码哈希处理
63+ 4. 设置令牌刷新机制
64+
65+ 测试建议:
66+ - 测试用户注册功能,包括有效和无效输入
67+ - 验证登录功能,测试正确和错误的凭据
68+ - 测试 JWT 令牌生成和验证流程
69+ - 验证密码安全性和哈希处理
70+ - 测试令牌刷新机制和过期处理
71+ - 验证受保护端点的访问控制"# ;
72+
73+ const BILINGUAL_PROMPT_TEMPLATE : & str = r#"Please analyze the git diff content and generate a detailed bilingual commit message with:
74+ 1. First line in English: type: message (under 50 characters)
75+ 2. Empty line after the title
76+ 3. Detailed explanation in English (what was changed and why)
77+ 4. Empty line after English explanation
78+ 5. Testing Suggestions section in English with black-box testing recommendations
79+ 6. Empty line after English testing suggestions
80+ 7. Chinese title and explanation (translate the English content)
81+ 8. Empty line after Chinese explanation
82+ 9. Chinese Testing Suggestions section (translate the English testing suggestions)
83+ 10. Type must be one of: feat/fix/docs/style/refactor/test/chore
84+ 11. Focus on both WHAT changed and WHY it was necessary
85+ 12. Include any important technical details or context
86+ 13. DO NOT wrap the response in any markdown or code block markers
87+
88+ Example response format:
89+ feat: add user authentication module
90+
91+ 1. Implement JWT-based authentication system
92+ 2. Add user login and registration endpoints
93+ 3. Include password hashing with bcrypt
94+ 4. Set up token refresh mechanism
95+
96+ Testing Suggestions:
97+ - Test user registration with valid and invalid inputs
98+ - Verify login functionality with correct and incorrect credentials
99+ - Test JWT token generation and validation
100+ - Verify password security and hashing
101+ - Test token refresh mechanism and expiration handling
102+ - Verify access control for protected endpoints
103+
104+ feat: 添加用户认证模块
105+
106+ 1. 实现基于 JWT 的认证系统
107+ 2. 添加用户登录和注册端点
108+ 3. 包含使用 bcrypt 的密码哈希处理
109+ 4. 设置令牌刷新机制
110+
111+ 测试建议:
112+ - 测试用户注册功能,包括有效和无效输入
113+ - 验证登录功能,测试正确和错误的凭据
114+ - 测试 JWT 令牌生成和验证流程
115+ - 验证密码安全性和哈希处理
116+ - 测试令牌刷新机制和过期处理
117+ - 验证受保护端点的访问控制
118+
119+ Please respond with ONLY the commit message following this format,
120+ DO NOT end commit titles with any punctuation."# ;
121+
122+ // 无测试建议版本的提示词模板
123+ const ENGLISH_PROMPT_TEMPLATE_NO_TEST : & str = r#"Please analyze the git diff content and generate a commit message in English only:
124+ 1. First line: type: message (under 50 characters)
125+ 2. Empty line after the title
126+ 3. Detailed explanation in English (what was changed and why)
181274. Type must be one of: feat/fix/docs/style/refactor/test/chore
191285. Focus on both WHAT changed and WHY it was necessary
201296. Include any important technical details or context
@@ -32,7 +141,7 @@ feat: add user authentication module
32141Please respond with ONLY the commit message following this format,
33142DO NOT end commit titles with any punctuation."# ;
34143
35- const CHINESE_PROMPT_TEMPLATE : & str = r#"请分析以下 git diff 内容,并按照以下格式生成提交信息:
144+ const CHINESE_PROMPT_TEMPLATE_NO_TEST : & str = r#"请分析以下 git diff 内容,并按照以下格式生成提交信息:
361451. 第一行为标题:type: message(不超过50个字符)
371462. 标题下方空一行
381473. 详细的中文说明(解释做了什么改动以及为什么需要这些改动)
@@ -50,7 +159,7 @@ feat: 添加用户认证模块
501593. 包含使用 bcrypt 的密码哈希处理
511604. 设置令牌刷新机制"# ;
52161
53- const BILINGUAL_PROMPT_TEMPLATE : & str = r#"Please analyze the git diff content and generate a detailed bilingual commit message with:
162+ const BILINGUAL_PROMPT_TEMPLATE_NO_TEST : & str = r#"Please analyze the git diff content and generate a detailed bilingual commit message with:
541631. First line in English: type: message (under 50 characters)
551642. Empty line after the title
561653. Detailed explanation in English (what was changed and why)
@@ -90,19 +199,22 @@ impl LanguageMode {
90199 }
91200 }
92201
93- fn template ( & self ) -> & ' static str {
94- match self {
95- Self :: EnglishOnly => ENGLISH_PROMPT_TEMPLATE ,
96- Self :: ChineseOnly => CHINESE_PROMPT_TEMPLATE ,
97- Self :: Bilingual => BILINGUAL_PROMPT_TEMPLATE ,
202+ fn template ( & self , include_test_suggestions : bool ) -> & ' static str {
203+ match ( self , include_test_suggestions) {
204+ ( Self :: EnglishOnly , true ) => ENGLISH_PROMPT_TEMPLATE ,
205+ ( Self :: EnglishOnly , false ) => ENGLISH_PROMPT_TEMPLATE_NO_TEST ,
206+ ( Self :: ChineseOnly , true ) => CHINESE_PROMPT_TEMPLATE ,
207+ ( Self :: ChineseOnly , false ) => CHINESE_PROMPT_TEMPLATE_NO_TEST ,
208+ ( Self :: Bilingual , true ) => BILINGUAL_PROMPT_TEMPLATE ,
209+ ( Self :: Bilingual , false ) => BILINGUAL_PROMPT_TEMPLATE_NO_TEST ,
98210 }
99211 }
100212}
101213
102214// 统一的提示词构建函数
103- fn build_prompt ( mode : LanguageMode , user_message : Option < & str > ) -> String {
104- let mut prompt = String :: from ( mode. template ( ) ) ;
105-
215+ fn build_prompt ( mode : LanguageMode , user_message : Option < & str > , include_test_suggestions : bool ) -> String {
216+ let mut prompt = String :: from ( mode. template ( include_test_suggestions ) ) ;
217+
106218 if let Some ( msg) = user_message {
107219 match mode {
108220 LanguageMode :: ChineseOnly => {
@@ -122,7 +234,7 @@ fn build_prompt(mode: LanguageMode, user_message: Option<&str>) -> String {
122234 }
123235 }
124236 }
125-
237+
126238 prompt
127239}
128240
@@ -229,6 +341,7 @@ pub async fn generate_commit_message(
229341 no_translate : bool ,
230342 mut only_chinese : bool ,
231343 mut only_english : bool ,
344+ no_test_suggestions : bool ,
232345) -> anyhow:: Result < ( ) > {
233346 // 加载配置,如果指定了参数则使用参数值,否则使用配置中的默认值
234347 if let Ok ( config) = config:: Config :: load ( ) {
@@ -237,7 +350,7 @@ pub async fn generate_commit_message(
237350 only_english = config. only_english ;
238351 }
239352 }
240-
353+
241354 // 处理语言选项冲突:only_english 优先级最高
242355 if only_english {
243356 only_chinese = false ;
@@ -280,9 +393,10 @@ pub async fn generate_commit_message(
280393 // 设置环境变量标记跳过后续的代码审查
281394 std:: env:: set_var ( "GIT_COMMIT_HELPER_SKIP_REVIEW" , "1" ) ;
282395
283- // 确定语言模式并构建提示词
396+ // 确定语言模式并构建提示词,考虑是否包含测试建议
284397 let language_mode = LanguageMode :: determine ( only_chinese, only_english) ;
285- let prompt = build_prompt ( language_mode, message. as_deref ( ) ) ;
398+ let include_test_suggestions = !no_test_suggestions;
399+ let prompt = build_prompt ( language_mode, message. as_deref ( ) , include_test_suggestions) ;
286400
287401 debug ! ( "生成的提示信息:\n {}" , prompt) ;
288402
0 commit comments