fix: github: restarting server creates duplicate webhook for repo
All checks were successful
Rust / build (push) Successful in 1m18s
ci/woodpecker/push/cron-docker-builder Pipeline was successful
ci/woodpecker/push/push-next Pipeline was successful
ci/woodpecker/push/tag-created Pipeline was successful

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
This commit is contained in:
Paul Campbell 2024-06-30 12:23:42 +01:00
parent 975c9e315c
commit db90280641

View file

@ -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(