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