Skip to content

Commit 9f8c61b

Browse files
committed
Don't ping everyone on rebase mistakes
1 parent 987ad86 commit 9f8c61b

File tree

3 files changed

+79
-18
lines changed

3 files changed

+79
-18
lines changed

src/config.rs

+39
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,10 @@ pub(crate) struct NoteConfig {
105105
}
106106

107107
#[derive(PartialEq, Eq, Debug, serde::Deserialize)]
108+
#[serde(rename_all = "kebab-case")]
108109
pub(crate) struct MentionsConfig {
110+
#[serde(default)]
111+
pub(crate) bors_commit_message: String,
109112
#[serde(flatten)]
110113
pub(crate) paths: HashMap<String, MentionsPathConfig>,
111114
}
@@ -398,4 +401,40 @@ mod tests {
398401
}
399402
);
400403
}
404+
405+
#[test]
406+
fn mentions_config() {
407+
let config = r#"
408+
[mentions."some_other_path"]
409+
message = "foo"
410+
cc = ["@someone"]
411+
412+
[mentions]
413+
bors-commit-message = "has bors commit"
414+
"#;
415+
let config = toml::from_str::<Config>(config).unwrap().mentions.unwrap();
416+
assert!(config.paths.len() == 1);
417+
assert_eq!(config.bors_commit_message, "has bors commit");
418+
419+
let config = r#"
420+
[mentions]
421+
bors-commit-message = "has bors commit"
422+
423+
[mentions."some_other_path"]
424+
message = "foo"
425+
cc = ["@someone"]
426+
"#;
427+
let config = toml::from_str::<Config>(config).unwrap().mentions.unwrap();
428+
assert!(config.paths.len() == 1);
429+
assert_eq!(config.bors_commit_message, "has bors commit");
430+
431+
let config = r#"
432+
[mentions."some_other_path"]
433+
message = "foo"
434+
cc = ["@someone"]
435+
"#;
436+
let config = toml::from_str::<Config>(config).unwrap().mentions.unwrap();
437+
assert!(config.paths.len() == 1);
438+
assert_eq!(config.bors_commit_message, "");
439+
}
401440
}

src/github.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1594,6 +1594,7 @@ pub struct GitCommit {
15941594

15951595
#[derive(Debug, serde::Deserialize)]
15961596
pub struct GitUser {
1597+
pub name: String,
15971598
pub date: DateTime<FixedOffset>,
15981599
}
15991600

src/handlers/mentions.rs

+39-18
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ use tracing as log;
1616

1717
const MENTIONS_KEY: &str = "mentions";
1818

19-
pub(super) struct MentionsInput {
20-
paths: Vec<String>,
19+
pub(super) enum MentionsInput {
20+
HasBorsCommit,
21+
Paths(Vec<String>),
2122
}
2223

2324
#[derive(Debug, Default, Deserialize, Serialize)]
@@ -50,6 +51,19 @@ pub(super) async fn parse_input(
5051
return Ok(None);
5152
}
5253

54+
// Don't ping if a bors commit is included - send a warning message instead
55+
if event
56+
.issue
57+
.commits(&ctx.github)
58+
.await
59+
.map_err(|e| log::error!("failed to fetch commits: {:?}", e))
60+
.unwrap_or_default()
61+
.into_iter()
62+
.any(|commit| commit.commit.author.name == "bors")
63+
{
64+
return Ok(Some(MentionsInput::HasBorsCommit));
65+
}
66+
5367
if let Some(diff) = event
5468
.issue
5569
.diff(&ctx.github)
@@ -78,7 +92,7 @@ pub(super) async fn parse_input(
7892
.map(|(key, _mention)| key.to_string())
7993
.collect();
8094
if !to_mention.is_empty() {
81-
return Ok(Some(MentionsInput { paths: to_mention }));
95+
return Ok(Some(MentionsInput::Paths(to_mention)));
8296
}
8397
}
8498
Ok(None)
@@ -95,23 +109,30 @@ pub(super) async fn handle_input(
95109
IssueData::load(&mut client, &event.issue, MENTIONS_KEY).await?;
96110
// Build the message to post to the issue.
97111
let mut result = String::new();
98-
for to_mention in &input.paths {
99-
if state.data.paths.iter().any(|p| p == to_mention) {
100-
// Avoid duplicate mentions.
101-
continue;
102-
}
103-
let MentionsPathConfig { message, cc } = &config.paths[to_mention];
104-
if !result.is_empty() {
105-
result.push_str("\n\n");
106-
}
107-
match message {
108-
Some(m) => result.push_str(m),
109-
None => write!(result, "Some changes occurred in {to_mention}").unwrap(),
112+
match input {
113+
MentionsInput::HasBorsCommit => {
114+
result = config.bors_commit_message.to_string();
110115
}
111-
if !cc.is_empty() {
112-
write!(result, "\n\ncc {}", cc.join(", ")).unwrap();
116+
MentionsInput::Paths(paths) => {
117+
for to_mention in &paths {
118+
if state.data.paths.iter().any(|p| p == to_mention) {
119+
// Avoid duplicate mentions.
120+
continue;
121+
}
122+
let MentionsPathConfig { message, cc } = &config.paths[to_mention];
123+
if !result.is_empty() {
124+
result.push_str("\n\n");
125+
}
126+
match message {
127+
Some(m) => result.push_str(m),
128+
None => write!(result, "Some changes occurred in {to_mention}").unwrap(),
129+
}
130+
if !cc.is_empty() {
131+
write!(result, "\n\ncc {}", cc.join(", ")).unwrap();
132+
}
133+
state.data.paths.push(to_mention.to_string());
134+
}
113135
}
114-
state.data.paths.push(to_mention.to_string());
115136
}
116137
if !result.is_empty() {
117138
event

0 commit comments

Comments
 (0)