Skip to content
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
24 changes: 22 additions & 2 deletions src/bin/foxguard_github_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,12 @@ async fn webhook(
},
EventKind::PullRequest => match parse_webhook_payload(&body) {
Ok(payload) => {
if let Some(installation) = payload.installation {
let action = payload.action.unwrap_or_else(|| "?".to_string());
if !should_process_pull_request_action(&action) {
tracing::debug!(delivery, action, "pull_request action ignored");
} else if let Some(installation) = payload.installation {
let state_for_task = state.clone();
let delivery = delivery.to_string();
let action = payload.action.unwrap_or_else(|| "?".to_string());
let installation_id = installation.id;
let pull_request = payload.pull_request;
let repository = payload.repository;
Expand Down Expand Up @@ -321,6 +323,13 @@ fn parse_webhook_payload(body: &[u8]) -> Result<GitHubWebhookPayload, serde_json
serde_json::from_slice(body)
}

fn should_process_pull_request_action(action: &str) -> bool {
matches!(
action,
"opened" | "reopened" | "synchronize" | "ready_for_review"
)
}

fn persist_installation_event(
state: &AppState,
payload: &GitHubWebhookPayload,
Expand Down Expand Up @@ -869,6 +878,17 @@ mod tests {
assert!(payload.installation.is_none());
}

#[test]
fn pull_request_action_filter_matches_code_changing_events() {
assert!(should_process_pull_request_action("opened"));
assert!(should_process_pull_request_action("reopened"));
assert!(should_process_pull_request_action("synchronize"));
assert!(should_process_pull_request_action("ready_for_review"));
assert!(!should_process_pull_request_action("edited"));
assert!(!should_process_pull_request_action("labeled"));
assert!(!should_process_pull_request_action("?"));
}

#[test]
fn parses_installation_metadata_payload() {
let payload = match parse_webhook_payload(
Expand Down
Loading