Procházet zdrojové kódy

Fix the pull_request event to be marked as a pull_request.

The `pull_request` event was not marking the issue as a pull_request.
That means that some handlers were ignoring pull requests when they
shouldn't have (like the rfc rendered handler).

Additionally I removed the empty `PullRequestDetails` struct and replaced
it with a bool instead. I don't foresee the `PullRequestDetails` ever
getting fields added to it (the fields usually are part of `Issue`).
Eric Huss před 2 roky
rodič
revize
3cde23dfb9
3 změnil soubory, kde provedl 11 přidání a 23 odebrání
  1. 3 7
      src/github.rs
  2. 1 2
      src/handlers/review_submitted.rs
  3. 7 14
      src/lib.rs

+ 3 - 7
src/github.rs

@@ -231,11 +231,6 @@ pub struct Label {
     pub name: String,
 }
 
-#[derive(Debug, serde::Deserialize)]
-pub struct PullRequestDetails {
-    // none for now
-}
-
 #[derive(Debug, serde::Deserialize)]
 pub struct Issue {
     pub number: u64,
@@ -250,7 +245,8 @@ pub struct Issue {
     pub user: User,
     pub labels: Vec<Label>,
     pub assignees: Vec<User>,
-    pub pull_request: Option<PullRequestDetails>,
+    #[serde(default)]
+    pub pull_request: bool,
     #[serde(default)]
     pub merged: bool,
     #[serde(default)]
@@ -431,7 +427,7 @@ impl Issue {
     }
 
     pub fn is_pr(&self) -> bool {
-        self.pull_request.is_some()
+        self.pull_request
     }
 
     pub async fn get_comment(&self, client: &GithubClient, id: usize) -> anyhow::Result<Comment> {

+ 1 - 2
src/handlers/review_submitted.rs

@@ -10,8 +10,7 @@ pub(crate) async fn handle(
         event @ IssueCommentEvent {
             action: IssueCommentAction::Created,
             issue: Issue {
-                pull_request: Some(_),
-                ..
+                pull_request: true, ..
             },
             ..
         },

+ 7 - 14
src/lib.rs

@@ -9,8 +9,6 @@ use interactions::ErrorComment;
 use std::fmt;
 use tracing as log;
 
-use crate::github::PullRequestDetails;
-
 pub mod actions;
 pub mod agenda;
 mod changelogs;
@@ -108,12 +106,7 @@ pub async fn webhook(
                 .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 {});
+            payload.pull_request.pull_request = true;
 
             // Treat pull request review comments exactly like pull request
             // review comments.
@@ -138,11 +131,7 @@ pub async fn webhook(
                 .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 {});
+            payload.issue.pull_request = true;
 
             log::info!("handling pull request review comment {:?}", payload);
 
@@ -166,10 +155,14 @@ pub async fn webhook(
             github::Event::IssueComment(payload)
         }
         EventName::Issue | EventName::PullRequest => {
-            let payload = deserialize_payload::<github::IssuesEvent>(&payload)
+            let mut payload = deserialize_payload::<github::IssuesEvent>(&payload)
                 .context(format!("{:?} failed to deserialize", event))
                 .map_err(anyhow::Error::from)?;
 
+            if matches!(event, EventName::PullRequest) {
+                payload.issue.pull_request = true;
+            }
+
             log::info!("handling issue event {:?}", payload);
 
             github::Event::Issue(payload)