diff --git a/crates/forge-github/src/webhook/register.rs b/crates/forge-github/src/webhook/register.rs index bca17be..a283537 100644 --- a/crates/forge-github/src/webhook/register.rs +++ b/crates/forge-github/src/webhook/register.rs @@ -1,5 +1,5 @@ // -use crate as github; +use crate::{self as github, webhook}; use git_next_config as config; use git_next_git as git; @@ -15,8 +15,13 @@ pub async fn register( return Err(git::forge::webhook::Error::NoRepoConfig); }; - let net = &github.net; + // remove any lingering webhooks for the same URL + let existing_webhook_ids = webhook::list(github, webhook_url).await?; + for webhook_id in existing_webhook_ids { + webhook::unregister(github, &webhook_id).await?; + } + let net = &github.net; let hostname = repo_details.forge.hostname(); let authorisation = config::WebhookAuth::generate(); let request = network::NetRequest::new(