Skip to content

Commit 379832d

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

File tree

3 files changed

+74
-1
lines changed

3 files changed

+74
-1
lines changed

src/config.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ 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+
pub(crate) bors_commit_message: Option<String>,
109111
#[serde(flatten)]
110112
pub(crate) paths: HashMap<String, MentionsPathConfig>,
111113
}
@@ -398,4 +400,46 @@ mod tests {
398400
}
399401
);
400402
}
403+
404+
#[test]
405+
fn mentions_config() {
406+
let config = r#"
407+
[mentions."some_other_path"]
408+
message = "foo"
409+
cc = ["@someone"]
410+
411+
[mentions]
412+
bors-commit-message = "has bors commit"
413+
"#;
414+
let config = toml::from_str::<Config>(config).unwrap().mentions.unwrap();
415+
assert!(config.paths.len() == 1);
416+
assert_eq!(
417+
config.bors_commit_message.as_deref(),
418+
Some("has bors commit")
419+
);
420+
421+
let config = r#"
422+
[mentions]
423+
bors-commit-message = "has bors commit"
424+
425+
[mentions."some_other_path"]
426+
message = "foo"
427+
cc = ["@someone"]
428+
"#;
429+
let config = toml::from_str::<Config>(config).unwrap().mentions.unwrap();
430+
assert!(config.paths.len() == 1);
431+
assert_eq!(
432+
config.bors_commit_message.as_deref(),
433+
Some("has bors commit")
434+
);
435+
436+
let config = r#"
437+
[mentions."some_other_path"]
438+
message = "foo"
439+
cc = ["@someone"]
440+
"#;
441+
let config = toml::from_str::<Config>(config).unwrap().mentions.unwrap();
442+
assert!(config.paths.len() == 1);
443+
assert_eq!(config.bors_commit_message, None);
444+
}
401445
}

src/github.rs

Lines changed: 1 addition & 0 deletions
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

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use tracing as log;
1717
const MENTIONS_KEY: &str = "mentions";
1818

1919
pub(super) struct MentionsInput {
20+
has_bors_commit: bool,
2021
paths: Vec<String>,
2122
}
2223

@@ -50,6 +51,17 @@ pub(super) async fn parse_input(
5051
return Ok(None);
5152
}
5253

54+
let has_bors_commit = event.action == IssuesAction::Opened
55+
&& config.bors_commit_message.is_some()
56+
&& event
57+
.issue
58+
.commits(&ctx.github)
59+
.await
60+
.map_err(|e| log::error!("failed to fetch commits: {:?}", e))
61+
.unwrap_or_default()
62+
.into_iter()
63+
.any(|commit| commit.commit.author.name == "bors");
64+
5365
if let Some(diff) = event
5466
.issue
5567
.diff(&ctx.github)
@@ -78,7 +90,10 @@ pub(super) async fn parse_input(
7890
.map(|(key, _mention)| key.to_string())
7991
.collect();
8092
if !to_mention.is_empty() {
81-
return Ok(Some(MentionsInput { paths: to_mention }));
93+
return Ok(Some(MentionsInput {
94+
has_bors_commit,
95+
paths: to_mention,
96+
}));
8297
}
8398
}
8499
Ok(None)
@@ -95,6 +110,14 @@ pub(super) async fn handle_input(
95110
IssueData::load(&mut client, &event.issue, MENTIONS_KEY).await?;
96111
// Build the message to post to the issue.
97112
let mut result = String::new();
113+
if input.has_bors_commit {
114+
write!(
115+
result,
116+
"{}\n",
117+
config.bors_commit_message.as_deref().unwrap()
118+
)
119+
.unwrap();
120+
}
98121
for to_mention in &input.paths {
99122
if state.data.paths.iter().any(|p| p == to_mention) {
100123
// Avoid duplicate mentions.
@@ -109,6 +132,11 @@ pub(super) async fn handle_input(
109132
None => write!(result, "Some changes occurred in {to_mention}").unwrap(),
110133
}
111134
if !cc.is_empty() {
135+
let cc: Vec<String> = if input.has_bors_commit {
136+
cc.iter().map(|s| format!("`{s}`")).collect()
137+
} else {
138+
cc.to_owned()
139+
};
112140
write!(result, "\n\ncc {}", cc.join(", ")).unwrap();
113141
}
114142
state.data.paths.push(to_mention.to_string());

0 commit comments

Comments
 (0)