Clarify success-status config/option

This commit is contained in:
Thomas Jackson 2019-01-22 14:00:40 -08:00
parent 54ec971ba0
commit ad41260327
2 changed files with 5 additions and 5 deletions

View File

@ -67,7 +67,7 @@ var flWebhookURL = flag.String("webhook-url", envString("GIT_SYNC_WEBHOOK_URL",
var flWebhookMethod = flag.String("webhook-method", envString("GIT_SYNC_WEBHOOK_METHOD", "POST"), var flWebhookMethod = flag.String("webhook-method", envString("GIT_SYNC_WEBHOOK_METHOD", "POST"),
"the method for the webook to send with") "the method for the webook to send with")
var flWebhookStatusSuccess = flag.Int("webhook-success-status", envInt("GIT_SYNC_WEBHOOK_SUCCESS_STATUS", 200), var flWebhookStatusSuccess = flag.Int("webhook-success-status", envInt("GIT_SYNC_WEBHOOK_SUCCESS_STATUS", 200),
"the status code which indicates a successful webhook call") "the status code which indicates a successful webhook call. A value of -1 disables success checks to make webhooks fire-and-forget")
var flWebhookTimeout = flag.Duration("webhook-timeout", envDuration("GIT_SYNC_WEBHOOK_TIMEOUT", time.Second), var flWebhookTimeout = flag.Duration("webhook-timeout", envDuration("GIT_SYNC_WEBHOOK_TIMEOUT", time.Second),
"the timeout used when communicating with the webhook target") "the timeout used when communicating with the webhook target")
var flWebhookBackoff = flag.Duration("webhook-backoff", envDuration("GIT_SYNC_WEBHOOK_BACKOFF", time.Second*3), var flWebhookBackoff = flag.Duration("webhook-backoff", envDuration("GIT_SYNC_WEBHOOK_BACKOFF", time.Second*3),
@ -217,7 +217,7 @@ func main() {
webhook := Webhook{ webhook := Webhook{
URL: *flWebhookURL, URL: *flWebhookURL,
Method: *flWebhookMethod, Method: *flWebhookMethod,
Success: flWebhookStatusSuccess, Success: *flWebhookStatusSuccess,
Timeout: *flWebhookTimeout, Timeout: *flWebhookTimeout,
Backoff: *flWebhookBackoff, Backoff: *flWebhookBackoff,
} }

View File

@ -15,7 +15,7 @@ type Webhook struct {
Method string Method string
// Code to look for when determining if the request was successful. // Code to look for when determining if the request was successful.
// If this is not specified, request is sent and forgotten about. // If this is not specified, request is sent and forgotten about.
Success *int Success int
// Timeout for the http/s request // Timeout for the http/s request
Timeout time.Duration Timeout time.Duration
// Backoff for failed webhook calls // Backoff for failed webhook calls
@ -40,8 +40,8 @@ func (w *Webhook) Do() error {
resp.Body.Close() resp.Body.Close()
// If the webhook has a success statusCode, check against it // If the webhook has a success statusCode, check against it
if w.Success != nil && resp.StatusCode != *w.Success { if w.Success != -1 && resp.StatusCode != w.Success {
return fmt.Errorf("received response code %d expected %d", resp.StatusCode, *w.Success) return fmt.Errorf("received response code %d expected %d", resp.StatusCode, w.Success)
} }
return nil return nil