Skip to content

Commit bfc7964

Browse files
authored
Merge pull request #2137 from blyxyas/no-notify-on-triagebot-pings
Add `exclude-titles` option to no-mentions
2 parents 480a7ba + cb79f88 commit bfc7964

File tree

3 files changed

+73
-11
lines changed

3 files changed

+73
-11
lines changed

src/config.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,12 @@ pub(crate) struct IssueLinksConfig {
516516
#[derive(PartialEq, Eq, Debug, serde::Deserialize)]
517517
#[serde(rename_all = "kebab-case")]
518518
#[serde(deny_unknown_fields)]
519-
pub(crate) struct NoMentionsConfig {}
519+
pub(crate) struct NoMentionsConfig {
520+
/// The check will not be performed on titles that include any of these substrings (case
521+
/// insensitive)
522+
#[serde(default)]
523+
pub(crate) exclude_titles: Vec<String>,
524+
}
520525

521526
/// Configuration for PR behind commits checks
522527
#[derive(PartialEq, Eq, Debug, serde::Deserialize)]
@@ -688,6 +693,7 @@ mod tests {
688693
trigger-files = ["posts/"]
689694
690695
[no-mentions]
696+
exclude-titles = ["subtree update"]
691697
692698
[behind-upstream]
693699
days-threshold = 14
@@ -778,7 +784,9 @@ mod tests {
778784
issue_links: Some(IssueLinksConfig {
779785
check_commits: true,
780786
}),
781-
no_mentions: Some(NoMentionsConfig {}),
787+
no_mentions: Some(NoMentionsConfig {
788+
exclude_titles: vec!["subtree update".into()],
789+
}),
782790
behind_upstream: Some(BehindUpstreamConfig {
783791
days_threshold: Some(14),
784792
}),

src/handlers/check_commits.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,11 @@ pub(super) async fn handle(
112112
}
113113

114114
if let Some(no_mentions) = &config.no_mentions {
115-
warnings.extend(no_mentions::mentions_in_commits(no_mentions, &commits));
115+
warnings.extend(no_mentions::mentions_in_commits(
116+
&event.issue.title,
117+
no_mentions,
118+
&commits,
119+
));
116120
}
117121

118122
if let Some(issue_links) = &config.issue_links {

src/handlers/check_commits/no_mentions.rs

Lines changed: 58 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,24 @@
44
use crate::{config::NoMentionsConfig, github::GithubCommit};
55

66
pub(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 <[email protected]>
4261
Co-authored-by: Baz Qux <[email protected]>",
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

Comments
 (0)