git-next/crates/repo-actor/src/handlers/register_webhook.rs

40 lines
1.4 KiB
Rust
Raw Normal View History

//
use actix::prelude::*;
use tracing::Instrument as _;
use crate as actor;
use actor::{messages::RegisterWebhook, RepoActor};
impl Handler<RegisterWebhook> for RepoActor {
type Result = ();
fn handle(&mut self, _msg: RegisterWebhook, ctx: &mut Self::Context) -> Self::Result {
if self.webhook_id.is_none() {
let forge_alias = self.repo_details.forge.forge_alias();
let repo_alias = &self.repo_details.repo_alias;
let webhook_url = self.webhook.url(forge_alias, repo_alias);
let forge = self.forge.duplicate();
let addr = ctx.address();
let log = self.log.clone();
tracing::debug!("registering webhook");
async move {
match forge.register_webhook(&webhook_url).await {
Ok(registered_webhook) => {
tracing::debug!(?registered_webhook, "");
actor::do_send(
addr,
actor::messages::WebhookRegistered::from(registered_webhook),
&log,
);
}
Err(err) => tracing::warn!(?err, "registering webhook"),
}
}
.in_current_span()
.into_actor(self)
.wait(ctx);
tracing::debug!("registering webhook done");
}
}
}