From 8cdea32a2b36b1015dc2476d94e434b56155c207 Mon Sep 17 00:00:00 2001 From: skippy10110 Date: Mon, 14 Mar 2022 17:35:08 -0300 Subject: [PATCH] After renaming zulip topic (#1588), post an additional comment under the old (now empty) topic pointing to the newly renamed topic. Fixes #1228. --- src/handlers/major_change.rs | 22 ++++++++++++++++++++++ src/zulip.rs | 9 +++++---- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/handlers/major_change.rs b/src/handlers/major_change.rs index 5b5016c62..a6e1366ff 100644 --- a/src/handlers/major_change.rs +++ b/src/handlers/major_change.rs @@ -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(()); } }; diff --git a/src/zulip.rs b/src/zulip.rs index c9cb2fa07..1d74930b1 100644 --- a/src/zulip.rs +++ b/src/zulip.rs @@ -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)] @@ -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 {