Skip to content

Revert pull_request field change. #1653

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions src/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,16 @@ pub struct Label {
pub name: String,
}

/// An indicator used to differentiate between an issue and a pull request.
///
/// Some webhook events include a `pull_request` field in the Issue object,
/// and some don't. GitHub does include a few fields here, but they aren't
/// needed at this time (merged_at, diff_url, html_url, patch_url, url).
#[derive(Debug, serde::Deserialize)]
pub struct PullRequestDetails {
// none for now
}

/// An issue or pull request.
///
/// For convenience, since issues and pull requests share most of their
Expand Down Expand Up @@ -259,16 +269,12 @@ pub struct Issue {
pub user: User,
pub labels: Vec<Label>,
pub assignees: Vec<User>,
/// This is true if this is a pull request.
///
/// Note that this field does not come from GitHub. This is manually added
/// when the webhook arrives to help differentiate between an event
/// related to an issue versus a pull request.
/// Indicator if this is a pull request.
///
/// GitHub *does* actually populate this field on some events, but triagebot ignores that data
/// and just stores a bool here when appropriate.
#[serde(skip)]
pub pull_request: bool,
/// This is `Some` if this is a PR (as opposed to an issue). Note that
/// this does not always get filled in by GitHub, and must be manually
/// populated (because some webhook events do not set it).
pub pull_request: Option<PullRequestDetails>,
/// Whether or not the pull request was merged.
#[serde(default)]
pub merged: bool,
Expand Down Expand Up @@ -458,7 +464,7 @@ impl Issue {
}

pub fn is_pr(&self) -> bool {
self.pull_request
self.pull_request.is_some()
}

pub async fn get_comment(&self, client: &GithubClient, id: usize) -> anyhow::Result<Comment> {
Expand Down
3 changes: 2 additions & 1 deletion src/handlers/review_submitted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ pub(crate) async fn handle(
event @ IssueCommentEvent {
action: IssueCommentAction::Created,
issue: Issue {
pull_request: true, ..
pull_request: Some(_),
..
},
..
},
Expand Down
8 changes: 5 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#[macro_use]
extern crate lazy_static;

use crate::github::PullRequestDetails;

use anyhow::Context;
use handlers::HandlerError;
use interactions::ErrorComment;
Expand Down Expand Up @@ -143,7 +145,7 @@ pub async fn webhook(
.map_err(anyhow::Error::from)?;

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

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

payload.issue.pull_request = true;
payload.issue.pull_request = Some(PullRequestDetails {});

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

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

if matches!(event, EventName::PullRequest) {
payload.issue.pull_request = true;
payload.issue.pull_request = Some(PullRequestDetails {});
}

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