From 7b00314d36a33c1d180e8dd0b18bf1efbdc5e108 Mon Sep 17 00:00:00 2001 From: Nick Guenther Date: Sat, 25 Feb 2023 01:13:33 -0500 Subject: [PATCH] Debug --- bids-hook.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/bids-hook.go b/bids-hook.go index 9435694..703e32d 100644 --- a/bids-hook.go +++ b/bids-hook.go @@ -199,6 +199,7 @@ func installWebhook() error { // This is the hook we want to exist // Note: Gitea internally uses a CreateHookOption or a EditHookOption for these // which are two different subsets of the Hook type. So we're not being 100% correct here. + log.Printf("SECERT: %s", string(bidsHookSecret)) hook := Hook{ Type: "gitea", Config: map[string]string{ @@ -225,6 +226,7 @@ func installWebhook() error { } req.Header.Add("Authorization", fmt.Sprintf("token %s", giteaToken)) req.Header.Add("Accept", "application/json") + log.Printf("Calling %s %s\n", req.Method, url.String()) // DEBUG resp, err := http.DefaultClient.Do(req) if err != nil { @@ -243,11 +245,15 @@ func installWebhook() error { if err != nil { return err } + fmt.Printf("Read this: |%s|\n", body) // search the result for pre-existing webhook found := false var id int64 + fmt.Printf("hook: %#v\n", hook) // DEBUG for _, _hook := range hooks { + fmt.Printf("hook: %#v\n", _hook) // DEBUG if _hook.URL == hook.URL { + fmt.Printf("found at id: %#v\n", _hook.ID) // DEBUG found = true id = _hook.ID break @@ -260,6 +266,7 @@ func installWebhook() error { method = http.MethodPatch url = url.JoinPath(fmt.Sprintf("%d", id)) } + log.Printf("Calling %s %s\n", method, url.String()) // DEBUG req, err = http.NewRequest(method, url.String(), bytes.NewReader(hookJSON)) if err != nil { @@ -274,12 +281,14 @@ func installWebhook() error { return err } if resp.StatusCode != 200 && resp.StatusCode != 201 { + log.Printf("Bailing\n") return errors.New(fmt.Sprintf("got http status code %d", resp.StatusCode)) } body, err = ioutil.ReadAll(resp.Body) if err != nil { return err } + fmt.Printf("Read: |%s|\n", body) defer resp.Body.Close() return nil