Skip to content

Commit d50a53c

Browse files
committed
Configure team in prioritization alerts on Zulip
1 parent c6fa165 commit d50a53c

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

src/handlers/notify_zulip.rs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ pub(super) async fn handle_input<'a>(
159159

160160
msg = msg.replace("{number}", &event.issue.number.to_string());
161161
msg = msg.replace("{title}", &event.issue.title);
162+
msg = replace_team_to_be_nominated(&event.issue.labels, msg);
162163

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

173174
Ok(())
174175
}
176+
177+
fn replace_team_to_be_nominated(labels: &Vec<Label>, msg: String) -> String {
178+
let teams = labels
179+
.iter()
180+
.map(|label| &label.name)
181+
.filter_map(|label| label.strip_prefix("T-"))
182+
.collect::<Vec<&str>>();
183+
184+
// - If a single team label is found, replace the placeholder with that one
185+
// - If multiple team labels are found and one of them is "compiler", pick that one
186+
// (currently the only team handling these Zulip notification)
187+
// - else, do nothing
188+
if teams.len() == 1 {
189+
msg.replace("{team}", teams[0])
190+
} else if teams.contains(&"compiler") {
191+
msg.replace("{team}", "compiler")
192+
} else {
193+
msg
194+
}
195+
}
196+
197+
#[test]
198+
fn test_notification() {
199+
let mut msg = replace_team_to_be_nominated(&vec![], "Needs `I-{team}-nominated`?".to_string());
200+
assert!(msg.contains("Needs `I-{team}-nominated`?"), "{}", msg);
201+
202+
msg = replace_team_to_be_nominated(
203+
&vec![Label {
204+
name: "T-cooks".to_string(),
205+
}],
206+
"Needs `I-{team}-nominated`?".to_string(),
207+
);
208+
assert!(msg.contains("I-cooks-nominated"), "{}", msg);
209+
210+
msg = replace_team_to_be_nominated(
211+
&vec![
212+
Label {
213+
name: "T-compiler".to_string(),
214+
},
215+
Label {
216+
name: "T-libs".to_string(),
217+
},
218+
Label {
219+
name: "T-cooks".to_string(),
220+
},
221+
],
222+
"Needs `I-{team}-nominated`?".to_string(),
223+
);
224+
assert!(msg.contains("I-compiler-nominated"), "{}", msg);
225+
226+
msg = replace_team_to_be_nominated(
227+
&vec![
228+
Label {
229+
name: "T-libs".to_string(),
230+
},
231+
Label {
232+
name: "T-cooks".to_string(),
233+
},
234+
],
235+
"Needs `I-{team}-nominated`?".to_string(),
236+
);
237+
assert!(msg.contains("Needs `I-{team}-nominated`?"), "{}", msg);
238+
}

0 commit comments

Comments
 (0)