Skip to content

Commit

Permalink
feat: made bitbucket pushes trigger tofutf webhooks
Browse files Browse the repository at this point in the history
  • Loading branch information
robbert229 committed Mar 9, 2024
1 parent 26d9d45 commit 57ee251
Showing 1 changed file with 7 additions and 43 deletions.
50 changes: 7 additions & 43 deletions internal/bitbucketserver/event_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,67 +67,31 @@ func HandleEvent(r *http.Request, secret string) (*vcs.EventPayload, error) {
changeType := event.Changes[0].Ref.Type
refID := event.Changes[0].Ref.ID

if changeType == "TAG" {
refParts := strings.Split(refID, "/")
if len(refParts) != 3 {
return nil, fmt.Errorf("malformed ref: %s", refID)
}

if changeType == "ADD" {
tag := strings.TrimPrefix(refID, "refs/")
return &vcs.EventPayload{
RepoPath: repoPath,
VCSKind: vcs.BitbucketServer,
Tag: refParts[2],
Tag: tag,
Action: vcs.ActionCreated,
CommitSHA: event.Changes[0].ToHash,
DefaultBranch: "main", // TODO(johnrowl) need to change this.
}, nil
} else if changeType == "BRANCH" {
refParts := strings.Split(refID, "/")
if len(refParts) != 3 {
return nil, fmt.Errorf("malformed ref: %s", refID)
}

} else if changeType == "DELETE" {
tag := strings.TrimPrefix(refID, "refs/")
return &vcs.EventPayload{
RepoPath: repoPath,
VCSKind: vcs.BitbucketServer,
Branch: refParts[2],
Tag: tag,
Action: vcs.ActionCreated,
CommitSHA: event.Changes[0].ToHash,
DefaultBranch: "main", // TODO(johnrowl) need to change this.
}, nil
}

// return &cloud.VCSEvent{

// }, nil

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

// switch event := rawEvent.(type) {
// case *gitlab.PushEvent:
// refParts := strings.Split(event.Ref, "/")
// if len(refParts) != 3 {
// return nil, fmt.Errorf("malformed ref: %s", event.Ref)
// }
// return &cloud.VCSEvent{
// Branch: refParts[2],
// CommitSHA: event.After,
// DefaultBranch: event.Project.DefaultBranch,
// }, nil
// case *gitlab.TagEvent:
// refParts := strings.Split(event.Ref, "/")
// if len(refParts) != 3 {
// return nil, fmt.Errorf("malformed ref: %s", event.Ref)
// }
// return &cloud.VCSEvent{
// Tag: refParts[2],
// // Action: action,
// CommitSHA: event.After,
// DefaultBranch: event.Project.DefaultBranch,
// }, nil
// case *gitlab.MergeEvent:
// }

return nil, nil
}

Expand Down

0 comments on commit 57ee251

Please sign in to comment.