44use crate :: { config:: NoMentionsConfig , github:: GithubCommit } ;
55
66pub ( super ) fn mentions_in_commits (
7- _conf : & NoMentionsConfig ,
7+ pr_title : & str ,
8+ conf : & NoMentionsConfig ,
89 commits : & [ GithubCommit ] ,
910) -> 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+
1019 let mentions_commits = commits
1120 . 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+ } )
1325 . map ( |c| format ! ( "- {}\n " , c. sha) )
1426 . collect :: < String > ( ) ;
1527
@@ -33,7 +45,14 @@ fn test_mentions_in_commits() {
3345 "This is simple without mentions!" ,
3446 ) ] ;
3547
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+ ) ;
3756
3857 commits. push ( dummy_commit_from_body (
3958 "10b96a74c484cae79164cbbcdfcd412109e0e4cf" ,
@@ -42,20 +61,51 @@ Signed-off-by: Foo Bar <foobar123@example.com>
4261Co-authored-by: Baz Qux <bazqux@example.com>" ,
4362 ) ) ;
4463
45- assert_eq ! ( mentions_in_commits( & NoMentionsConfig { } , & commits) , None ) ;
64+ assert_eq ! (
65+ mentions_in_commits( "any title" , & default_conf, & commits, ) ,
66+ None
67+ ) ;
4668
4769 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" ,
5082 ) ) ;
5183
5284 assert_eq ! (
53- mentions_in_commits( & NoMentionsConfig { } , & commits) ,
85+ mentions_in_commits( "any title" , & default_conf , & commits, ) ,
5486 Some (
5587 r"There are username mentions (such as `@user`) in the commit messages of the following commits.
5688*Please remove the mentions to avoid spamming these users.*
57- - d7daa17bc97df9377640b0d33cbd0bbeed703c3a
89+ - 4894129179b361200c9cd733ba0e906bf98747a2
5890" . to_string( )
5991 )
6092 ) ;
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+ ) ;
61111}
0 commit comments