From 5f9b260d7639bd8fde31b9223f2f988f7aa1f5bf Mon Sep 17 00:00:00 2001 From: MCorange99 Date: Sat, 30 Mar 2024 19:05:02 +0200 Subject: [PATCH] uwu --- src/database/models/posts.rs | 2 +- .../routes/api/webhooks/github/events/mod.rs | 29 +++++++++++-------- src/web/routes/api/webhooks/github/mod.rs | 2 +- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/database/models/posts.rs b/src/database/models/posts.rs index 6b89d76..315fb38 100644 --- a/src/database/models/posts.rs +++ b/src/database/models/posts.rs @@ -17,7 +17,7 @@ pub struct Post { #[allow(dead_code)] impl Post { - pub async fn create_new(db: &mut Database, title: String, descr: String, img_url: String, origin_url: String, orignal_request: Value) -> anyhow::Result { + pub async fn create_new(db: &mut Database, title: String, descr: String, img_url: String, origin_url: String, orignal_request: String) -> anyhow::Result { let id = Uuid::new_v4(); let posted_on = chrono::Utc::now().timestamp_millis(); diff --git a/src/web/routes/api/webhooks/github/events/mod.rs b/src/web/routes/api/webhooks/github/events/mod.rs index 2a9db14..8f85289 100644 --- a/src/web/routes/api/webhooks/github/events/mod.rs +++ b/src/web/routes/api/webhooks/github/events/mod.rs @@ -6,21 +6,26 @@ use crate::database::{models::{self, tokens::Token}, Database}; use super::types::ReleaseEvent; -pub async fn release_handler(db: Data>, token: Token, body: ReleaseEvent, raw_body: String,) -> Result { +pub async fn release_handler(db: Data>, token: Token, body: ReleaseEvent, raw_body: String) -> Result { - let title = format!("{} has been released on {}!", body.release.tag_name, body.repository.full_name); - - dbg!(body); - // models::posts::Post::create_new( - // db.lock().unwrap().borrow_mut(), - // title, - // descr, - // img_url, - // origin_url, - // orignal_request - // ); + let title = format!("(New release {}:{}) {}", body.repository.full_name, body.release.tag_name, body.release.name.unwrap_or("No title provided".into())); + let origin_url = body.repository.html_url.clone(); + let descr = body.release.body.unwrap_or("No body provided".into()); + let img_url = body.repository.owner.avatar_url.clone(); + let res = models::posts::Post::create_new( + db.lock().unwrap().borrow_mut(), + title, + descr, + img_url, + origin_url, + raw_body + ).await; + if let Err(e) = res { + log::error!("{e}"); + return Ok(HttpResponse::InternalServerError()); + } Ok(HttpResponse::Ok()) diff --git a/src/web/routes/api/webhooks/github/mod.rs b/src/web/routes/api/webhooks/github/mod.rs index 49edae7..986f05e 100644 --- a/src/web/routes/api/webhooks/github/mod.rs +++ b/src/web/routes/api/webhooks/github/mod.rs @@ -50,7 +50,7 @@ pub async fn handler(req: HttpRequest, token: web::Path, body: Bytes, db match event { types::Event::Release(body) => events::release_handler(db, token, body, json).await, _ => { - dbg!(json); + // dbg!(json); Ok(HttpResponse::Ok()) } }