Skip to content

Commit 24668d2

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

File tree

3 files changed

+84
-18
lines changed

3 files changed

+84
-18
lines changed

src/config.rs

+44
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

+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.clone().unwrap_or_default();
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)