From b97b5373bad831ae731809fd6e763fcd59199233 Mon Sep 17 00:00:00 2001 From: pep Date: Sun, 4 May 2025 00:25:16 +0200 Subject: [PATCH] Use ForgejoHook::try_from_event Signed-off-by: pep --- src/error.rs | 9 +++++++++ src/web.rs | 13 ++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/error.rs b/src/error.rs index 8b55931..cf29c6f 100644 --- a/src/error.rs +++ b/src/error.rs @@ -18,6 +18,7 @@ use std::error::Error as StdError; use std::io::Error as IoError; use std::str::Utf8Error; +use forgejo_hooks::Error as FjError; use hex::FromHexError; use hmac::digest::InvalidLength as HmacInvalidLength; use hyper::StatusCode; @@ -31,6 +32,7 @@ pub enum Error { InvalidSignature, InvalidRequest, UnsupportedHookConversion, + ForgejoHooks(FjError), Hex(FromHexError), Hmac(HmacInvalidLength), Hyper(hyper::Error), @@ -68,6 +70,7 @@ impl std::fmt::Display for Error { Error::InvalidSignature => write!(fmt, "the signature is invalid"), Error::InvalidRequest => write!(fmt, "the request is invalid"), Error::UnsupportedHookConversion => write!(fmt, "Unable to convert hook"), + Error::ForgejoHooks(e) => write!(fmt, "forgejo-hooks error: {}", e), Error::Hex(e) => write!(fmt, "hex error: {}", e), Error::Hmac(e) => write!(fmt, "hmac error: {}", e), Error::Hyper(e) => write!(fmt, "hyper error: {}", e), @@ -81,6 +84,12 @@ impl std::fmt::Display for Error { } } +impl From for Error { + fn from(err: FjError) -> Error { + Error::ForgejoHooks(err) + } +} + impl From for Error { fn from(err: FromHexError) -> Error { Error::Hex(err) diff --git a/src/web.rs b/src/web.rs index dade14e..b748a08 100644 --- a/src/web.rs +++ b/src/web.rs @@ -89,9 +89,16 @@ async fn hooks_inner(req: Request, secret: &str) -> Result