From db9028064188d766fc1ff872b81f63d1f6758fdd Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Sun, 30 Jun 2024 12:23:42 +0100 Subject: [PATCH] fix: github: restarting server creates duplicate webhook for repo The Github routine for registering a new webhook, wasn't removing any existing matching webhooks. There is a test for this, but it doesn't assert that the delete requests are made. (This is a limitation of kxio). Closes kemitix/git-next#102 --- crates/forge-github/src/webhook/register.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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(