Skip to content

Commit 65409fa

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 1f9ba8c commit 65409fa

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-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: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,19 @@ func TestParsePayload(t *testing.T) {
660660
payloadEvent: bbv1test.MakePREvent(ev1, "/cancel"),
661661
expEvent: ev1,
662662
},
663+
{
664+
name: "deleted branch should be ignored",
665+
eventType: "repo:refs_changed",
666+
payloadEvent: bbv1test.MakePushEvent(ev1, []types.PushRequestEventChange{
667+
{
668+
ToHash: "0000000000000000000000000000000000000000",
669+
RefID: "refs/heads/feature-branch",
670+
Type: "DELETE",
671+
},
672+
},[]types.Commit{},
673+
),
674+
expEvent: nil,
675+
},
663676
}
664677
for _, tt := range tests {
665678
t.Run(tt.name, func(t *testing.T) {
@@ -685,7 +698,12 @@ func TestParsePayload(t *testing.T) {
685698
return
686699
}
687700
assert.NilError(t, err)
688-
701+
if tt.expEvent == nil {
702+
if got != nil {
703+
t.Fatalf("expected event to be nil, got: %+v", got)
704+
}
705+
return
706+
}
689707
assert.Equal(t, got.AccountID, tt.expEvent.AccountID)
690708

691709
// test that we got slashed

0 commit comments

Comments
 (0)