@@ -301,7 +301,7 @@ func (s *handlerTestSuite) Test_PushEventUnmatchedRepo() {
301301 Times (1 )
302302 jobSummary := models.JobSummary {Name : "jobname" , AppName : expectAppDetail .appName , Branch : "master" , CommitID : commitID , TriggeredBy : "" }
303303 s .apiServer .EXPECT ().
304- TriggerPipeline (gomock .Any (), expectAppDetail .appName , "master" , commitID , "" ).
304+ TriggerPipeline (gomock .Any (), expectAppDetail .appName , "master" , "branch" , commitID , "" ).
305305 Return (& jobSummary , nil ).
306306 Times (1 )
307307 }
@@ -457,7 +457,7 @@ func (s *handlerTestSuite) Test_PushEventTriggerPipelineReturnsError() {
457457
458458 s .apiServer .EXPECT ().ShowApplications (gomock .Any (), "git@github.com:equinor/repo-4.git" ).Return ([]* models.ApplicationSummary {& appSummary }, nil ).Times (1 )
459459 s .apiServer .EXPECT ().GetApplication (gomock .Any (), appName ).Return (appDetail , nil ).Times (1 )
460- s .apiServer .EXPECT ().TriggerPipeline (gomock .Any (), appName , "master" , commitID , "" ).Return (nil , scenario .apiError ).Times (1 )
460+ s .apiServer .EXPECT ().TriggerPipeline (gomock .Any (), appName , "master" , "branch" , commitID , "" ).Return (nil , scenario .apiError ).Times (1 )
461461
462462 sut := NewWebHookHandler (s .apiServer )
463463 req , _ := http .NewRequest ("POST" , "/" , bytes .NewReader (payload ))
@@ -490,7 +490,7 @@ func (s *handlerTestSuite) Test_PushEventCorrectSecret() {
490490 jobSummary := models.JobSummary {Name : "jobname" , AppName : "jobappname" , Branch : "jobbranchname" , CommitID : "jobcommitID" , TriggeredBy : "anyuser" }
491491 s .apiServer .EXPECT ().ShowApplications (gomock .Any (), "git@github.com:equinor/repo-4.git" ).Return ([]* models.ApplicationSummary {& appSummary }, nil ).Times (1 )
492492 s .apiServer .EXPECT ().GetApplication (gomock .Any (), appName ).Return (appDetail , nil ).Times (1 )
493- s .apiServer .EXPECT ().TriggerPipeline (gomock .Any (), appName , "master" , commitID , "" ).Return (& jobSummary , nil ).Times (1 )
493+ s .apiServer .EXPECT ().TriggerPipeline (gomock .Any (), appName , "master" , "branch" , commitID , "" ).Return (& jobSummary , nil ).Times (1 )
494494
495495 sut := NewWebHookHandler (s .apiServer )
496496 req , _ := http .NewRequest ("POST" , "/" , bytes .NewReader (payload ))
@@ -502,7 +502,7 @@ func (s *handlerTestSuite) Test_PushEventCorrectSecret() {
502502 var res response
503503 err := json .Unmarshal (s .w .Body .Bytes (), & res )
504504 require .NoError (s .T (), err )
505- s .Equal (createPipelineJobSuccessMessage (jobSummary .Name , jobSummary .AppName , jobSummary .Branch , jobSummary .CommitID ), res .Message )
505+ s .Equal (createPipelineJobSuccessMessage (jobSummary .Name , jobSummary .AppName , jobSummary .Branch , "branch" , jobSummary .CommitID ), res .Message )
506506 s .ctrl .Finish ()
507507}
508508
@@ -528,9 +528,18 @@ func (s *handlerTestSuite) Test_PushEventWithRefDeleted() {
528528}
529529
530530func Test_GetBranch_RemovesRefsHead (t * testing.T ) {
531- assert .Equal (t , "master" , getBranch (& github.PushEvent {Ref : strPtr ("refs/heads/master" )}))
532- assert .Equal (t , "feature/RA-326-TestBranch" , getBranch (& github.PushEvent {Ref : strPtr ("refs/heads/feature/RA-326-TestBranch" )}))
533- assert .Equal (t , "hotfix/api/refs/heads/fix1" , getBranch (& github.PushEvent {Ref : strPtr ("refs/heads/hotfix/api/refs/heads/fix1" )}))
531+ gitRef , gitRefType := getGitRefWithType (& github.PushEvent {Ref : strPtr ("refs/tags/v1.0.2" )})
532+ assert .Equal (t , "v1.0.2" , gitRef )
533+ assert .Equal (t , "tag" , gitRefType )
534+ gitRef , gitRefType = getGitRefWithType (& github.PushEvent {Ref : strPtr ("refs/heads/master" )})
535+ assert .Equal (t , "master" , gitRef )
536+ assert .Equal (t , "branch" , gitRefType )
537+ gitRef , gitRefType = getGitRefWithType (& github.PushEvent {Ref : strPtr ("refs/heads/feature/RA-326-TestBranch" )})
538+ assert .Equal (t , "feature/RA-326-TestBranch" , gitRef )
539+ assert .Equal (t , "branch" , gitRefType )
540+ gitRef , gitRefType = getGitRefWithType (& github.PushEvent {Ref : strPtr ("refs/heads/hotfix/api/refs/heads/fix1" )})
541+ assert .Equal (t , "hotfix/api/refs/heads/fix1" , gitRef )
542+ assert .Equal (t , "branch" , gitRefType )
534543}
535544
536545func (s * handlerTestSuite ) Test_PushEventWithAnnotatedTag () {
@@ -550,7 +559,7 @@ func (s *handlerTestSuite) Test_PushEventWithAnnotatedTag() {
550559 jobSummary := models.JobSummary {Name : "jobname" , AppName : "jobappname" , Branch : "jobbranchname" , CommitID : headCommitID , TriggeredBy : "anyuser" }
551560 s .apiServer .EXPECT ().ShowApplications (gomock .Any (), "git@github.com:equinor/repo-1.git" ).Return ([]* models.ApplicationSummary {& appSummary }, nil ).Times (1 )
552561 s .apiServer .EXPECT ().GetApplication (gomock .Any (), appName ).Return (appDetail , nil ).Times (1 )
553- s .apiServer .EXPECT ().TriggerPipeline (gomock .Any (), appName , tag , headCommitID , "" ).Return (& jobSummary , nil ).Times (1 )
562+ s .apiServer .EXPECT ().TriggerPipeline (gomock .Any (), appName , tag , "tag" , headCommitID , "" ).Return (& jobSummary , nil ).Times (1 )
554563
555564 sut := NewWebHookHandler (s .apiServer )
556565 req , _ := http .NewRequest ("POST" , "/" , bytes .NewReader (payload ))
@@ -562,7 +571,7 @@ func (s *handlerTestSuite) Test_PushEventWithAnnotatedTag() {
562571 var res response
563572 err := json .Unmarshal (s .w .Body .Bytes (), & res )
564573 require .NoError (s .T (), err )
565- s .Equal (createPipelineJobSuccessMessage (jobSummary .Name , jobSummary .AppName , jobSummary .Branch , jobSummary .CommitID ), res .Message )
574+ s .Equal (createPipelineJobSuccessMessage (jobSummary .Name , jobSummary .AppName , jobSummary .Branch , "branch" , jobSummary .CommitID ), res .Message )
566575 s .ctrl .Finish ()
567576}
568577
@@ -571,7 +580,7 @@ type response struct {
571580 Error string `json:"error"`
572581}
573582
574- // GitHubPayloadBuilder Handles construction of github payload
583+ // GitHubPayloadBuilder Handles construction of GitHub payload
575584type GitHubPayloadBuilder interface {
576585 withRef (refs string ) GitHubPayloadBuilder
577586 withAfter (after string ) GitHubPayloadBuilder
0 commit comments