webhooks
This commit is contained in:
parent
83b9d04c7c
commit
644bb4dbec
|
@ -1,36 +1 @@
|
||||||
use std::{borrow::BorrowMut, sync::Mutex};
|
pub mod release;
|
||||||
|
|
||||||
use actix_web::{web::Data, HttpResponse, HttpResponseBuilder, Result};
|
|
||||||
|
|
||||||
use crate::database::{models, Database};
|
|
||||||
|
|
||||||
use super::types::ReleaseEvent;
|
|
||||||
|
|
||||||
pub async fn release_handler(db: Data<Mutex<Database>>, body: ReleaseEvent, raw_body: String) -> Result<HttpResponseBuilder> {
|
|
||||||
|
|
||||||
if body.action != "released" {
|
|
||||||
return Ok(HttpResponse::Ok());
|
|
||||||
}
|
|
||||||
|
|
||||||
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())
|
|
||||||
}
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
use std::{borrow::BorrowMut, sync::Mutex};
|
||||||
|
|
||||||
|
use actix_web::{web::Data, HttpResponse, HttpResponseBuilder, Result};
|
||||||
|
|
||||||
|
use crate::{database::{models, Database}, web::routes::api::webhooks::github::types::ReleaseEvent};
|
||||||
|
|
||||||
|
|
||||||
|
pub async fn release_handler(db: Data<Mutex<Database>>, body: ReleaseEvent, raw_body: String) -> Result<HttpResponseBuilder> {
|
||||||
|
|
||||||
|
if body.action != "released" {
|
||||||
|
return Ok(HttpResponse::Ok());
|
||||||
|
}
|
||||||
|
|
||||||
|
let title = format!("Release {}: {}", body.repository.full_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())
|
||||||
|
}
|
|
@ -52,7 +52,7 @@ pub async fn handler(req: HttpRequest, token: web::Path<String>, body: Bytes, db
|
||||||
};
|
};
|
||||||
|
|
||||||
match event {
|
match event {
|
||||||
types::Event::Release(body) => events::release_handler(db, body, json).await,
|
types::Event::Release(body) => events::release::release_handler(db, body, json).await,
|
||||||
_ => {
|
_ => {
|
||||||
// dbg!(json);
|
// dbg!(json);
|
||||||
Ok(HttpResponse::Ok())
|
Ok(HttpResponse::Ok())
|
||||||
|
|
Loading…
Reference in New Issue
Block a user