func()

in pkg/hook/webhook.go [60:84]


func (w *Webhook) Do(ctx context.Context, hash string) error {
	req, err := http.NewRequest(w.method, w.url, nil)
	if err != nil {
		return err
	}
	req.Header.Set("Gitsync-Hash", hash)

	ctx, cancel := context.WithTimeout(ctx, w.timeout)
	defer cancel()
	req = req.WithContext(ctx)

	w.logger.V(0).Info("sending webhook", "hash", hash, "url", w.url, "method", w.method, "timeout", w.timeout)
	resp, err := http.DefaultClient.Do(req)
	if err != nil {
		return err
	}
	resp.Body.Close()

	// If the webhook has a success statusCode, check against it
	if w.success != -1 && resp.StatusCode != w.success {
		return fmt.Errorf("received response code %d expected %d", resp.StatusCode, w.success)
	}

	return nil
}