Provisioning: Avoid localhost error loop (#101253)

This commit is contained in:
Ryan McKinley authored and GitHub committed 2025-02-24 22:42:15 +03:00
1 parent 926eb3f82f
commit 64632af3f7
1 file changed
+14 -1
@@ -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 {