瀏覽代碼

Add access to previous contents of issues and comments

kellda 4 年之前
父節點
當前提交
7d39688a52
共有 2 個文件被更改,包括 24 次插入0 次删除
  1. 22 0
      src/github.rs
  2. 2 0
      src/lib.rs

+ 22 - 0
src/github.rs

@@ -541,6 +541,16 @@ impl Issue {
     }
 }
 
+#[derive(Debug, serde::Deserialize)]
+pub struct ChangeInner {
+    pub from: String,
+}
+
+#[derive(Debug, serde::Deserialize)]
+pub struct Changes {
+    pub body: ChangeInner,
+}
+
 #[derive(PartialEq, Eq, Debug, serde::Deserialize)]
 #[serde(rename_all = "lowercase")]
 pub enum PullRequestReviewAction {
@@ -554,12 +564,14 @@ pub struct PullRequestReviewEvent {
     pub action: PullRequestReviewAction,
     pub pull_request: Issue,
     pub review: Comment,
+    pub changes: Option<Changes>,
     pub repository: Repository,
 }
 
 #[derive(Debug, serde::Deserialize)]
 pub struct PullRequestReviewComment {
     pub action: IssueCommentAction,
+    pub changes: Option<Changes>,
     #[serde(rename = "pull_request")]
     pub issue: Issue,
     pub comment: Comment,
@@ -577,6 +589,7 @@ pub enum IssueCommentAction {
 #[derive(Debug, serde::Deserialize)]
 pub struct IssueCommentEvent {
     pub action: IssueCommentAction,
+    pub changes: Option<Changes>,
     pub issue: Issue,
     pub comment: Comment,
     pub repository: Repository,
@@ -612,6 +625,7 @@ pub struct IssuesEvent {
     pub action: IssuesAction,
     #[serde(alias = "pull_request")]
     pub issue: Issue,
+    pub changes: Option<Changes>,
     pub repository: Repository,
     /// Some if action is IssuesAction::Labeled, for example
     pub label: Option<Label>,
@@ -769,6 +783,14 @@ impl Event {
         }
     }
 
+    /// This will both extract from IssueComment events but also Issue events
+    pub fn comment_from(&self) -> Option<&str> {
+        match self {
+            Event::Issue(e) => Some(&e.changes.as_ref()?.body.from),
+            Event::IssueComment(e) => Some(&e.changes.as_ref()?.body.from),
+        }
+    }
+
     pub fn html_url(&self) -> Option<&str> {
         match self {
             Event::Issue(e) => Some(&e.issue.html_url),

+ 2 - 0
src/lib.rs

@@ -109,6 +109,7 @@ pub async fn webhook(
                         github::IssueCommentAction::Deleted
                     }
                 },
+                changes: payload.changes,
                 issue: payload.pull_request,
                 comment: payload.review,
                 repository: payload.repository,
@@ -125,6 +126,7 @@ pub async fn webhook(
             // review comments.
             github::Event::IssueComment(github::IssueCommentEvent {
                 action: payload.action,
+                changes: payload.changes,
                 issue: payload.issue,
                 comment: payload.comment,
                 repository: payload.repository,