Skip to content

Commit 66da374

Browse files
committed
Do not comment if only rustbot is pinged in a commit message
1 parent 6991b23 commit 66da374

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

src/handlers/check_commits/no_mentions.rs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ pub(super) fn mentions_in_commits(
99
) -> Option<String> {
1010
let mentions_commits = commits
1111
.into_iter()
12-
.filter(|c| !parser::get_mentions(&c.commit.message).is_empty())
12+
.filter(|c| {
13+
let mentions = parser::get_mentions(&c.commit.message);
14+
!mentions.is_empty() && mentions.iter().any(|m| *m != "rustbot")
15+
})
1316
.map(|c| format!("- {}\n", c.sha))
1417
.collect::<String>();
1518

@@ -44,6 +47,30 @@ Co-authored-by: Baz Qux <[email protected]>",
4447

4548
assert_eq!(mentions_in_commits(&NoMentionsConfig {}, &commits), None);
4649

50+
commits.push(dummy_commit_from_body(
51+
"6565ffdd8af4ca0ec7c8faceee59c582edcd83b2",
52+
"This is a body that only mentions @rustbot for a command!",
53+
));
54+
55+
assert_eq!(mentions_in_commits(&NoMentionsConfig {}, &commits), None);
56+
57+
commits.push(dummy_commit_from_body(
58+
"6565ffdd8af4ca0ec7c8faceee59c582edcd83b2",
59+
"This is a body that mentions @rustbot for a command! And then a user @mention",
60+
));
61+
62+
assert_eq!(
63+
mentions_in_commits(&NoMentionsConfig {}, &commits),
64+
Some(
65+
r"There are username mentions (such as `@user`) in the commit messages of the following commits.
66+
*Please remove the mentions to avoid spamming these users.*
67+
- 6565ffdd8af4ca0ec7c8faceee59c582edcd83b2
68+
".to_string()
69+
)
70+
);
71+
72+
let _ = commits.pop(); // Remove that @rustbot & @mention case
73+
4774
commits.push(dummy_commit_from_body(
4875
"d7daa17bc97df9377640b0d33cbd0bbeed703c3a",
4976
"This is a body with a @mention!",

0 commit comments

Comments
 (0)