Skip to content

Commit

Permalink
fix: main changes to processDeleteEvent() to get things working
Browse files Browse the repository at this point in the history
  • Loading branch information
Claire.Nicholas authored and Claire.Nicholas committed Jan 16, 2024
1 parent 8662409 commit 7c25580
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 37 deletions.
16 changes: 15 additions & 1 deletion api/webhook/post.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,12 +367,26 @@ func PostWebhook(c *gin.Context) {
b.SetHeadRef(headref)
}

// if the event is delete,
// call SCM for more data not provided in webhook payload
if strings.EqualFold(b.GetEvent(), constants.EventDelete) {
// send API call to capture the commit sha for the branch
_, commit, err := scm.FromContext(c).GetBranch(ctx, u, r, r.GetBranch())
if err != nil {
retErr := fmt.Errorf("failed to get commit for repo %s on %s branch: %w", r.GetFullName(), r.GetBranch(), err)
util.HandleError(c, http.StatusInternalServerError, retErr)
}

b.SetCommit(commit)
}

// variable to store changeset files
var files []string

// check if the build event is not issue_comment or pull_request
if !strings.EqualFold(b.GetEvent(), constants.EventComment) &&
!strings.EqualFold(b.GetEvent(), constants.EventPull) {
!strings.EqualFold(b.GetEvent(), constants.EventPull) &&
!strings.EqualFold(b.GetEvent(), constants.EventDelete) {
// send API call to capture list of files changed for the commit
files, err = scm.FromContext(c).Changeset(ctx, u, repo, b.GetCommit())
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require (
github.com/drone/envsubst v1.0.3
github.com/gin-gonic/gin v1.9.1
github.com/go-playground/assert/v2 v2.2.0
github.com/go-vela/types v0.22.1-0.20240111192144-0d0e22367796
github.com/go-vela/types v0.22.1-0.20240115212525-483bff0c8693
github.com/golang-jwt/jwt/v5 v5.1.0
github.com/google/go-cmp v0.6.0
github.com/google/go-github/v56 v56.0.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ github.com/go-vela/types v0.22.1-0.20240105182535-a91bd54636bc h1:S59SXYfqFTJeuI
github.com/go-vela/types v0.22.1-0.20240105182535-a91bd54636bc/go.mod h1:cax3mW1kVz/ioI8qltZE+wl9rOLgOPdwBIvCooL09e4=
github.com/go-vela/types v0.22.1-0.20240111192144-0d0e22367796 h1:fjma5QAoncoknvTOp2AL/qYDOt4liWkZS5+sUaCQKJw=
github.com/go-vela/types v0.22.1-0.20240111192144-0d0e22367796/go.mod h1:cax3mW1kVz/ioI8qltZE+wl9rOLgOPdwBIvCooL09e4=
github.com/go-vela/types v0.22.1-0.20240115212525-483bff0c8693 h1:hF7S/clsM2rdruxgkRceQSttjl0iMur1ZhYHxGbNXtY=
github.com/go-vela/types v0.22.1-0.20240115212525-483bff0c8693/go.mod h1:cax3mW1kVz/ioI8qltZE+wl9rOLgOPdwBIvCooL09e4=
github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
Expand Down
Binary file removed scm/github/__debug_bin273415630
Binary file not shown.
41 changes: 6 additions & 35 deletions scm/github/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -528,16 +528,15 @@ func (c *client) processDeleteEvent(h *library.Hook, payload *github.DeleteEvent
b := new(library.Build)
b.SetEvent(constants.EventDelete)
b.SetClone(repo.GetCloneURL())
//b.SetSource(payload.GetHeadCommit().GetURL())
b.SetEventAction(payload.GetRefType())
b.SetTitle(fmt.Sprintf("%s received from %s", constants.EventDelete, repo.GetHTMLURL()))
//b.SetMessage(payload.GetHeadCommit().GetMessage())
//b.SetCommit(payload.GetHeadCommit().GetID())
b.SetMessage(fmt.Sprintf("%s %s deleted", payload.GetRef(), payload.GetRefType()))
b.SetSender(payload.GetSender().GetLogin())
//b.SetAuthor(payload.GetDelete())
//b.SetEmail(payload.GetHeadCommit().GetAuthor().GetEmail())
b.SetAuthor(payload.GetSender().GetLogin())
b.SetEmail(payload.GetSender().GetEmail())
b.SetBranch(strings.TrimPrefix(payload.GetRef(), "refs/heads/"))
b.SetRef(payload.GetRef())
//b.SetBaseRef(payload.GetBaseRef())
b.SetRef(repo.GetDefaultBranch())
b.SetSource(payload.GetRepo().GetOwner().GetHTMLURL())

// update the hook object
h.SetBranch(b.GetBranch())
Expand All @@ -546,34 +545,6 @@ func (c *client) processDeleteEvent(h *library.Hook, payload *github.DeleteEvent
fmt.Sprintf("https://%s/%s/settings/hooks", h.GetHost(), r.GetFullName()),
)

// ensure the build author is set
//if len(b.GetAuthor()) == 0 {
// b.SetAuthor(payload.GetHeadCommit().GetCommitter().GetName())
//}

// ensure the build sender is set
//if len(b.GetSender()) == 0 {
// b.SetSender(payload.GetPusher().GetName())
//}

// ensure the build email is set
//if len(b.GetEmail()) == 0 {
// b.SetEmail(payload.GetHeadCommit().GetCommitter().GetEmail())
//}

// handle when push event is a tag
//if strings.HasPrefix(b.GetRef(), "refs/tags/") {
// set the proper event for the hook
// h.SetEvent(constants.EventTag)
// set the proper event for the build
// b.SetEvent(constants.EventTag)

// set the proper branch from the base ref
// if strings.HasPrefix(payload.GetBaseRef(), "refs/heads/") {
// b.SetBranch(strings.TrimPrefix(payload.GetBaseRef(), "refs/heads/"))
// }
//}

return &types.Webhook{
Hook: h,
Repo: r,
Expand Down

0 comments on commit 7c25580

Please sign in to comment.