Skip to content

fix(bitbucketdatacenter): ignore branch deletion events in ParsePayload #2126

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions pkg/provider/bitbucketdatacenter/parse_payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,13 @@ func (v *Provider) ParsePayload(_ context.Context, run *params.Run, request *htt
return nil, fmt.Errorf("push event contains no commits under 'changes'; cannot proceed")
}

// Check for branch deletion - if any change is a DELETE type with zero hash, skip processing
for _, change := range e.Changes {
if provider.IsZeroSHA(change.ToHash) && change.Type == "DELETE" {
return nil, fmt.Errorf("branch delete event is not supported; cannot proceed")
}
}

if len(e.Commits) == 0 {
return nil, fmt.Errorf("push event contains no commits; cannot proceed")
}
Expand Down
23 changes: 21 additions & 2 deletions pkg/provider/bitbucketdatacenter/parse_payload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,20 @@ func TestParsePayload(t *testing.T) {
expEvent: ev1,
wantSHA: "abcd",
},
{
name: "branch/deleted with zero hash",
eventType: "repo:refs_changed",
payloadEvent: bbv1test.MakePushEvent(ev1, []types.PushRequestEventChange{
{
ToHash: "0000000000000000000000000000000000000000",
RefID: "refs/heads/feature-branch",
Type: "DELETE",
},
}, []types.Commit{},
),
expEvent: ev1,
wantErrSubstr: "branch delete event is not supported; cannot proceed",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand All @@ -735,10 +749,15 @@ func TestParsePayload(t *testing.T) {
return
}
assert.NilError(t, err)

// Handle case where expEvent is nil (e.g., branch deletion)
if tt.expEvent == nil {
if got != nil {
t.Fatalf("expected event to be nil, got: %+v", got)
}
return
}
// assert SHA ID
assert.Equal(t, tt.wantSHA, got.SHA)

assert.Equal(t, got.AccountID, tt.expEvent.AccountID)

// test that we got slashed
Expand Down
Loading