Skip to content

Commit 3cde23d

Browse files
committed
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`).
1 parent 42dba1d commit 3cde23d

File tree

3 files changed

+11
-23
lines changed

3 files changed

+11
-23
lines changed

src/github.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -231,11 +231,6 @@ pub struct Label {
231231
pub name: String,
232232
}
233233

234-
#[derive(Debug, serde::Deserialize)]
235-
pub struct PullRequestDetails {
236-
// none for now
237-
}
238-
239234
#[derive(Debug, serde::Deserialize)]
240235
pub struct Issue {
241236
pub number: u64,
@@ -250,7 +245,8 @@ pub struct Issue {
250245
pub user: User,
251246
pub labels: Vec<Label>,
252247
pub assignees: Vec<User>,
253-
pub pull_request: Option<PullRequestDetails>,
248+
#[serde(default)]
249+
pub pull_request: bool,
254250
#[serde(default)]
255251
pub merged: bool,
256252
#[serde(default)]
@@ -431,7 +427,7 @@ impl Issue {
431427
}
432428

433429
pub fn is_pr(&self) -> bool {
434-
self.pull_request.is_some()
430+
self.pull_request
435431
}
436432

437433
pub async fn get_comment(&self, client: &GithubClient, id: usize) -> anyhow::Result<Comment> {

src/handlers/review_submitted.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ pub(crate) async fn handle(
1010
event @ IssueCommentEvent {
1111
action: IssueCommentAction::Created,
1212
issue: Issue {
13-
pull_request: Some(_),
14-
..
13+
pull_request: true, ..
1514
},
1615
..
1716
},

src/lib.rs

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ use interactions::ErrorComment;
99
use std::fmt;
1010
use tracing as log;
1111

12-
use crate::github::PullRequestDetails;
13-
1412
pub mod actions;
1513
pub mod agenda;
1614
mod changelogs;
@@ -108,12 +106,7 @@ pub async fn webhook(
108106
.map_err(anyhow::Error::from)?;
109107

110108
log::info!("handling pull request review comment {:?}", payload);
111-
112-
// Github doesn't send a pull_request field nested into the
113-
// pull_request field, so we need to adjust the deserialized result
114-
// to preserve that this event came from a pull request (since it's
115-
// a PR review, that's obviously the case).
116-
payload.pull_request.pull_request = Some(PullRequestDetails {});
109+
payload.pull_request.pull_request = true;
117110

118111
// Treat pull request review comments exactly like pull request
119112
// review comments.
@@ -138,11 +131,7 @@ pub async fn webhook(
138131
.context("PullRequestReview(Comment) failed to deserialize")
139132
.map_err(anyhow::Error::from)?;
140133

141-
// Github doesn't send a pull_request field nested into the
142-
// pull_request field, so we need to adjust the deserialized result
143-
// to preserve that this event came from a pull request (since it's
144-
// a PR review, that's obviously the case).
145-
payload.issue.pull_request = Some(PullRequestDetails {});
134+
payload.issue.pull_request = true;
146135

147136
log::info!("handling pull request review comment {:?}", payload);
148137

@@ -166,10 +155,14 @@ pub async fn webhook(
166155
github::Event::IssueComment(payload)
167156
}
168157
EventName::Issue | EventName::PullRequest => {
169-
let payload = deserialize_payload::<github::IssuesEvent>(&payload)
158+
let mut payload = deserialize_payload::<github::IssuesEvent>(&payload)
170159
.context(format!("{:?} failed to deserialize", event))
171160
.map_err(anyhow::Error::from)?;
172161

162+
if matches!(event, EventName::PullRequest) {
163+
payload.issue.pull_request = true;
164+
}
165+
173166
log::info!("handling issue event {:?}", payload);
174167

175168
github::Event::Issue(payload)

0 commit comments

Comments
 (0)