git-next/src/server/actors/repo/webhook.rs

56 lines
1.4 KiB
Rust
Raw Normal View History

use actix::prelude::*;
use tracing::info;
use std::ops::Deref;
use crate::server::actors::{
repo::{RepoActor, ValidateRepo},
webhook::WebhookMessage,
};
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct WebhookId(String);
impl WebhookId {
#[allow(dead_code)]
pub const fn new(id: String) -> Self {
Self(id)
}
}
impl Deref for WebhookId {
type Target = String;
fn deref(&self) -> &Self::Target {
&self.0
}
}
pub async fn unregister(
_webhook_id: WebhookId,
_repo_details: crate::server::config::RepoDetails,
_addr: actix::prelude::Addr<super::RepoActor>,
_net: kxio::network::Network,
) {
// TODO: (#17) unregister webhook
// on success - stop the actor
}
pub async fn register(
_repo_details: crate::server::config::RepoDetails,
addr: actix::prelude::Addr<super::RepoActor>,
_net: kxio::network::Network,
) {
// TODO: (#15) register webhook - on success send webhook id to RepoActor
tokio::time::sleep(std::time::Duration::from_secs(10)).await;
addr.do_send(ValidateRepo);
}
impl Handler<WebhookMessage> for RepoActor {
type Result = ();
fn handle(&mut self, msg: WebhookMessage, _ctx: &mut Self::Context) -> Self::Result {
let id = msg.id();
let body = msg.body();
info!(?id, ?body, "RepoActor received message");
// TODO: (#43) do something with the message
}
}