瀏覽代碼

shortcut: ping users on ready/author

Llandy Riveron Del Risco 3 年之前
父節點
當前提交
02b0aed4a3
共有 2 個文件被更改,包括 32 次插入1 次删除
  1. 13 1
      src/handlers/shortcut.rs
  2. 19 0
      src/interactions.rs

+ 13 - 1
src/handlers/shortcut.rs

@@ -6,7 +6,7 @@ use crate::{
     config::ShortcutConfig,
     github::{Event, Label},
     handlers::Context,
-    interactions::ErrorComment,
+    interactions::{ErrorComment, PingComment},
 };
 use parser::command::shortcut::ShortcutCommand;
 
@@ -37,6 +37,14 @@ pub(super) async fn handle_command(
                 return Ok(());
             }
             issue.set_labels(&ctx.github, issue_labels).await?;
+
+            let to_ping: Vec<_> = issue
+                .assignees
+                .iter()
+                .map(|user| user.login.as_str())
+                .collect();
+            let cmnt = PingComment::new(&issue, &to_ping);
+            cmnt.post(&ctx.github).await?;
         }
         ShortcutCommand::Author => {
             if assign_and_remove_label(&mut issue_labels, waiting_on_author, waiting_on_review)
@@ -45,6 +53,10 @@ pub(super) async fn handle_command(
                 return Ok(());
             }
             issue.set_labels(&ctx.github, issue_labels).await?;
+
+            let to_ping = vec![issue.user.login.as_str()];
+            let cmnt = PingComment::new(&issue, &to_ping);
+            cmnt.post(&ctx.github).await?;
         }
     }
 

+ 19 - 0
src/interactions.rs

@@ -29,6 +29,25 @@ impl<'a> ErrorComment<'a> {
     }
 }
 
+pub struct PingComment<'a> {
+    issue: &'a Issue,
+    users: &'a [&'a str],
+}
+
+impl<'a> PingComment<'a> {
+    pub fn new(issue: &'a Issue, users: &'a [&str]) -> PingComment<'a> {
+        PingComment { issue, users }
+    }
+
+    pub async fn post(&self, client: &GithubClient) -> anyhow::Result<()> {
+        let mut body = String::new();
+        for user in self.users {
+            write!(body, "@{} ", user)?;
+        }
+        self.issue.post_comment(client, &body).await
+    }
+}
+
 pub struct EditIssueBody<'a> {
     issue: &'a Issue,
     id: &'static str,