From 96e24e4d5e2a5c3f03454a165226716ec1e7d24f Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Fri, 3 Jun 2022 20:33:38 -0400 Subject: [PATCH] Treat PR reviews as pull requests --- src/lib.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index f502405b8..c5f03bb04 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,6 +9,8 @@ use interactions::ErrorComment; use std::fmt; use tracing as log; +use crate::github::PullRequestDetails; + pub mod actions; pub mod agenda; mod changelogs; @@ -100,12 +102,18 @@ pub async fn webhook( ) -> Result { let event = match event { EventName::PullRequestReview => { - let payload = deserialize_payload::(&payload) + let mut payload = deserialize_payload::(&payload) .context("PullRequestReview failed to deserialize") .map_err(anyhow::Error::from)?; log::info!("handling pull request review comment {:?}", payload); + // Github doesn't send a pull_request field nested into the + // pull_request field, so we need to adjust the deserialized result + // to preserve that this event came from a pull request (since it's + // a PR review, that's obviously the case). + payload.pull_request.pull_request = Some(PullRequestDetails {}); + // Treat pull request review comments exactly like pull request // review comments. github::Event::IssueComment(github::IssueCommentEvent { @@ -125,10 +133,16 @@ pub async fn webhook( }) } EventName::PullRequestReviewComment => { - let payload = deserialize_payload::(&payload) + let mut payload = deserialize_payload::(&payload) .context("PullRequestReview(Comment) failed to deserialize") .map_err(anyhow::Error::from)?; + // Github doesn't send a pull_request field nested into the + // pull_request field, so we need to adjust the deserialized result + // to preserve that this event came from a pull request (since it's + // a PR review, that's obviously the case). + payload.issue.pull_request = Some(PullRequestDetails {}); + log::info!("handling pull request review comment {:?}", payload); // Treat pull request review comments exactly like pull request