diff --git a/README.md b/README.md index 8f55e68..630637b 100644 --- a/README.md +++ b/README.md @@ -343,7 +343,7 @@ OPTIONS --webhook-success-status , $GIT_SYNC_WEBHOOK_SUCCESS_STATUS The HTTP status code indicating a successful --webhook-url. Setting - this to -1 disables success checks to make webhooks + this to 0 disables success checks, which makes webhooks "fire-and-forget". If not specified, this defaults to 200. --webhook-timeout , $GIT_SYNC_WEBHOOK_TIMEOUT diff --git a/cmd/git-sync/main.go b/cmd/git-sync/main.go index 75d8aa9..4a0cba7 100644 --- a/cmd/git-sync/main.go +++ b/cmd/git-sync/main.go @@ -102,7 +102,7 @@ var flWebhookURL = pflag.String("webhook-url", envString("GIT_SYNC_WEBHOOK_URL", var flWebhookMethod = pflag.String("webhook-method", envString("GIT_SYNC_WEBHOOK_METHOD", "POST"), "the HTTP method for the webhook") var flWebhookStatusSuccess = pflag.Int("webhook-success-status", envInt("GIT_SYNC_WEBHOOK_SUCCESS_STATUS", 200), - "the HTTP status code indicating a successful webhook (-1 disables success checks") + "the HTTP status code indicating a successful webhook (0 disables success checks") var flWebhookTimeout = pflag.Duration("webhook-timeout", envDuration("GIT_SYNC_WEBHOOK_TIMEOUT", time.Second), "the timeout for the webhook") var flWebhookBackoff = pflag.Duration("webhook-backoff", envDuration("GIT_SYNC_WEBHOOK_BACKOFF", time.Second*3), @@ -509,8 +509,12 @@ func main() { } if *flWebhookURL != "" { - if *flWebhookStatusSuccess < -1 { - handleConfigError(log, true, "ERROR: --webhook-success-status must be a valid HTTP code or -1") + if *flWebhookStatusSuccess == -1 { + // Back-compat: -1 and 0 mean the same things + *flWebhookStatusSuccess = 0 + } + if *flWebhookStatusSuccess < 0 { + handleConfigError(log, true, "ERROR: --webhook-success-status must be a valid HTTP code or 0") } if *flWebhookTimeout < time.Second { handleConfigError(log, true, "ERROR: --webhook-timeout must be at least 1s") @@ -2205,7 +2209,7 @@ OPTIONS --webhook-success-status , $GIT_SYNC_WEBHOOK_SUCCESS_STATUS The HTTP status code indicating a successful --webhook-url. Setting - this to -1 disables success checks to make webhooks + this to 0 disables success checks, which makes webhooks "fire-and-forget". If not specified, this defaults to 200. --webhook-timeout , $GIT_SYNC_WEBHOOK_TIMEOUT diff --git a/pkg/hook/webhook.go b/pkg/hook/webhook.go index 742faca..1f01918 100644 --- a/pkg/hook/webhook.go +++ b/pkg/hook/webhook.go @@ -74,7 +74,7 @@ func (w *Webhook) Do(ctx context.Context, hash string) error { resp.Body.Close() // If the webhook has a success statusCode, check against it - if w.success != -1 && resp.StatusCode != w.success { + if w.success > 0 && resp.StatusCode != w.success { return fmt.Errorf("received response code %d expected %d", resp.StatusCode, w.success) } diff --git a/test_e2e.sh b/test_e2e.sh index 095bfc8..57f33c2 100755 --- a/test_e2e.sh +++ b/test_e2e.sh @@ -1865,7 +1865,7 @@ function e2e::webhook_fire_and_forget() { --repo="file://$REPO" \ --root="$ROOT" \ --webhook-url="http://$IP" \ - --webhook-success-status=-1 \ + --webhook-success-status=0 \ --link="link" \ >> "$1" 2>&1 &