Skip to content

Commit 8cdea32

Browse files
After renaming zulip topic (#1588), post an additional comment under the old (now empty) topic pointing to the newly renamed topic. Fixes #1228.
1 parent bc415ec commit 8cdea32

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

src/handlers/major_change.rs

+22
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,28 @@ pub(super) async fn handle_input(
147147
.await
148148
.context("zulip message update failed")?;
149149

150+
// after renaming the zulip topic, post an additional comment under the old topic with a url to the new, renamed topic
151+
// this is necessary due to the lack of topic permalinks, see https://github.com/zulip/zulip/issues/15290
152+
let new_topic_url = crate::zulip::Recipient::Stream {
153+
id: config.zulip_stream,
154+
topic: &new_topic,
155+
}.url();
156+
let breadcrumb_comment = format!(
157+
"The associated GitHub issue has been renamed. Please see the [renamed Zulip topic]({}).",
158+
new_topic_url
159+
);
160+
let zulip_send_breadcrumb_req = crate::zulip::MessageApiRequest {
161+
recipient: crate::zulip::Recipient::Stream {
162+
id: config.zulip_stream,
163+
topic: &prev_topic,
164+
},
165+
content: &breadcrumb_comment,
166+
};
167+
zulip_send_breadcrumb_req
168+
.send(&ctx.github.raw())
169+
.await
170+
.context("zulip post failed")?;
171+
150172
return Ok(());
151173
}
152174
};

src/zulip.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,10 @@ impl Recipient<'_> {
393393
Recipient::Private { id, .. } => format!("pm-with/{}-xxx", id),
394394
}
395395
}
396+
397+
pub fn url(&self) -> String {
398+
format!("https://rust-lang.zulipchat.com/#narrow/{}", self.narrow())
399+
}
396400
}
397401

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

431435
impl<'a> MessageApiRequest<'a> {
432436
pub fn url(&self) -> String {
433-
format!(
434-
"https://rust-lang.zulipchat.com/#narrow/{}",
435-
self.recipient.narrow()
436-
)
437+
self.recipient.url()
437438
}
438439

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

0 commit comments

Comments
 (0)