Skip to content
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

After renaming zulip topic, post a comment under the old topic pointing to the new topic #1590

Merged
merged 1 commit into from Apr 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/handlers/major_change.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,28 @@ pub(super) async fn handle_input(
.await
.context("zulip message update failed")?;

// after renaming the zulip topic, post an additional comment under the old topic with a url to the new, renamed topic
// this is necessary due to the lack of topic permalinks, see https://github.com/zulip/zulip/issues/15290
let new_topic_url = crate::zulip::Recipient::Stream {
id: config.zulip_stream,
topic: &new_topic,
}.url();
let breadcrumb_comment = format!(
"The associated GitHub issue has been renamed. Please see the [renamed Zulip topic]({}).",
new_topic_url
);
let zulip_send_breadcrumb_req = crate::zulip::MessageApiRequest {
recipient: crate::zulip::Recipient::Stream {
id: config.zulip_stream,
topic: &prev_topic,
},
content: &breadcrumb_comment,
};
zulip_send_breadcrumb_req
.send(&ctx.github.raw())
.await
.context("zulip post failed")?;

return Ok(());
}
};
Expand Down
9 changes: 5 additions & 4 deletions src/zulip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,10 @@ impl Recipient<'_> {
Recipient::Private { id, .. } => format!("pm-with/{}-xxx", id),
}
}

pub fn url(&self) -> String {
format!("https://rust-lang.zulipchat.com/#narrow/{}", self.narrow())
}
}

#[cfg(test)]
Expand Down Expand Up @@ -430,10 +434,7 @@ pub struct MessageApiRequest<'a> {

impl<'a> MessageApiRequest<'a> {
pub fn url(&self) -> String {
format!(
"https://rust-lang.zulipchat.com/#narrow/{}",
self.recipient.narrow()
)
self.recipient.url()
}

pub async fn send(&self, client: &reqwest::Client) -> anyhow::Result<reqwest::Response> {
Expand Down