Skip to content

Commit

Permalink
Run hook on pull_request events too.
Browse files Browse the repository at this point in the history
The check_suite event is only triggered for the
repository on which the commit is pushed, not on
the source of the fork.
  • Loading branch information
elegaanz committed Sep 26, 2024
1 parent 7f06adc commit 52087d4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -167,6 +167,15 @@ async fn github_hook<G: GitHubAuth>(
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,
Expand Down
18 changes: 18 additions & 0 deletions src/github/api/hook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::github::AppState;

use super::{
check::{CheckRun, CheckRunAction, CheckSuite, CheckSuiteAction},
pr::PullRequest,
AsInstallation, Installation,
};

Expand All @@ -16,6 +17,7 @@ pub enum HookPayload {
Installation(InstallationPayload),
CheckSuite(CheckSuitePayload),
CheckRun(CheckRunPayload),
PullRequest(PullRequestPayload),
}

impl HookPayload {
Expand All @@ -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,
}
}
}
Expand Down Expand Up @@ -113,6 +116,7 @@ impl FromRequest<AppState> 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: {}",
Expand Down Expand Up @@ -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,
}

0 comments on commit 52087d4

Please sign in to comment.