Skip to content

Commit

Permalink
Debug
Browse files Browse the repository at this point in the history
  • Loading branch information
kousu committed Feb 25, 2023
1 parent e90fb33 commit 13fae9d
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions bids-hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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 {
Expand All @@ -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
Expand All @@ -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 {
Expand All @@ -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
Expand Down

0 comments on commit 13fae9d

Please sign in to comment.