Skip to content

Commit

Permalink
fix: hacking on bitbucket webhooks
Browse files Browse the repository at this point in the history
  • Loading branch information
robbert229 committed Mar 10, 2024
1 parent 01b4ca8 commit e08e8ce
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions internal/bitbucketserver/event_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"net/http"
"strings"

"github.com/davecgh/go-spew/spew"
bitbucketv1 "github.com/gfleury/go-bitbucket-v1"
"github.com/tofutf/tofutf/internal/vcs"
"golang.org/x/exp/slog"
Expand Down Expand Up @@ -49,8 +48,6 @@ func HandleEvent(r *http.Request, secret string) (*vcs.EventPayload, error) {
}
}

spew.Dump(event)

repoPath := ""

switch event.EventKey {
Expand All @@ -64,10 +61,11 @@ func HandleEvent(r *http.Request, secret string) (*vcs.EventPayload, error) {
return nil, fmt.Errorf("unable to handle multiple changes in a single push")
}

changeType := event.Changes[0].Ref.Type
refType := event.Changes[0].Ref.Type
actionType := event.Changes[0].Type
refID := event.Changes[0].Ref.ID

if changeType == "ADD" {
if refType == "TAG" && actionType == "ADD" {
tag := strings.TrimPrefix(refID, "refs/")
return &vcs.EventPayload{
RepoPath: repoPath,
Expand All @@ -77,7 +75,7 @@ func HandleEvent(r *http.Request, secret string) (*vcs.EventPayload, error) {
CommitSHA: event.Changes[0].ToHash,
DefaultBranch: "main", // TODO(johnrowl) need to change this.
}, nil
} else if changeType == "DELETE" {
} else if refType == "TAG" && actionType == "DELETE" {
tag := strings.TrimPrefix(refID, "refs/")
return &vcs.EventPayload{
RepoPath: repoPath,
Expand All @@ -89,6 +87,8 @@ func HandleEvent(r *http.Request, secret string) (*vcs.EventPayload, error) {
}, nil
}

slog.Error("unhandled push event", "event", event)

return nil, fmt.Errorf("failed to handle push event")
}

Expand Down

0 comments on commit e08e8ce

Please sign in to comment.