@@ -8,12 +8,16 @@ use std::{
8
8
9
9
use anyhow:: { anyhow, bail} ;
10
10
use git_repository as git;
11
- use git_repository:: { actor, bstr:: BString , interrupt, objs, prelude:: * , progress, refs:: file:: ReferenceExt , Progress } ;
11
+ use git_repository:: {
12
+ actor, bstr:: BString , bstr:: ByteSlice , interrupt, objs, prelude:: * , progress, refs:: file:: ReferenceExt , Progress ,
13
+ } ;
12
14
use itertools:: Itertools ;
13
15
use rayon:: prelude:: * ;
14
16
15
17
/// Additional configuration for the hours estimation functionality.
16
18
pub struct Context < W > {
19
+ /// Ignore github bots which match the `[bot]` search string.
20
+ pub ignore_bots : bool ,
17
21
/// Show personally identifiable information before the summary. Includes names and email addresses.
18
22
pub show_pii : bool ,
19
23
/// Omit unifying identities by name and email which can lead to the same author appear multiple times
@@ -35,6 +39,7 @@ pub fn estimate<W, P>(
35
39
mut progress : P ,
36
40
Context {
37
41
show_pii,
42
+ ignore_bots,
38
43
omit_unify_identities,
39
44
mut out,
40
45
} : Context < W > ,
@@ -110,11 +115,17 @@ where
110
115
let mut current_email = & all_commits[ 0 ] . email ;
111
116
let mut slice_start = 0 ;
112
117
let mut results_by_hours = Vec :: new ( ) ;
118
+ let mut ignored_bot_commits = 0_u32 ;
113
119
for ( idx, elm) in all_commits. iter ( ) . enumerate ( ) {
114
120
if elm. email != * current_email {
115
- results_by_hours . push ( estimate_hours ( & all_commits[ slice_start..idx] ) ) ;
121
+ let estimate = estimate_hours ( & all_commits[ slice_start..idx] ) ;
116
122
slice_start = idx;
117
123
current_email = & elm. email ;
124
+ if ignore_bots && estimate. name . contains_str ( b"[bot]" ) {
125
+ ignored_bot_commits += estimate. num_commits ;
126
+ continue ;
127
+ }
128
+ results_by_hours. push ( estimate) ;
118
129
}
119
130
}
120
131
if let Some ( commits) = all_commits. get ( slice_start..) {
@@ -170,7 +181,14 @@ where
170
181
( 1.0 - ( num_unique_authors as f32 / num_authors as f32 ) ) * 100.0
171
182
) ?;
172
183
}
173
- assert_eq ! ( total_commits, all_commits. len( ) as u32 , "need to get all commits" ) ;
184
+ if ignored_bot_commits != 0 {
185
+ writeln ! ( out, "commits by bots: {}" , ignored_bot_commits, ) ?;
186
+ }
187
+ assert_eq ! (
188
+ total_commits,
189
+ all_commits. len( ) as u32 - ignored_bot_commits,
190
+ "need to get all commits"
191
+ ) ;
174
192
Ok ( ( ) )
175
193
}
176
194
0 commit comments