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. exclude_titles . iter ( ) . any ( |s| pr_title. contains ( s) ) {
12+ return None ;
13+ }
14+
1015 let mentions_commits = commits
1116 . 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+ } )
1321 . map ( |c| format ! ( "- {}\n " , c. sha) )
1422 . collect :: < String > ( ) ;
1523
@@ -33,7 +41,14 @@ fn test_mentions_in_commits() {
3341 "This is simple without mentions!" ,
3442 ) ] ;
3543
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+ ) ;
3752
3853 commits. push ( dummy_commit_from_body (
3954 "10b96a74c484cae79164cbbcdfcd412109e0e4cf" ,
4257Co-authored-by: Baz Qux <[email protected] >" , 4358 ) ) ;
4459
45- assert_eq ! ( mentions_in_commits( & NoMentionsConfig { } , & commits) , None ) ;
60+ assert_eq ! (
61+ mentions_in_commits( "any title" , & default_conf, & commits, ) ,
62+ None
63+ ) ;
4664
4765 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" ,
5078 ) ) ;
5179
5280 assert_eq ! (
53- mentions_in_commits( & NoMentionsConfig { } , & commits) ,
81+ mentions_in_commits( "any title" , & default_conf , & commits, ) ,
5482 Some (
5583 r"There are username mentions (such as `@user`) in the commit messages of the following commits.
5684*Please remove the mentions to avoid spamming these users.*
57- - d7daa17bc97df9377640b0d33cbd0bbeed703c3a
85+ - 6565ffdd8af4ca0ec7c8faceee59c582edcd83b2
5886" . to_string( )
5987 )
6088 ) ;
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+ ) ;
61107}
0 commit comments