parse gitea pr webhook

This commit is contained in:
2026-05-28 21:35:41 +00:00
parent e33187dc80
commit c119bed142
7 changed files with 321 additions and 8 deletions
+35
View File
@@ -0,0 +1,35 @@
use anyhow::anyhow;
use serde_json::Value;
pub enum WebhookType {
Review(u64, String)
}
impl TryFrom<Value> for WebhookType {
type Error = anyhow::Error;
fn try_from(json: Value) -> Result<Self, Self::Error> {
let pull_request = json.get("pull_request");
let comment = json.get("comment");
if let (Some(pull_request), Some(comment)) = (pull_request, comment) {
let comment_body = comment
.get("body")
.ok_or(anyhow!("comment body not found"))?
.as_str()
.ok_or(anyhow!("error while get pr comment"))?
.to_string();
let pr_id = pull_request
.get("id")
.ok_or(anyhow!("pr id not found"))?
.as_u64()
.ok_or(anyhow!("error while get pr id"))?;
return Ok(WebhookType::Review(pr_id, comment_body));
}
anyhow::bail!("unknow webhook type")
}
}