Browse Source

Handle pull request review comments

This handles pull request review comments precisely the same as issue comments,
hopefully allowing us to handle all "inputs" to the handlers.
Mark Rousskov 5 years ago
parent
commit
3935511b96
2 changed files with 28 additions and 0 deletions
  1. 9 0
      src/github.rs
  2. 19 0
      src/lib.rs

+ 9 - 0
src/github.rs

@@ -391,6 +391,15 @@ impl Issue {
     }
     }
 }
 }
 
 
+#[derive(Debug, serde::Deserialize)]
+pub struct PullRequestReviewComment {
+    pub action: IssueCommentAction,
+    #[serde(rename = "pull_request")]
+    pub issue: Issue,
+    pub comment: Comment,
+    pub repository: Repository,
+}
+
 #[derive(PartialEq, Eq, Debug, serde::Deserialize)]
 #[derive(PartialEq, Eq, Debug, serde::Deserialize)]
 #[serde(rename_all = "lowercase")]
 #[serde(rename_all = "lowercase")]
 pub enum IssueCommentAction {
 pub enum IssueCommentAction {

+ 19 - 0
src/lib.rs

@@ -16,6 +16,7 @@ pub mod team;
 pub mod zulip;
 pub mod zulip;
 
 
 pub enum EventName {
 pub enum EventName {
+    PullRequestReviewComment,
     IssueComment,
     IssueComment,
     Issue,
     Issue,
     Other,
     Other,
@@ -25,6 +26,7 @@ impl std::str::FromStr for EventName {
     type Err = std::convert::Infallible;
     type Err = std::convert::Infallible;
     fn from_str(s: &str) -> Result<EventName, Self::Err> {
     fn from_str(s: &str) -> Result<EventName, Self::Err> {
         Ok(match s {
         Ok(match s {
+            "pull_request_review_comment" => EventName::PullRequestReviewComment,
             "issue_comment" => EventName::IssueComment,
             "issue_comment" => EventName::IssueComment,
             "issues" => EventName::Issue,
             "issues" => EventName::Issue,
             _ => EventName::Other,
             _ => EventName::Other,
@@ -38,6 +40,7 @@ impl fmt::Display for EventName {
             f,
             f,
             "{}",
             "{}",
             match self {
             match self {
+                EventName::PullRequestReviewComment => "pull_request_review_comment",
                 EventName::IssueComment => "issue_comment",
                 EventName::IssueComment => "issue_comment",
                 EventName::Issue => "issues",
                 EventName::Issue => "issues",
                 EventName::Other => "other",
                 EventName::Other => "other",
@@ -65,6 +68,22 @@ pub async fn webhook(
     ctx: &handlers::Context,
     ctx: &handlers::Context,
 ) -> Result<(), WebhookError> {
 ) -> Result<(), WebhookError> {
     let event = match event {
     let event = match event {
+        EventName::PullRequestReviewComment => {
+            let payload = deserialize_payload::<github::PullRequestReviewComment>(&payload)
+                .context("IssueCommentEvent failed to deserialize")
+                .map_err(anyhow::Error::from)?;
+
+            log::info!("handling pull request review comment {:?}", payload);
+
+            // Treat pull request review comments exactly like pull request
+            // review comments.
+            github::Event::IssueComment(github::IssueCommentEvent {
+                action: payload.action,
+                issue: payload.issue,
+                comment: payload.comment,
+                repository: payload.repository,
+            })
+        }
         EventName::IssueComment => {
         EventName::IssueComment => {
             let payload = deserialize_payload::<github::IssueCommentEvent>(&payload)
             let payload = deserialize_payload::<github::IssueCommentEvent>(&payload)
                 .context("IssueCommentEvent failed to deserialize")
                 .context("IssueCommentEvent failed to deserialize")