Skip to content

Commit 63ae02e

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

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

src/github.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,8 @@ pub struct Issue {
408408
// User performing an `action` (or PR/issue author)
409409
pub user: User,
410410
pub labels: Vec<Label>,
411-
// Users assigned to the issue/pr after `action` has been performed
411+
// Users assigned to the issue/pr after `action` has been performed issue
412+
// (PR reviewers or issue assignees)
412413
// These are NOT the same as `IssueEvent.assignee`
413414
pub assignees: Vec<User>,
414415
/// Indicator if this is a pull request.

src/handlers/notify_zulip.rs

Lines changed: 35 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 {
@@ -214,10 +217,15 @@ pub(super) async fn handle_input<'a>(
214217
topic: &topic,
215218
};
216219

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+
217224
for msg in msgs {
218225
let msg = msg.replace("{number}", &event.issue.number.to_string());
219226
let msg = msg.replace("{title}", &event.issue.title);
220227
let msg = replace_team_to_be_nominated(&event.issue.labels, msg);
228+
let msg = msg.replace("{recipients}", &get_zulip_ids(ctx, &recipients).await);
221229

222230
let req = crate::zulip::MessageApiRequest {
223231
recipient,
@@ -236,6 +244,33 @@ pub(super) async fn handle_input<'a>(
236244
Ok(())
237245
}
238246

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
239274
fn replace_team_to_be_nominated(labels: &[Label], msg: String) -> String {
240275
let teams = labels
241276
.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)