// use git_next_core::{git, server::RepoListenUrl, WebhookId}; use kxio::network; use crate::webhook::Hook; pub async fn list( repo_details: &git::RepoDetails, repo_listen_url: &RepoListenUrl, net: &network::Network, ) -> git::forge::webhook::Result> { let mut ids: Vec = vec![]; let hostname = &repo_details.forge.hostname(); let repo_path = &repo_details.repo_path; let mut page = 1; loop { use secrecy::ExposeSecret; let token = &repo_details.forge.token().expose_secret(); let url = format!("https://{hostname}/api/v1/repos/{repo_path}/hooks?page={page}&token={token}"); let net_url = network::NetUrl::new(url); let request = network::NetRequest::new( network::RequestMethod::Get, net_url, network::NetRequestHeaders::new(), network::RequestBody::None, network::ResponseType::Json, None, network::NetRequestLogging::None, ); let result = net.get::>(request).await; match result { Ok(response) => { if let Some(list) = response.response_body() { if list.is_empty() { return Ok(ids); } for hook in list { if let Some(existing_url) = hook.config.get("url") { if existing_url.starts_with(&repo_listen_url.to_string()) { ids.push(hook.id()); } } } page += 1; } } Err(e) => { return Err(git::forge::webhook::Error::Network(e)); } }; } }