33 lines
1 KiB
Rust
33 lines
1 KiB
Rust
|
//
|
||
|
use crate as github;
|
||
|
use git_next_config as config;
|
||
|
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,
|
||
|
webhook_id: &config::WebhookId,
|
||
|
) -> git::forge::webhook::Result<()> {
|
||
|
let net = &github.net;
|
||
|
let repo_details = &github.repo_details;
|
||
|
let request = network::NetRequest::new(
|
||
|
network::RequestMethod::Delete,
|
||
|
network::NetUrl::new(format!(
|
||
|
"https://api.github.com/repos/{}/hooks/{}",
|
||
|
repo_details.repo_path, webhook_id
|
||
|
)),
|
||
|
github::webhook::headers(repo_details.forge.token()),
|
||
|
network::RequestBody::None,
|
||
|
network::ResponseType::None,
|
||
|
None,
|
||
|
network::NetRequestLogging::None,
|
||
|
);
|
||
|
if let Err(e) = net.post_json::<github::GithubHook>(request).await {
|
||
|
tracing::warn!("Failed to register webhook");
|
||
|
return Err(git::forge::webhook::Error::FailedToRegister(e.to_string()));
|
||
|
}
|
||
|
Ok(())
|
||
|
}
|