4
4
use crate :: { config:: NoMentionsConfig , github:: GithubCommit } ;
5
5
6
6
pub ( super ) fn mentions_in_commits (
7
- _conf : & NoMentionsConfig ,
7
+ pr_title : & str ,
8
+ conf : & NoMentionsConfig ,
8
9
commits : & [ GithubCommit ] ,
9
10
) -> Option < String > {
11
+ if conf
12
+ . exclude_titles
13
+ . iter ( )
14
+ . any ( |s| pr_title. to_lowercase ( ) . contains ( & s. to_lowercase ( ) ) )
15
+ {
16
+ return None ;
17
+ }
18
+
10
19
let mentions_commits = commits
11
20
. into_iter ( )
12
- . filter ( |c| !parser:: get_mentions ( & c. commit . message ) . is_empty ( ) )
21
+ . filter ( |c| {
22
+ let mentions = parser:: get_mentions ( & c. commit . message ) ;
23
+ !mentions. is_empty ( ) && mentions. iter ( ) . any ( |m| * m != "rustbot" )
24
+ } )
13
25
. map ( |c| format ! ( "- {}\n " , c. sha) )
14
26
. collect :: < String > ( ) ;
15
27
@@ -33,7 +45,14 @@ fn test_mentions_in_commits() {
33
45
"This is simple without mentions!" ,
34
46
) ] ;
35
47
36
- assert_eq ! ( mentions_in_commits( & NoMentionsConfig { } , & commits) , None ) ;
48
+ let default_conf = NoMentionsConfig {
49
+ exclude_titles : vec ! [ ] ,
50
+ } ;
51
+
52
+ assert_eq ! (
53
+ mentions_in_commits( "any title" , & default_conf, & commits) ,
54
+ None
55
+ ) ;
37
56
38
57
commits. push ( dummy_commit_from_body (
39
58
"10b96a74c484cae79164cbbcdfcd412109e0e4cf" ,
42
61
Co-authored-by: Baz Qux <[email protected] >" ,
43
62
) ) ;
44
63
45
- assert_eq ! ( mentions_in_commits( & NoMentionsConfig { } , & commits) , None ) ;
64
+ assert_eq ! (
65
+ mentions_in_commits( "any title" , & default_conf, & commits, ) ,
66
+ None
67
+ ) ;
46
68
47
69
commits. push ( dummy_commit_from_body (
48
- "d7daa17bc97df9377640b0d33cbd0bbeed703c3a" ,
49
- "This is a body with a @mention!" ,
70
+ "6565ffdd8af4ca0ec7c8faceee59c582edcd83b2" ,
71
+ "This is a body that only mentions @rustbot for a command!" ,
72
+ ) ) ;
73
+
74
+ assert_eq ! (
75
+ mentions_in_commits( "any title" , & default_conf, & commits) ,
76
+ None
77
+ ) ;
78
+
79
+ commits. push ( dummy_commit_from_body (
80
+ "4894129179b361200c9cd733ba0e906bf98747a2" ,
81
+ "This is a body that mentions @rustbot for a command! And then a user @mention" ,
50
82
) ) ;
51
83
52
84
assert_eq ! (
53
- mentions_in_commits( & NoMentionsConfig { } , & commits) ,
85
+ mentions_in_commits( "any title" , & default_conf , & commits, ) ,
54
86
Some (
55
87
r"There are username mentions (such as `@user`) in the commit messages of the following commits.
56
88
*Please remove the mentions to avoid spamming these users.*
57
- - d7daa17bc97df9377640b0d33cbd0bbeed703c3a
89
+ - 4894129179b361200c9cd733ba0e906bf98747a2
58
90
" . to_string( )
59
91
)
60
92
) ;
93
+
94
+ let _ = commits. pop ( ) ; // Remove that @rustbot & @mention case
95
+
96
+ commits. push ( dummy_commit_from_body (
97
+ "d7daa17bc97df9377640b0d33cbd0bbeed703c3a" ,
98
+ "This is a body with a @mention!" ,
99
+ ) ) ;
100
+
101
+ assert_eq ! (
102
+ mentions_in_commits(
103
+ "exclude this pull from checking " ,
104
+ & NoMentionsConfig {
105
+ exclude_titles: vec![ String :: from( "exclude this" ) ]
106
+ } ,
107
+ & commits
108
+ ) ,
109
+ None
110
+ ) ;
61
111
}
0 commit comments