add "protection" against non-pr events
This commit is contained in:
parent
613442ff62
commit
9afa1cde0c
23
src/main.rs
23
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<SharedState>) -> tide::Result {
|
|||
let body = req.body_string().await.unwrap();
|
||||
let pr = serde_json::from_str::<gitea::PullWh>(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());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue