@@ -167,6 +167,7 @@ pub(super) async fn handle_input<'a>(
167
167
for msg in msgs {
168
168
let msg = msg. replace ( "{number}" , & event. issue . number . to_string ( ) ) ;
169
169
let msg = msg. replace ( "{title}" , & event. issue . title ) ;
170
+ let msg = replace_team_to_be_nominated ( & event. issue . labels , msg) ;
170
171
171
172
crate :: zulip:: MessageApiRequest {
172
173
recipient,
@@ -179,3 +180,66 @@ pub(super) async fn handle_input<'a>(
179
180
180
181
Ok ( ( ) )
181
182
}
183
+
184
+ fn replace_team_to_be_nominated ( labels : & [ Label ] , msg : String ) -> String {
185
+ let teams = labels
186
+ . iter ( )
187
+ . map ( |label| & label. name )
188
+ . filter_map ( |label| label. strip_prefix ( "T-" ) )
189
+ . collect :: < Vec < & str > > ( ) ;
190
+
191
+ // - If a single team label is found, replace the placeholder with that one
192
+ // - If multiple team labels are found and one of them is "compiler", pick that one
193
+ // (currently the only team handling these Zulip notification)
194
+ // - else, do nothing
195
+ if let [ team] = & * teams {
196
+ msg. replace ( "{team}" , team)
197
+ } else if teams. contains ( & "compiler" ) {
198
+ msg. replace ( "{team}" , "compiler" )
199
+ } else {
200
+ msg
201
+ }
202
+ }
203
+
204
+ #[ test]
205
+ fn test_notification ( ) {
206
+ let mut msg = replace_team_to_be_nominated ( & [ ] , "Needs `I-{team}-nominated`?" . to_string ( ) ) ;
207
+ assert ! ( msg. contains( "Needs `I-{team}-nominated`?" ) , "{}" , msg) ;
208
+
209
+ msg = replace_team_to_be_nominated (
210
+ & [ Label {
211
+ name : "T-cooks" . to_string ( ) ,
212
+ } ] ,
213
+ "Needs `I-{team}-nominated`?" . to_string ( ) ,
214
+ ) ;
215
+ assert ! ( msg. contains( "I-cooks-nominated" ) , "{}" , msg) ;
216
+
217
+ msg = replace_team_to_be_nominated (
218
+ & [
219
+ Label {
220
+ name : "T-compiler" . to_string ( ) ,
221
+ } ,
222
+ Label {
223
+ name : "T-libs" . to_string ( ) ,
224
+ } ,
225
+ Label {
226
+ name : "T-cooks" . to_string ( ) ,
227
+ } ,
228
+ ] ,
229
+ "Needs `I-{team}-nominated`?" . to_string ( ) ,
230
+ ) ;
231
+ assert ! ( msg. contains( "I-compiler-nominated" ) , "{}" , msg) ;
232
+
233
+ msg = replace_team_to_be_nominated (
234
+ & [
235
+ Label {
236
+ name : "T-libs" . to_string ( ) ,
237
+ } ,
238
+ Label {
239
+ name : "T-cooks" . to_string ( ) ,
240
+ } ,
241
+ ] ,
242
+ "Needs `I-{team}-nominated`?" . to_string ( ) ,
243
+ ) ;
244
+ assert ! ( msg. contains( "Needs `I-{team}-nominated`?" ) , "{}" , msg) ;
245
+ }
0 commit comments