Skip to content

Commit e9febd3

Browse files
zakisksavitaashture
authored andcommitted
fix: PAC controller crash on empty changes in BDC
fixed crash on push when there are no changes in in event payload in Bitbucket Data Center. https://issues.redhat.com/browse/SRVKP-7522 Signed-off-by: Zaki Shaikh <zashaikh@redhat.com>
1 parent 031011b commit e9febd3

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

pkg/provider/bitbucketserver/parse_payload.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,11 @@ func (v *Provider) ParsePayload(_ context.Context, _ *params.Run, request *http.
159159
processedEvent.EventType = triggertype.Push.String()
160160
processedEvent.Organization = e.Repository.Project.Key
161161
processedEvent.Repository = e.Repository.Slug
162+
163+
if len(e.Changes) == 0 {
164+
return nil, fmt.Errorf("push event contains no commits under 'changes'; cannot proceed")
165+
}
166+
162167
processedEvent.SHA = e.Changes[0].ToHash
163168
processedEvent.URL = e.Repository.Links.Self[0].Href
164169
processedEvent.BaseBranch = e.Changes[0].RefID

pkg/provider/bitbucketserver/parse_payload_test.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,9 +612,16 @@ func TestParsePayload(t *testing.T) {
612612
{
613613
name: "good/push",
614614
eventType: "repo:refs_changed",
615-
payloadEvent: bbv1test.MakePushEvent(ev1),
615+
payloadEvent: bbv1test.MakePushEvent(ev1, []types.PushRequestEventChange{{ToHash: ev1.SHA, RefID: "base"}}),
616616
expEvent: ev1,
617617
},
618+
{
619+
name: "bad/changes are empty in push",
620+
eventType: "repo:refs_changed",
621+
payloadEvent: bbv1test.MakePushEvent(ev1, []types.PushRequestEventChange{}),
622+
expEvent: ev1,
623+
wantErrSubstr: "push event contains no commits under 'changes'; cannot proceed",
624+
},
618625
{
619626
name: "good/comment ok-to-test",
620627
eventType: "pr:comment:added",

pkg/provider/bitbucketserver/test/test.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ func MakePREvent(event *info.Event, comment string) *types.PullRequestEvent {
330330
return pr
331331
}
332332

333-
func MakePushEvent(event *info.Event) *types.PushRequestEvent {
333+
func MakePushEvent(event *info.Event, changes []types.PushRequestEventChange) *types.PushRequestEvent {
334334
iii, _ := strconv.Atoi(event.AccountID)
335335

336336
return &types.PushRequestEvent{
@@ -357,11 +357,6 @@ func MakePushEvent(event *info.Event) *types.PushRequestEvent {
357357
},
358358
},
359359
},
360-
Changes: []types.PushRequestEventChange{
361-
{
362-
ToHash: event.SHA,
363-
RefID: "base",
364-
},
365-
},
360+
Changes: changes,
366361
}
367362
}

0 commit comments

Comments
 (0)