diff --git a/src/github.rs b/src/github.rs index b2e2ba5..9649f07 100644 --- a/src/github.rs +++ b/src/github.rs @@ -16,7 +16,7 @@ use codespan_reporting::{ files::Files, }; use eyre::Context; -use hook::CheckRunPayload; +use hook::{CheckRunPayload, PullRequestAction, PullRequestPayload}; use jwt_simple::prelude::*; use pr::{AnyPullRequest, MinimalPullRequest, PullRequest, PullRequestUpdate}; use tracing::{debug, error, info, warn}; @@ -167,6 +167,15 @@ async fn github_hook( check_run.check_suite.pull_requests.pop(), Some(check_run), ), + HookPayload::PullRequest(PullRequestPayload { + action: PullRequestAction::Opened | PullRequestAction::Synchronize, + pull_request, + .. + }) => ( + pull_request.head.sha.clone(), + Some(AnyPullRequest::Full(pull_request)), + None, + ), HookPayload::CheckRun(_) | HookPayload::CheckSuite(CheckSuitePayload { action: CheckSuiteAction::Completed, diff --git a/src/github/api/hook.rs b/src/github/api/hook.rs index c8f5eac..09247cd 100644 --- a/src/github/api/hook.rs +++ b/src/github/api/hook.rs @@ -8,6 +8,7 @@ use crate::github::AppState; use super::{ check::{CheckRun, CheckRunAction, CheckSuite, CheckSuiteAction}, + pr::PullRequest, AsInstallation, Installation, }; @@ -16,6 +17,7 @@ pub enum HookPayload { Installation(InstallationPayload), CheckSuite(CheckSuitePayload), CheckRun(CheckRunPayload), + PullRequest(PullRequestPayload), } impl HookPayload { @@ -24,6 +26,7 @@ impl HookPayload { HookPayload::CheckSuite(cs) => &cs.installation, HookPayload::Installation(i) => &i.installation, HookPayload::CheckRun(cr) => &cr.installation, + HookPayload::PullRequest(pr) => &pr.installation, } } } @@ -113,6 +116,7 @@ impl FromRequest for HookPayload { Some(b"installation") => try_deser!(Installation, &raw_payload), Some(b"check_suite") => try_deser!(CheckSuite, &raw_payload), Some(b"check_run") => try_deser!(CheckRun, &raw_payload), + Some(b"pull_request") => try_deser!(PullRequest, &raw_payload), Some(x) => { debug!( "Uknown event type: {}", @@ -144,3 +148,17 @@ pub struct CheckRunPayload { pub action: CheckRunAction, pub check_run: CheckRun, } + +#[derive(Debug, Deserialize)] +pub struct PullRequestPayload { + pub installation: Installation, + pub action: PullRequestAction, + pub pull_request: PullRequest, +} + +#[derive(Debug, Deserialize)] +#[serde(rename_all = "snake_case")] +pub enum PullRequestAction { + Opened, + Synchronize, +}