Skip to content

Commit f4c2231

Browse files
committed
Turn automatic backport nominations into suggestions
1 parent 24d215a commit f4c2231

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/handlers/notify_zulip.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
use crate::github::User;
12
use crate::zulip::api::Recipient;
3+
use crate::zulip::render_zulip_username;
24
use crate::{
35
config::{NotifyZulipConfig, NotifyZulipLabelConfig, NotifyZulipTablesConfig},
46
github::{Issue, IssuesAction, IssuesEvent, Label},
57
handlers::Context,
68
};
9+
use futures::future::join_all;
710
use tracing as log;
811

912
pub(super) struct NotifyZulipInput {
@@ -218,6 +221,10 @@ pub(super) async fn handle_input<'a>(
218221
let msg = msg.replace("{number}", &event.issue.number.to_string());
219222
let msg = msg.replace("{title}", &event.issue.title);
220223
let msg = replace_team_to_be_nominated(&event.issue.labels, msg);
224+
let msg = msg.replace(
225+
"{reviewers}",
226+
&retrieve_zulip_ids(ctx, &event.issue.assignees).await,
227+
);
221228

222229
let req = crate::zulip::MessageApiRequest {
223230
recipient,
@@ -236,6 +243,24 @@ pub(super) async fn handle_input<'a>(
236243
Ok(())
237244
}
238245

246+
/// Retrieve Zulip IDs for PR assignees
247+
async fn retrieve_zulip_ids(ctx: &Context, assignees: &[User]) -> String {
248+
let gh_ids_fut = assignees
249+
.iter()
250+
.map(|reviewer| async move { ctx.team.github_to_zulip_id(reviewer.id).await });
251+
let zulip_ids = join_all(gh_ids_fut).await;
252+
253+
zulip_ids
254+
.iter()
255+
.map(|x| {
256+
let id = x.as_ref().unwrap().unwrap();
257+
render_zulip_username(id)
258+
})
259+
.collect::<Vec<String>>()
260+
.join(", cc: ")
261+
}
262+
263+
/// Replace the placeholder "{team}" with the correct team name
239264
fn replace_team_to_be_nominated(labels: &[Label], msg: String) -> String {
240265
let teams = labels
241266
.iter()

src/zulip.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,7 @@ async fn lookup_github_username(ctx: &Context, zulip_username: &str) -> anyhow::
708708
))
709709
}
710710

711-
fn render_zulip_username(zulip_id: u64) -> String {
711+
pub fn render_zulip_username(zulip_id: u64) -> String {
712712
// Rendering the username directly was running into some encoding issues, so we use
713713
// the special `|<user-id>` syntax instead.
714714
// @**|<zulip-id>** is Zulip syntax that will render as the username (and a link) of the user

0 commit comments

Comments
 (0)