Skip to content

Commit 023e178

Browse files
committed
fix(bitbucketdatacenter): ignore branch deletion events in ParsePayload
When a branch is deleted in Bitbucket Data Center, the repo:refs_changed webhook sends a change with toHash set to all-zeros. Previously, Pipelines as Code treated this like a push event, which caused errors when trying to validate a missing commit. This patch detects and ignores such events early in ParsePayload. Fixes #2035
1 parent d2ac965 commit 023e178

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

pkg/provider/bitbucketdatacenter/parse_payload.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,11 @@ func (v *Provider) ParsePayload(_ context.Context, _ *params.Run, request *http.
155155
}
156156
v.pullRequestNumber = e.PullRequest.ID
157157
case *types.PushRequestEvent:
158+
for _, change := range e.Changes {
159+
if change.ToHash == "0000000000000000000000000000000000000000" && change.Type == "DELETE" {
160+
return nil, nil
161+
}
162+
}
158163
processedEvent.TriggerTarget = triggertype.Push
159164
processedEvent.EventType = triggertype.Push.String()
160165
processedEvent.Organization = e.Repository.Project.Key

pkg/provider/bitbucketdatacenter/parse_payload_test.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,18 @@ func TestParsePayload(t *testing.T) {
653653
payloadEvent: bbv1test.MakePREvent(ev1, "/cancel"),
654654
expEvent: ev1,
655655
},
656+
{
657+
name: "deleted branch should be ignored",
658+
eventType: "repo:refs_changed",
659+
payloadEvent: bbv1test.MakePushEvent(ev1, []types.PushRequestEventChange{
660+
{
661+
ToHash: "0000000000000000000000000000000000000000",
662+
RefID: "refs/heads/feature-branch",
663+
Type: "DELETE",
664+
},
665+
}),
666+
expEvent: nil,
667+
},
656668
}
657669
for _, tt := range tests {
658670
t.Run(tt.name, func(t *testing.T) {
@@ -678,7 +690,12 @@ func TestParsePayload(t *testing.T) {
678690
return
679691
}
680692
assert.NilError(t, err)
681-
693+
if tt.expEvent == nil {
694+
if got != nil {
695+
t.Fatalf("expected event to be nil, got: %+v", got)
696+
}
697+
return
698+
}
682699
assert.Equal(t, got.AccountID, tt.expEvent.AccountID)
683700

684701
// test that we got slashed

0 commit comments

Comments
 (0)