浏览代码

Merge pull request #741 from dtolnay/sender

Handle absent sender_short_name in zulip-hook
Mark Rousskov 4 年之前
父节点
当前提交
fbcf122c03
共有 1 个文件被更改,包括 8 次插入4 次删除
  1. 8 4
      src/zulip.rs

+ 8 - 4
src/zulip.rs

@@ -23,7 +23,7 @@ pub struct Request {
 struct Message {
     sender_id: u64,
     recipient_id: u64,
-    sender_short_name: String,
+    sender_short_name: Option<String>,
     sender_full_name: String,
     stream_id: Option<u64>,
     topic: Option<String>,
@@ -268,11 +268,15 @@ async fn execute_for_other_user(
 
     // At this point, the command has been run (FIXME: though it may have
     // errored, it's hard to determine that currently, so we'll just give the
-    // output fromt he command as well as the command itself).
+    // output from the command as well as the command itself).
 
+    let sender = match &message_data.sender_short_name {
+        Some(short_name) => format!("{} ({})", message_data.sender_full_name, short_name),
+        None => message_data.sender_full_name.clone(),
+    };
     let message = format!(
-        "{} ({}) ran `{}` with output `{}` as you.",
-        message_data.sender_full_name, message_data.sender_short_name, command, output_msg
+        "{} ran `{}` with output `{}` as you.",
+        sender, command, output_msg
     );
 
     let res = MessageApiRequest {