Skip to content

Commit 7f614d2

Browse files
infernus01zakisk
authored andcommitted
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 bca681c commit 7f614d2

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-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" {
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: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,17 @@ 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+
},
664+
}),
665+
expEvent: nil,
666+
},
656667
}
657668
for _, tt := range tests {
658669
t.Run(tt.name, func(t *testing.T) {
@@ -678,7 +689,12 @@ func TestParsePayload(t *testing.T) {
678689
return
679690
}
680691
assert.NilError(t, err)
681-
692+
if tt.expEvent == nil {
693+
if got != nil {
694+
t.Fatalf("expected event to be nil, got: %+v", got)
695+
}
696+
return
697+
}
682698
assert.Equal(t, got.AccountID, tt.expEvent.AccountID)
683699

684700
// test that we got slashed

0 commit comments

Comments
 (0)