git-next/crates/repo-actor/src/handlers/register_webhook.rs
Paul Campbell ffab1986a7
Some checks failed
ci/woodpecker/cron/cron-docker-builder Pipeline was successful
ci/woodpecker/cron/push-next Pipeline was successful
ci/woodpecker/cron/tag-created Pipeline was successful
ci/woodpecker/push/cron-docker-builder Pipeline was successful
ci/woodpecker/push/push-next Pipeline was successful
Rust / build (push) Has been cancelled
ci/woodpecker/push/tag-created Pipeline was successful
refactor: repo-actor: rewrite tests using mockall
2024-06-27 18:58:47 +01:00

39 lines
1.4 KiB
Rust

//
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");
}
}
}