Skip to content

Commit

Permalink
Make --webhook-success-status=0 the same as -1
Browse files Browse the repository at this point in the history
  • Loading branch information
thockin committed Apr 29, 2023
1 parent 20ed7df commit e84a4cb
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ OPTIONS
--webhook-success-status <int>, $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 <duration>, $GIT_SYNC_WEBHOOK_TIMEOUT
Expand Down
12 changes: 8 additions & 4 deletions cmd/git-sync/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -2205,7 +2209,7 @@ OPTIONS
--webhook-success-status <int>, $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 <duration>, $GIT_SYNC_WEBHOOK_TIMEOUT
Expand Down
2 changes: 1 addition & 1 deletion pkg/hook/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion test_e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 &

Expand Down

0 comments on commit e84a4cb

Please sign in to comment.