-
Notifications
You must be signed in to change notification settings - Fork 97
Turn automatic backport nominations into suggestions #2191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
use crate::github::User; | ||
use crate::zulip::api::Recipient; | ||
use crate::zulip::render_zulip_username; | ||
use crate::{ | ||
config::{NotifyZulipConfig, NotifyZulipLabelConfig, NotifyZulipTablesConfig}, | ||
github::{Issue, IssuesAction, IssuesEvent, Label}, | ||
handlers::Context, | ||
}; | ||
use futures::future::join_all; | ||
use tracing as log; | ||
|
||
pub(super) struct NotifyZulipInput { | ||
|
@@ -214,10 +217,15 @@ pub(super) async fn handle_input<'a>( | |
topic: &topic, | ||
}; | ||
|
||
// Issue/PR authors/reviewers will receive a mention if the template has `{recipients}`. | ||
let recipients = &mut event.issue.assignees.clone(); | ||
recipients.push(event.issue.user.clone()); | ||
|
||
for msg in msgs { | ||
let msg = msg.replace("{number}", &event.issue.number.to_string()); | ||
let msg = msg.replace("{title}", &event.issue.title); | ||
let msg = replace_team_to_be_nominated(&event.issue.labels, msg); | ||
let msg = msg.replace("{recipients}", &get_zulip_ids(ctx, &recipients).await); | ||
|
||
let req = crate::zulip::MessageApiRequest { | ||
recipient, | ||
|
@@ -236,6 +244,33 @@ pub(super) async fn handle_input<'a>( | |
Ok(()) | ||
} | ||
|
||
async fn get_zulip_ids(ctx: &Context, recipients: &[User]) -> String { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this code here is duplicating what we have in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. to generate the mention it's using the trick to write |
||
let gh_ids_fut = recipients | ||
.iter() | ||
.map(|recipient| async move { ctx.team.github_to_zulip_id(recipient.id).await }); | ||
let zulip_ids = join_all(gh_ids_fut).await; | ||
|
||
let zulip_ids = zulip_ids | ||
.iter() | ||
.filter_map(|x| { | ||
if let Ok(id2) = x.as_ref() | ||
&& let Some(id) = *id2 | ||
{ | ||
Some(render_zulip_username(id)) | ||
} else { | ||
None | ||
} | ||
}) | ||
.collect::<Vec<String>>(); | ||
|
||
if !zulip_ids.is_empty() { | ||
zulip_ids.join(", ") | ||
} else { | ||
"".to_string() | ||
} | ||
} | ||
|
||
/// Replace the placeholder "{team}" with the correct team name | ||
fn replace_team_to_be_nominated(labels: &[Label], msg: String) -> String { | ||
let teams = labels | ||
.iter() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is different from before: if the template has a
{recipients}
placeholder, author and reviewers of the PR/issue will receive a mention.(this change is very specific to my use-case but I think it can be used in other contexts)