Skip to content
Draft
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
11 changes: 8 additions & 3 deletions src/zulip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ pub struct Request {
}

#[derive(Clone, Debug, serde::Deserialize)]
struct Message {
pub(crate) struct Message {
id: u64,
sender_id: u64,
/// A unique ID for the set of users receiving the message (either a
Expand Down Expand Up @@ -375,10 +375,15 @@ async fn handle_command<'a>(
StreamCommand::AssignPriority { issue_num, prio } => {
let _ = match assign_issue_prio(&ctx, message_data, issue_num, prio).await {
// give user feedback
Ok(_) => ctx.zulip.add_reaction(message_data.id, "check").await,
Ok(_) => {
// emoji reaction for the triagebot command
ctx.zulip.add_reaction(message_data.id, "check").await?;
// resolve the Zulip topic
ctx.zulip.resolve_topic(message_data.clone()).await?;
}
Err(err) => {
log::error!("Could not assign priority to #{}: {:?}", issue_num, err);
ctx.zulip.add_reaction(message_data.id, "scream").await
ctx.zulip.add_reaction(message_data.id, "scream").await?;
}
};
Ok(None)
Expand Down
39 changes: 39 additions & 0 deletions src/zulip/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,45 @@ impl ZulipClient {
.into()
})
}

// https://zulip.com/api/update-message#parameter-topic
pub(crate) async fn resolve_topic(&self, message_data: super::Message) -> anyhow::Result<()> {
let message_id = message_data.id;
let topic = message_data
.subject
.unwrap_or_default()
.replacen("", "✔ ", 1);
#[derive(serde::Serialize)]
struct ResolveTopic<'a> {
topic: &'a str,
propagate_mode: &'a str,
send_notification_to_old_thread: bool,
send_notification_to_new_thread: bool,
}

let resp = self
.make_request(Method::PATCH, &format!("messages/{message_id}"))
.form(&ResolveTopic {
topic: &topic,
propagate_mode: "change_all",
send_notification_to_old_thread: false,
send_notification_to_new_thread: false,
})
.send()
.await
.context("failed to add reaction to a Zulip message")?;

let status = resp.status();
if !status.is_success() {
let body = resp
.text()
.await
.context("fail receiving Zulip API response (when adding a reaction)")?;
anyhow::bail!(body)
}

Ok(())
}
}

async fn deserialize_response<T>(response: Response) -> anyhow::Result<T>
Expand Down