From 64632af3f71697a7749136bbe62ece2d6d8fa9a5 Mon Sep 17 00:00:00 2001 From: Ryan McKinley Date: Mon, 24 Feb 2025 22:42:15 +0300 Subject: [PATCH] Provisioning: Avoid localhost error loop (#101253) --- .../apis/provisioning/repository/github.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/pkg/registry/apis/provisioning/repository/github.go b/pkg/registry/apis/provisioning/repository/github.go index 4d21b1f28ae..17c58b4c103 100644 --- a/pkg/registry/apis/provisioning/repository/github.go +++ b/pkg/registry/apis/provisioning/repository/github.go @@ -819,13 +819,23 @@ func (r *githubRepository) deleteWebhook(ctx context.Context) error { return nil } +func (r *githubRepository) supportsWebhook() bool { + u, err := url.Parse(r.webhookURL) + if err != nil || u.Hostname() == "localhost" { + return false + } + return true +} + func (r *githubRepository) OnCreate(ctx context.Context) (*provisioning.WebhookStatus, error) { + if !r.supportsWebhook() { + return nil, nil + } ctx, _ = r.logger(ctx, "") hook, err := r.createWebhook(ctx) if err != nil { return nil, err } - return &provisioning.WebhookStatus{ ID: hook.ID, URL: hook.URL, @@ -835,6 +845,9 @@ func (r *githubRepository) OnCreate(ctx context.Context) (*provisioning.WebhookS } func (r *githubRepository) OnUpdate(ctx context.Context) (*provisioning.WebhookStatus, error) { + if !r.supportsWebhook() { + return nil, nil + } ctx, _ = r.logger(ctx, "") hook, _, err := r.updateWebhook(ctx) if err != nil {