From 14373c21dd2758768768adbfee58dfd5cbf3bfba Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sun, 14 Jul 2024 16:38:07 -0400 Subject: [PATCH] Initial schema for webhook. --- Cargo.lock | 1 + Cargo.toml | 2 ++ src/main.rs | 1 + src/webhook.rs | 23 ++++++++++++++++++++++- 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index a4f1fbd..7235c67 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -831,6 +831,7 @@ version = "0.0.1" dependencies = [ "axum", "serde", + "serde_json", "tokio", "tower-http", "tracing", diff --git a/Cargo.toml b/Cargo.toml index 7be4ace..aa6c998 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,6 +21,8 @@ include = [ # default form, http1, json, matched-path, original-uri, query, tokio, tower-log, tracing axum = { version = "0.7.5", default-features = false, features = ["tokio", "http1", "http2", "json"] } serde = { version = "1.0.204", features = ["derive"] } +# default std +serde_json = { version = "1.0.120", default-features = false, features = ["std"] } tokio = { version = "1.38.0", default-features = false, features = ["macros", "process", "rt", "rt-multi-thread"] } tower-http = { version = "0.5.2", default-features = false, features = ["trace"] } # default attributes, std, tracing-attributes diff --git a/src/main.rs b/src/main.rs index 3ac9486..a805ace 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,4 @@ +#![forbid(unsafe_code)] use axum::http::StatusCode; use axum::routing::get; use axum::routing::post; diff --git a/src/webhook.rs b/src/webhook.rs index a1010a2..68c8446 100644 --- a/src/webhook.rs +++ b/src/webhook.rs @@ -1,11 +1,32 @@ +use axum::http::HeaderMap; use axum::http::StatusCode; use axum::Json; +use serde::Deserialize; use serde::Serialize; +use serde_json::Value; -pub(crate) async fn hook() -> (StatusCode, Json) { +pub(crate) async fn hook( + headers: HeaderMap, + Json(payload): Json, +) -> (StatusCode, Json) { (StatusCode::OK, Json(HookResponse { ok: true })) } +#[allow(dead_code)] +#[derive(Deserialize)] +pub(crate) struct HookRequest { + #[serde(rename = "ref")] + ref_field: String, + before: String, + compare_url: String, + commits: Value, + total_commits: u64, + head_commit: Value, + repository: Value, + pusher: Value, + sender: Value, +} + #[derive(Serialize)] pub(crate) struct HookResponse { ok: bool,