Skip to content

Commit 1683bbd

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 1f9ba8c commit 1683bbd

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
@@ -660,6 +660,18 @@ 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+
}),
673+
expEvent: nil,
674+
},
663675
}
664676
for _, tt := range tests {
665677
t.Run(tt.name, func(t *testing.T) {
@@ -685,7 +697,12 @@ func TestParsePayload(t *testing.T) {
685697
return
686698
}
687699
assert.NilError(t, err)
688-
700+
if tt.expEvent == nil {
701+
if got != nil {
702+
t.Fatalf("expected event to be nil, got: %+v", got)
703+
}
704+
return
705+
}
689706
assert.Equal(t, got.AccountID, tt.expEvent.AccountID)
690707

691708
// test that we got slashed

0 commit comments

Comments
 (0)