Skip to content

Commit 6ba29f7

Browse files
Merge pull request #1653 from ehuss/revert-pull_request-change
Revert pull_request field change.
2 parents a3eafef + 266dd5d commit 6ba29f7

File tree

3 files changed

+23
-14
lines changed

3 files changed

+23
-14
lines changed

src/github.rs

+16-10
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,16 @@ pub struct Label {
231231
pub name: String,
232232
}
233233

234+
/// An indicator used to differentiate between an issue and a pull request.
235+
///
236+
/// Some webhook events include a `pull_request` field in the Issue object,
237+
/// and some don't. GitHub does include a few fields here, but they aren't
238+
/// needed at this time (merged_at, diff_url, html_url, patch_url, url).
239+
#[derive(Debug, serde::Deserialize)]
240+
pub struct PullRequestDetails {
241+
// none for now
242+
}
243+
234244
/// An issue or pull request.
235245
///
236246
/// For convenience, since issues and pull requests share most of their
@@ -259,16 +269,12 @@ pub struct Issue {
259269
pub user: User,
260270
pub labels: Vec<Label>,
261271
pub assignees: Vec<User>,
262-
/// This is true if this is a pull request.
263-
///
264-
/// Note that this field does not come from GitHub. This is manually added
265-
/// when the webhook arrives to help differentiate between an event
266-
/// related to an issue versus a pull request.
272+
/// Indicator if this is a pull request.
267273
///
268-
/// GitHub *does* actually populate this field on some events, but triagebot ignores that data
269-
/// and just stores a bool here when appropriate.
270-
#[serde(skip)]
271-
pub pull_request: bool,
274+
/// This is `Some` if this is a PR (as opposed to an issue). Note that
275+
/// this does not always get filled in by GitHub, and must be manually
276+
/// populated (because some webhook events do not set it).
277+
pub pull_request: Option<PullRequestDetails>,
272278
/// Whether or not the pull request was merged.
273279
#[serde(default)]
274280
pub merged: bool,
@@ -458,7 +464,7 @@ impl Issue {
458464
}
459465

460466
pub fn is_pr(&self) -> bool {
461-
self.pull_request
467+
self.pull_request.is_some()
462468
}
463469

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

src/handlers/review_submitted.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ pub(crate) async fn handle(
1010
event @ IssueCommentEvent {
1111
action: IssueCommentAction::Created,
1212
issue: Issue {
13-
pull_request: true, ..
13+
pull_request: Some(_),
14+
..
1415
},
1516
..
1617
},

src/lib.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#[macro_use]
44
extern crate lazy_static;
55

6+
use crate::github::PullRequestDetails;
7+
68
use anyhow::Context;
79
use handlers::HandlerError;
810
use interactions::ErrorComment;
@@ -143,7 +145,7 @@ pub async fn webhook(
143145
.map_err(anyhow::Error::from)?;
144146

145147
log::info!("handling pull request review comment {:?}", payload);
146-
payload.pull_request.pull_request = true;
148+
payload.pull_request.pull_request = Some(PullRequestDetails {});
147149

148150
// Treat pull request review comments exactly like pull request
149151
// review comments.
@@ -168,7 +170,7 @@ pub async fn webhook(
168170
.context("PullRequestReview(Comment) failed to deserialize")
169171
.map_err(anyhow::Error::from)?;
170172

171-
payload.issue.pull_request = true;
173+
payload.issue.pull_request = Some(PullRequestDetails {});
172174

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

@@ -197,7 +199,7 @@ pub async fn webhook(
197199
.map_err(anyhow::Error::from)?;
198200

199201
if matches!(event, EventName::PullRequest) {
200-
payload.issue.pull_request = true;
202+
payload.issue.pull_request = Some(PullRequestDetails {});
201203
}
202204

203205
log::info!("handling issue event {:?}", payload);

0 commit comments

Comments
 (0)