Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure team nominate label in prioritization alerts on Zulip #1766

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions src/handlers/notify_zulip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ pub(super) async fn handle_input<'a>(
for msg in msgs {
let msg = msg.replace("{number}", &event.issue.number.to_string());
let msg = msg.replace("{title}", &event.issue.title);
let msg = replace_team_to_be_nominated(&event.issue.labels, msg);

crate::zulip::MessageApiRequest {
recipient,
Expand All @@ -179,3 +180,66 @@ pub(super) async fn handle_input<'a>(

Ok(())
}

fn replace_team_to_be_nominated(labels: &[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 let [team] = &*teams {
msg.replace("{team}", team)
} else if teams.contains(&"compiler") {
msg.replace("{team}", "compiler")
} else {
msg
}
}

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

msg = replace_team_to_be_nominated(
&[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(
&[
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(
&[
Label {
name: "T-libs".to_string(),
},
Label {
name: "T-cooks".to_string(),
},
],
"Needs `I-{team}-nominated`?".to_string(),
);
assert!(msg.contains("Needs `I-{team}-nominated`?"), "{}", msg);
}
Loading