Browse Source

After renaming zulip topic (#1588), post an additional comment under the old (now empty) topic pointing to the newly renamed topic. Fixes #1228.

skippy10110 3 years ago
parent
commit
8cdea32a2b
2 changed files with 27 additions and 4 deletions
  1. 22 0
      src/handlers/major_change.rs
  2. 5 4
      src/zulip.rs

+ 22 - 0
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(());
         }
     };

+ 5 - 4
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<reqwest::Response> {