Skip to content

Commit 915cc6f

Browse files
zakiskchmouel
authored andcommitted
fix: inavlidate empty commits in push events in bitbucket dc
invalidated empty commits in push in bitbucket data center as we may want to check commit field for commit SHA. Signed-off-by: Zaki Shaikh <[email protected]>
1 parent 9324dc4 commit 915cc6f

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

pkg/provider/bitbucketdatacenter/parse_payload.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,10 @@ func (v *Provider) ParsePayload(_ context.Context, _ *params.Run, request *http.
164164
return nil, fmt.Errorf("push event contains no commits under 'changes'; cannot proceed")
165165
}
166166

167+
if len(e.Commits) == 0 {
168+
return nil, fmt.Errorf("push event contains no commits; cannot proceed")
169+
}
170+
167171
processedEvent.SHA = e.Changes[0].ToHash
168172
processedEvent.URL = e.Repository.Links.Self[0].Href
169173
processedEvent.BaseBranch = e.Changes[0].RefID

pkg/provider/bitbucketdatacenter/parse_payload_test.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -611,16 +611,23 @@ func TestParsePayload(t *testing.T) {
611611
{
612612
name: "good/push",
613613
eventType: "repo:refs_changed",
614-
payloadEvent: bbv1test.MakePushEvent(ev1, []types.PushRequestEventChange{{ToHash: ev1.SHA, RefID: "base"}}),
614+
payloadEvent: bbv1test.MakePushEvent(ev1, []types.PushRequestEventChange{{ToHash: ev1.SHA, RefID: "base"}}, []types.Commit{{ID: ev1.SHA}}),
615615
expEvent: ev1,
616616
},
617617
{
618618
name: "bad/changes are empty in push",
619619
eventType: "repo:refs_changed",
620-
payloadEvent: bbv1test.MakePushEvent(ev1, []types.PushRequestEventChange{}),
620+
payloadEvent: bbv1test.MakePushEvent(ev1, []types.PushRequestEventChange{}, []types.Commit{}),
621621
expEvent: ev1,
622622
wantErrSubstr: "push event contains no commits under 'changes'; cannot proceed",
623623
},
624+
{
625+
name: "bad/commits are empty in push",
626+
eventType: "repo:refs_changed",
627+
payloadEvent: bbv1test.MakePushEvent(ev1, []types.PushRequestEventChange{{ToHash: ev1.SHA, RefID: "base"}}, []types.Commit{}),
628+
expEvent: ev1,
629+
wantErrSubstr: "push event contains no commits; cannot proceed",
630+
},
624631
{
625632
name: "good/comment ok-to-test",
626633
eventType: "pr:comment:added",

pkg/provider/bitbucketdatacenter/test/test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ func MakePREvent(event *info.Event, comment string) *types.PullRequestEvent {
338338
return pr
339339
}
340340

341-
func MakePushEvent(event *info.Event, changes []types.PushRequestEventChange) *types.PushRequestEvent {
341+
func MakePushEvent(event *info.Event, changes []types.PushRequestEventChange, commits []types.Commit) *types.PushRequestEvent {
342342
iii, _ := strconv.Atoi(event.AccountID)
343343

344344
return &types.PushRequestEvent{
@@ -366,5 +366,6 @@ func MakePushEvent(event *info.Event, changes []types.PushRequestEventChange) *t
366366
},
367367
},
368368
Changes: changes,
369+
Commits: commits,
369370
}
370371
}

0 commit comments

Comments
 (0)