Skip to content

Commit aa58849

Browse files
authored
BIVS-2946 (#219)
1 parent fa33744 commit aa58849

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

service/hook/gitlab/gitlab.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,14 @@ func (hp HookProvider) transformCodePushEvent(codePushEvent CodePushEventModel)
311311
}
312312
}
313313

314+
if len(codePushEvent.Commits) == 0 {
315+
return hookCommon.TransformResultModel{
316+
DontWaitForTriggerResponse: true,
317+
Error: fmt.Errorf("Empty 'commits' array - probably created a branch with no commits yet"),
318+
ShouldSkip: true,
319+
}
320+
}
321+
314322
lastCommit := CommitModel{}
315323
isLastCommitFound := false
316324
for _, aCommit := range codePushEvent.Commits {

service/hook/gitlab/gitlab_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -927,6 +927,22 @@ func Test_transformCodePushEvent(t *testing.T) {
927927
require.Equal(t, true, hookTransformResult.DontWaitForTriggerResponse)
928928
}
929929

930+
t.Log("No commits (branch creation)")
931+
{
932+
codePush := CodePushEventModel{
933+
ObjectKind: "push",
934+
Ref: "refs/heads/master",
935+
CheckoutSHA: "checkout-sha",
936+
UserUsername: "test_user",
937+
Commits: []CommitModel{},
938+
}
939+
hookTransformResult := NewDefaultHookProvider(zap.NewNop()).transformCodePushEvent(codePush)
940+
require.EqualError(t, hookTransformResult.Error, "Empty 'commits' array - probably created a branch with no commits yet")
941+
require.True(t, hookTransformResult.ShouldSkip)
942+
require.Nil(t, hookTransformResult.TriggerAPIParams)
943+
require.Equal(t, true, hookTransformResult.DontWaitForTriggerResponse)
944+
}
945+
930946
t.Log("Commit without CheckoutSHA (squashed merge request)")
931947
{
932948
codePush := CodePushEventModel{

0 commit comments

Comments
 (0)