File tree 2 files changed +24
-0
lines changed
2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -311,6 +311,14 @@ func (hp HookProvider) transformCodePushEvent(codePushEvent CodePushEventModel)
311
311
}
312
312
}
313
313
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
+
314
322
lastCommit := CommitModel {}
315
323
isLastCommitFound := false
316
324
for _ , aCommit := range codePushEvent .Commits {
Original file line number Diff line number Diff line change @@ -927,6 +927,22 @@ func Test_transformCodePushEvent(t *testing.T) {
927
927
require .Equal (t , true , hookTransformResult .DontWaitForTriggerResponse )
928
928
}
929
929
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
+
930
946
t .Log ("Commit without CheckoutSHA (squashed merge request)" )
931
947
{
932
948
codePush := CodePushEventModel {
You can’t perform that action at this time.
0 commit comments