1
+ use crate :: github:: User ;
1
2
use crate :: zulip:: api:: Recipient ;
3
+ use crate :: zulip:: render_zulip_username;
2
4
use crate :: {
3
5
config:: { NotifyZulipConfig , NotifyZulipLabelConfig , NotifyZulipTablesConfig } ,
4
6
github:: { Issue , IssuesAction , IssuesEvent , Label } ,
5
7
handlers:: Context ,
6
8
} ;
9
+ use futures:: future:: join_all;
7
10
use tracing as log;
8
11
9
12
pub ( super ) struct NotifyZulipInput {
@@ -214,10 +217,15 @@ pub(super) async fn handle_input<'a>(
214
217
topic : & topic,
215
218
} ;
216
219
220
+ // Issue/PR authors/reviewers will receive a mention if the template has `{recipients}`.
221
+ let recipients = & mut event. issue . assignees . clone ( ) ;
222
+ recipients. push ( event. issue . user . clone ( ) ) ;
223
+
217
224
for msg in msgs {
218
225
let msg = msg. replace ( "{number}" , & event. issue . number . to_string ( ) ) ;
219
226
let msg = msg. replace ( "{title}" , & event. issue . title ) ;
220
227
let msg = replace_team_to_be_nominated ( & event. issue . labels , msg) ;
228
+ let msg = msg. replace ( "{recipients}" , & get_zulip_ids ( ctx, & recipients) . await ) ;
221
229
222
230
let req = crate :: zulip:: MessageApiRequest {
223
231
recipient,
@@ -236,6 +244,33 @@ pub(super) async fn handle_input<'a>(
236
244
Ok ( ( ) )
237
245
}
238
246
247
+ async fn get_zulip_ids ( ctx : & Context , recipients : & [ User ] ) -> String {
248
+ let gh_ids_fut = recipients
249
+ . iter ( )
250
+ . map ( |recipient| async move { ctx. team . github_to_zulip_id ( recipient. id ) . await } ) ;
251
+ let zulip_ids = join_all ( gh_ids_fut) . await ;
252
+
253
+ let zulip_ids = zulip_ids
254
+ . iter ( )
255
+ . filter_map ( |x| {
256
+ if let Ok ( id2) = x. as_ref ( )
257
+ && let Some ( id) = * id2
258
+ {
259
+ Some ( render_zulip_username ( id) )
260
+ } else {
261
+ None
262
+ }
263
+ } )
264
+ . collect :: < Vec < String > > ( ) ;
265
+
266
+ if !zulip_ids. is_empty ( ) {
267
+ zulip_ids. join ( ", " )
268
+ } else {
269
+ "" . to_string ( )
270
+ }
271
+ }
272
+
273
+ /// Replace the placeholder "{team}" with the correct team name
239
274
fn replace_team_to_be_nominated ( labels : & [ Label ] , msg : String ) -> String {
240
275
let teams = labels
241
276
. iter ( )
0 commit comments