add gitea sig header check, add Json errors, begin AppState

This commit is contained in:
2026-05-31 20:32:49 +00:00
parent c119bed142
commit aa746f357d
10 changed files with 288 additions and 37 deletions
+14 -4
View File
@@ -1,17 +1,27 @@
use anyhow::anyhow;
use serde_json::Value;
use crate::errors::AppError;
pub enum WebhookType {
Review(u64, String)
Review(u64, String),
}
impl TryFrom<Value> for WebhookType {
type Error = anyhow::Error;
type Error = AppError;
fn try_from(json: Value) -> Result<Self, Self::Error> {
let pull_request = json.get("pull_request");
let comment = json.get("comment");
let action = json
.get("action")
.ok_or(anyhow!("action not found"))?
.as_str()
.ok_or(anyhow!("error while action"))?;
if action != "created" {
return Err(AppError::BadJsonStructErr);
}
if let (Some(pull_request), Some(comment)) = (pull_request, comment) {
let comment_body = comment
@@ -30,6 +40,6 @@ impl TryFrom<Value> for WebhookType {
return Ok(WebhookType::Review(pr_id, comment_body));
}
anyhow::bail!("unknow webhook type")
Err(AppError::BadJsonStructErr)
}
}
}