diff --git a/src/main.rs b/src/main.rs index fcf6350..c93479c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,9 +1,6 @@ #![forbid(unsafe_code)] #![feature(new_uninit)] -use std::mem::MaybeUninit; - -use gitea::PullWh; use log; use teloxide_core::{prelude::*, types::{Recipient, Chat}}; use teloxide::Bot; @@ -55,6 +52,26 @@ async fn webhook(mut req: Request) -> tide::Result { let body = req.body_string().await.unwrap(); let pr = serde_json::from_str::(body.as_str()); + let event_type = req.header("X-Gitea-Event-Type"); + if event_type.is_none() { + return Ok( + Response::builder(400) + .body("{\"error\":\"no event type (X-Gitea-Event-Type)\"}") + .content_type("application/json") + .build() + ) + } + + let event_type = event_type.unwrap().get(0).unwrap().to_string(); + if event_type != "pull_request" { + return Ok( + Response::builder(200) + .body("{\"status\":\"ignoring non-pr event\"}") + .content_type("application/json") + .build() + ) + } + if pr.is_err() { return Ok(format!("Bad serialization: {}", pr.unwrap_err().to_string()).into()); }