feat(server/webhook): implement unregister webhook
Closes kemitix/git-next#17
This commit is contained in:
parent
df2d9d684c
commit
e7060800eb
2 changed files with 33 additions and 11 deletions
|
@ -39,9 +39,8 @@ impl Actor for RepoActor {
|
|||
match self.webhook_id.take() {
|
||||
Some(webhook_id) => {
|
||||
let repo_details = self.details.clone();
|
||||
let addr = ctx.address();
|
||||
let net = self.net.clone();
|
||||
webhook::unregister(webhook_id, repo_details, addr, net)
|
||||
webhook::unregister(webhook_id, repo_details, net)
|
||||
.into_actor(self)
|
||||
.wait(ctx);
|
||||
Running::Continue
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
use actix::prelude::*;
|
||||
use tracing::info;
|
||||
use kxio::network;
|
||||
use tracing::{info, warn};
|
||||
|
||||
use std::ops::Deref;
|
||||
use std::{fmt::Display, ops::Deref};
|
||||
|
||||
use crate::server::actors::{
|
||||
repo::{RepoActor, ValidateRepo},
|
||||
|
@ -22,21 +23,43 @@ impl Deref for WebhookId {
|
|||
&self.0
|
||||
}
|
||||
}
|
||||
impl Display for WebhookId {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "{}", 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,
|
||||
webhook_id: WebhookId,
|
||||
repo_details: crate::server::config::RepoDetails,
|
||||
net: network::Network,
|
||||
) {
|
||||
// TODO: (#17) unregister webhook
|
||||
// on success - stop the actor
|
||||
info!(?webhook_id, "unregister webhook");
|
||||
let hostname = &repo_details.forge.hostname;
|
||||
let path = repo_details.repo;
|
||||
let url = network::NetUrl::new(format!(
|
||||
"https://{hostname}/api/v1/repos/{path}/hooks/{webhook_id}"
|
||||
));
|
||||
let request = network::NetRequest::new(
|
||||
network::RequestMethod::Delete,
|
||||
url,
|
||||
network::NetRequestHeaders::new(),
|
||||
network::RequestBody::None,
|
||||
network::ResponseType::Json,
|
||||
None,
|
||||
network::NetRequestLogging::None,
|
||||
);
|
||||
let result = net.delete(request).await;
|
||||
match result {
|
||||
Ok(_) => info!(?webhook_id, "unregistered webhook"),
|
||||
Err(_) => warn!(?webhook_id, "Failed to unregister webhook"),
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn register(
|
||||
_repo_details: crate::server::config::RepoDetails,
|
||||
addr: actix::prelude::Addr<super::RepoActor>,
|
||||
_net: kxio::network::Network,
|
||||
_net: network::Network,
|
||||
) {
|
||||
// TODO: (#15) register webhook - on success send webhook id to RepoActor
|
||||
tokio::time::sleep(std::time::Duration::from_secs(10)).await;
|
||||
|
|
Loading…
Reference in a new issue