2024-05-31 07:37:40 +01:00
|
|
|
//
|
|
|
|
use crate as github;
|
2024-07-25 09:02:43 +01:00
|
|
|
|
|
|
|
use git_next_core::WebhookId;
|
2024-05-31 07:37:40 +01:00
|
|
|
use git_next_git as git;
|
|
|
|
|
|
|
|
use kxio::network;
|
|
|
|
|
|
|
|
// https://docs.github.com/en/rest/repos/webhooks?apiVersion=2022-11-28#delete-a-repository-webhook
|
|
|
|
pub async fn unregister(
|
|
|
|
github: &github::Github,
|
2024-07-25 09:02:43 +01:00
|
|
|
webhook_id: &WebhookId,
|
2024-05-31 07:37:40 +01:00
|
|
|
) -> git::forge::webhook::Result<()> {
|
|
|
|
let net = &github.net;
|
|
|
|
let repo_details = &github.repo_details;
|
2024-06-04 18:30:11 +01:00
|
|
|
let hostname = repo_details.forge.hostname();
|
2024-05-31 07:37:40 +01:00
|
|
|
let request = network::NetRequest::new(
|
|
|
|
network::RequestMethod::Delete,
|
|
|
|
network::NetUrl::new(format!(
|
2024-06-04 18:30:11 +01:00
|
|
|
"https://api.{hostname}/repos/{}/hooks/{}",
|
2024-05-31 07:37:40 +01:00
|
|
|
repo_details.repo_path, webhook_id
|
|
|
|
)),
|
|
|
|
github::webhook::headers(repo_details.forge.token()),
|
|
|
|
network::RequestBody::None,
|
|
|
|
network::ResponseType::None,
|
|
|
|
None,
|
|
|
|
network::NetRequestLogging::None,
|
|
|
|
);
|
2024-06-04 18:30:11 +01:00
|
|
|
net.delete(request)
|
|
|
|
.await
|
|
|
|
.map_err(|e| git::forge::webhook::Error::FailedToRegister(e.to_string()))
|
|
|
|
.map(|_| ())
|
2024-05-31 07:37:40 +01:00
|
|
|
}
|