Skip to content

Commit

Permalink
Configure team in prioritization alerts on Zulip
Browse files Browse the repository at this point in the history
  • Loading branch information
apiraino committed Apr 8, 2024
1 parent c6fa165 commit bf17d70
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions src/handlers/notify_zulip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ pub(super) async fn handle_input<'a>(

msg = msg.replace("{number}", &event.issue.number.to_string());
msg = msg.replace("{title}", &event.issue.title);
msg = replace_team_to_be_nominated(&event.issue.labels, msg);

let zulip_req = crate::zulip::MessageApiRequest {
recipient: crate::zulip::Recipient::Stream {
Expand All @@ -172,3 +173,66 @@ pub(super) async fn handle_input<'a>(

Ok(())
}

fn replace_team_to_be_nominated(labels: &Vec<Label>, msg: String) -> String {
let teams = labels
.iter()
.map(|label| &label.name)
.filter_map(|label| label.strip_prefix("T-"))
.collect::<Vec<&str>>();

// - If a single team label is found, replace the placeholder with that one
// - If multiple team labels are found and one of them is "compiler", pick that one
// (currently the only team handling these Zulip notification)
// - else, do nothing
if teams.len() == 1 {
msg.replace("{team}", teams[0])
} else if teams.contains(&"compiler") {
msg.replace("{team}", "compiler")
} else {
msg
}
}

#[test]
fn test_notification() {
let mut msg = replace_team_to_be_nominated(&vec![], "Needs `I-{team}-nominated`?".to_string());
assert!(msg.contains("Issue needs to be nominated?"), "{}", msg);

msg = replace_team_to_be_nominated(
&vec![Label {
name: "T-cooks".to_string(),
}],
"Needs `I-{team}-nominated`?".to_string(),
);
assert!(msg.contains("I-cooks-nominated"), "{}", msg);

msg = replace_team_to_be_nominated(
&vec![
Label {
name: "T-compiler".to_string(),
},
Label {
name: "T-libs".to_string(),
},
Label {
name: "T-cooks".to_string(),
},
],
"Needs `I-{team}-nominated`?".to_string(),
);
assert!(msg.contains("I-compiler-nominated"), "{}", msg);

msg = replace_team_to_be_nominated(
&vec![
Label {
name: "T-libs".to_string(),
},
Label {
name: "T-cooks".to_string(),
},
],
"Needs `I-{team}-nominated`?".to_string(),
);
assert!(msg.contains("Issue needs to be nominated?"), "{}", msg);
}

0 comments on commit bf17d70

Please sign in to comment.