From 991474e4ad4647a6513b12abc3a0367df81685b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Sun, 21 Apr 2024 17:41:47 +0200 Subject: [PATCH] Implement gitea hook support instead MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- Cargo.toml | 2 +- src/web.rs | 6 +++--- src/webhook.rs | 16 ++++++++++++++-- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2902e97..3176a27 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ license = "AGPL-3.0+" [dependencies] clap = { version = "4.3", features = [ "cargo" ] } gitlab = "0.1610" -forgejo-api-types = "0.1" +gitea-rs = "1.19" hyper = { version = "0.14", features = [ "full" ] } jid = { version = "*", features = [ "serde" ] } log = "0.4" diff --git a/src/web.rs b/src/web.rs index 4791157..105092a 100644 --- a/src/web.rs +++ b/src/web.rs @@ -14,7 +14,7 @@ // along with this program. If not, see . use crate::error::Error; -use crate::webhook::{Hook, ForgejoHook, GitlabHook}; +use crate::webhook::{Hook, GiteaHook, GitlabHook}; use std::convert::Infallible; use std::str::from_utf8; @@ -79,9 +79,9 @@ async fn webhooks_inner(req: Request, token: &str) -> Result let tmp = body::to_bytes(req.into_body()).await?; let text: &str = from_utf8(&tmp)?; debug!("FOO3 text: {:?}", text); - let hook: ForgejoHook = serde_json::from_str(text)?; + let hook: GiteaHook = serde_json::from_str(text)?; debug!("FOO3 json: {:?}", hook); - Ok(Hook::Forgejo(hook)) + Ok(Hook::Gitea(hook)) } } else { debug!("FOO3: else"); diff --git a/src/webhook.rs b/src/webhook.rs index 4985bb5..af8d9ea 100644 --- a/src/webhook.rs +++ b/src/webhook.rs @@ -14,15 +14,27 @@ // along with this program. If not, see . pub use gitlab::webhooks::{IssueAction, MergeRequestAction, WebHook as GitlabHook, WikiPageAction}; -pub use forgejo_api_types::types::api::hook::Hook as ForgejoHook; +pub use gitea_rs::models::hook::Hook as GiteaHook; use log::debug; #[derive(Debug)] pub enum Hook { - Forgejo(ForgejoHook), + Gitea(GiteaHook), Gitlab(GitlabHook), } +impl From for Hook { + fn from(hook: GiteaHook) -> Hook { + Hook::Gitea(hook) + } +} + +impl From for Hook { + fn from(hook: GitlabHook) -> Hook { + Hook::Gitlab(hook) + } +} + pub fn format_webhook(glh: &GitlabHook) -> Option { Some(match glh { GitlabHook::Push(push) => {