Initial schema for webhook.

This commit is contained in:
Tom Alexander 2024-07-14 16:38:07 -04:00
parent ab5db8aded
commit 14373c21dd
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
4 changed files with 26 additions and 1 deletions

1
Cargo.lock generated
View File

@ -831,6 +831,7 @@ version = "0.0.1"
dependencies = [
"axum",
"serde",
"serde_json",
"tokio",
"tower-http",
"tracing",

View File

@ -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

View File

@ -1,3 +1,4 @@
#![forbid(unsafe_code)]
use axum::http::StatusCode;
use axum::routing::get;
use axum::routing::post;

View File

@ -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<HookResponse>) {
pub(crate) async fn hook(
headers: HeaderMap,
Json(payload): Json<HookRequest>,
) -> (StatusCode, Json<HookResponse>) {
(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,