@@ -7,11 +7,12 @@ pub struct Commit {
7
7
files_changed : usize ,
8
8
added : usize ,
9
9
deleted : usize ,
10
+ commit_msg : String , // 新增的 commit_msg 字段
10
11
}
11
12
12
13
pub fn get_commits ( keyword : & str , exclude_merge : & bool ) -> Vec < Commit > {
13
14
let k = format ! ( "--grep={}" , keyword) ;
14
- let mut args = vec ! [ "log" , & k, "--pretty=format:%H" ] ;
15
+ let mut args = vec ! [ "log" , & k, "--pretty=format:%H %s " ] ; // 获取哈希和提交消息
15
16
16
17
if !exclude_merge {
17
18
args. push ( "--no-merges" ) ;
@@ -27,12 +28,16 @@ pub fn get_commits(keyword: &str, exclude_merge: &bool) -> Vec<Commit> {
27
28
commits
28
29
. lines ( )
29
30
. map ( |commit| {
30
- let ( files_changed, added, deleted) = calculate_diff_info ( commit) ;
31
+ let parts: Vec < & str > = commit. splitn ( 2 , ' ' ) . collect ( ) ;
32
+ let commit_hash = parts[ 0 ] . to_string ( ) ;
33
+ let commit_msg = parts. get ( 1 ) . unwrap_or ( & "" ) . to_string ( ) ; // 获取提交消息
34
+ let ( files_changed, added, deleted) = calculate_diff_info ( & commit_hash) ;
31
35
Commit {
32
- commit_hash : commit . to_string ( ) ,
36
+ commit_hash,
33
37
files_changed,
34
38
added,
35
39
deleted,
40
+ commit_msg,
36
41
}
37
42
} )
38
43
. collect ( )
@@ -84,8 +89,8 @@ pub fn print_commit_stats(commit_stats: Vec<Commit>) {
84
89
85
90
for commit in commit_stats {
86
91
println ! (
87
- "Commit {}: {} insertions(+), {} deletions(-),{} files changed" ,
88
- commit. commit_hash, commit. added, commit. deleted, commit. files_changed,
92
+ "Commit {}: {}, {} insertions(+), {} deletions(-),{} files changed" ,
93
+ commit. commit_hash, commit. commit_msg , commit . added, commit. deleted, commit. files_changed,
89
94
) ;
90
95
91
96
total_added += commit. added ;
@@ -107,12 +112,14 @@ mod tests {
107
112
let keyword = "README" ;
108
113
let exclude_merge = true ;
109
114
let expected_commit_id = "cd13ae5251d6aaf12e4497d6285a6aa1b507eb42" ;
115
+ let expected_commit_msg = "feat: README" ; // 假设这是提交消息
110
116
111
117
let commits = get_commits ( keyword, & exclude_merge) ;
112
118
assert ! ( !commits. is_empty( ) ) ;
113
119
114
120
let expected_commit = Commit {
115
121
commit_hash : expected_commit_id. to_string ( ) ,
122
+ commit_msg : expected_commit_msg. to_string ( ) , // 检查提交消息
116
123
files_changed : 1 ,
117
124
added : 99 ,
118
125
deleted : 0 ,
@@ -145,18 +152,21 @@ mod tests {
145
152
files_changed: 2 ,
146
153
added: 10 ,
147
154
deleted: 5 ,
155
+ commit_msg: "commit1" . to_string( )
148
156
} ,
149
157
Commit {
150
158
commit_hash: "commit2" . to_string( ) ,
151
159
files_changed: 3 ,
152
160
added: 50 ,
153
161
deleted: 10 ,
162
+ commit_msg: "commit2" . to_string( )
154
163
} ,
155
164
Commit {
156
165
commit_hash: "commit3" . to_string( ) ,
157
166
files_changed: 1 ,
158
167
added: 30 ,
159
168
deleted: 2 ,
169
+ commit_msg: "commit3" . to_string( )
160
170
} ,
161
171
] ;
162
172
0 commit comments