webhook_bridge/src/webhook.rs

159 lines
3.7 KiB
Rust
Raw Normal View History

2024-07-14 20:38:07 +00:00
use axum::http::HeaderMap;
2024-07-14 20:13:06 +00:00
use axum::http::StatusCode;
use axum::Json;
2024-07-14 20:38:07 +00:00
use serde::Deserialize;
2024-07-14 20:13:06 +00:00
use serde::Serialize;
2024-07-14 20:38:07 +00:00
use serde_json::Value;
2024-07-14 20:13:06 +00:00
2024-07-14 20:38:07 +00:00
pub(crate) async fn hook(
headers: HeaderMap,
Json(payload): Json<HookRequest>,
) -> (StatusCode, Json<HookResponse>) {
2024-07-14 20:13:06 +00:00
(StatusCode::OK, Json(HookResponse { ok: true }))
}
2024-07-14 20:38:07 +00:00
#[allow(dead_code)]
#[derive(Deserialize)]
pub(crate) struct HookRequest {
#[serde(rename = "ref")]
ref_field: String,
before: String,
compare_url: String,
2024-07-14 21:04:08 +00:00
commits: Vec<HookCommit>,
2024-07-14 20:38:07 +00:00
total_commits: u64,
2024-07-14 21:04:08 +00:00
head_commit: HookCommit,
repository: HookRepository,
pusher: HookUser,
sender: HookUser,
}
#[allow(dead_code)]
#[derive(Deserialize)]
pub(crate) struct HookUser {
id: u64,
login: String,
login_name: String,
full_name: String,
email: String,
avatar_url: String,
language: String,
is_admin: bool,
last_login: String, // TODO: parse to datetime
created: String, // TODO: parse to datetime
restricted: bool,
active: bool,
prohibit_login: bool,
location: String,
website: String,
description: String,
visibility: String,
followers_count: u64,
following_count: u64,
starred_repos_count: u64,
username: String,
}
#[allow(dead_code)]
#[derive(Deserialize)]
pub(crate) struct HookRepository {
id: u64,
owner: HookUser,
name: String,
full_name: String,
description: String,
empty: bool,
private: bool,
fork: bool,
template: bool,
parent: Value, // Was null in test hook
mirror: bool,
size: u64,
language: String,
languages_url: String,
html_url: String,
url: String,
link: String,
ssh_url: String,
clone_url: String,
original_url: String,
website: String,
stars_count: u64,
forks_count: u64,
watchers_count: u64,
open_issues_count: u64,
open_pr_counter: u64,
release_counter: u64,
default_branch: String,
archived: bool,
created_at: String, // TODO: parse to datetime
updated_at: String, // TODO: parse to datetime
archived_at: String, // TODO: parse to datetime
permissions: HookRepositoryPermissions,
has_issues: bool,
internal_tracker: HookRepositoryInternalTracker,
has_wiki: bool,
has_pull_requests: bool,
has_projects: bool,
has_releases: bool,
has_packages: bool,
has_actions: bool,
ignore_whitespace_conflicts: bool,
allow_merge_commits: bool,
allow_rebase: bool,
allow_rebase_explicit: bool,
allow_squash_merge: bool,
allow_rebase_update: bool,
default_delete_branch_after_merge: bool,
default_merge_style: String,
default_allow_maintainer_edit: bool,
avatar_url: String,
internal: bool,
mirror_interval: String,
mirror_updated: String, // TODO: parse to datetime
repo_transfer: Value, // Was null in test hook
}
#[allow(dead_code)]
#[derive(Deserialize)]
pub(crate) struct HookRepositoryPermissions {
admin: bool,
push: bool,
pull: bool,
}
#[allow(dead_code)]
#[derive(Deserialize)]
pub(crate) struct HookRepositoryInternalTracker {
enable_time_tracker: bool,
allow_only_contributors_to_track_time: bool,
enable_issue_dependencies: bool,
}
#[allow(dead_code)]
#[derive(Deserialize)]
pub(crate) struct HookCommit {
id: String,
message: String,
url: String,
author: HookGitUser,
committer: HookGitUser,
verification: Value, // Was null in test hook
timestamp: String, // TODO: parse to datetime
added: Vec<String>,
removed: Vec<String>,
modified: Vec<String>,
}
#[allow(dead_code)]
#[derive(Deserialize)]
pub(crate) struct HookGitUser {
name: String,
email: String,
username: String,
2024-07-14 20:38:07 +00:00
}
2024-07-14 20:13:06 +00:00
#[derive(Serialize)]
pub(crate) struct HookResponse {
ok: bool,
}