@@ -201,12 +201,15 @@ func TestParsePayload(t *testing.T) {
201201 wantErrMsg : "error parse_payload: the repository in event payload must not be nil" ,
202202 },
203203 {
204- name : "bad/commit comment wrong branch keyword" ,
204+ name : "bad/commit comment wrong branch keyword" ,
205+ fields : fields {sourceProjectID : 200 },
205206 args : args {
206207 event : gitlab .EventTypeNote ,
207208 payload : sample .CommitNoteEventAsJSON ("/test brrranch:fix" , "create" , "{}" ),
208209 },
209- wantErrMsg : "the GitOps comment brrranch does not contain a branch word" ,
210+ wantErrMsg : "does not contain a branch or tag word" ,
211+ wantKubeClient : true ,
212+ wantClient : true ,
210213 },
211214 {
212215 name : "good/commit comment /test all pipelineruns" ,
@@ -307,6 +310,82 @@ func TestParsePayload(t *testing.T) {
307310 wantKubeClient : true ,
308311 wantClient : true ,
309312 },
313+ {
314+ name : "good/commit comment /test on a tag" ,
315+ fields : fields {sourceProjectID : 200 },
316+ args : args {
317+ event : gitlab .EventTypeNote ,
318+ payload : sample .CommitNoteEventAsJSON ("/test tag:v1.0.0" , "create" , "{}" ),
319+ },
320+ want : & info.Event {
321+ EventType : opscomments .TestSingleCommentEventType .String (),
322+ TriggerTarget : triggertype .Push ,
323+ Organization : "hello/this/is/me/ze" ,
324+ Repository : "project" ,
325+ HeadBranch : "refs/tags/v1.0.0" ,
326+ BaseBranch : "refs/tags/v1.0.0" ,
327+ },
328+ wantKubeClient : true ,
329+ wantClient : true ,
330+ },
331+ {
332+ name : "good/commit comment /retest on a tag" ,
333+ fields : fields {sourceProjectID : 200 },
334+ args : args {
335+ event : gitlab .EventTypeNote ,
336+ payload : sample .CommitNoteEventAsJSON ("/retest tag:v1.0.0" , "create" , "{}" ),
337+ },
338+ want : & info.Event {
339+ EventType : opscomments .RetestSingleCommentEventType .String (),
340+ TriggerTarget : triggertype .Push ,
341+ Organization : "hello/this/is/me/ze" ,
342+ Repository : "project" ,
343+ HeadBranch : "refs/tags/v1.0.0" ,
344+ BaseBranch : "refs/tags/v1.0.0" ,
345+ },
346+ wantKubeClient : true ,
347+ wantClient : true ,
348+ },
349+ {
350+ name : "good/commit comment /cancel on a tag" ,
351+ fields : fields {sourceProjectID : 200 },
352+ args : args {
353+ event : gitlab .EventTypeNote ,
354+ payload : sample .CommitNoteEventAsJSON ("/cancel tag:v1.0.0" , "create" , "{}" ),
355+ },
356+ want : & info.Event {
357+ EventType : opscomments .CancelCommentSingleEventType .String (),
358+ TriggerTarget : triggertype .Push ,
359+ Organization : "hello/this/is/me/ze" ,
360+ Repository : "project" ,
361+ HeadBranch : "refs/tags/v1.0.0" ,
362+ BaseBranch : "refs/tags/v1.0.0" ,
363+ },
364+ wantKubeClient : true ,
365+ wantClient : true ,
366+ },
367+ {
368+ name : "bad/commit comment tag does not exist" ,
369+ fields : fields {sourceProjectID : 200 },
370+ args : args {
371+ event : gitlab .EventTypeNote ,
372+ payload : sample .CommitNoteEventAsJSON ("/test tag:nonexistent" , "create" , "{}" ),
373+ },
374+ wantErrMsg : "error getting tag nonexistent" ,
375+ wantKubeClient : true ,
376+ wantClient : true ,
377+ },
378+ {
379+ name : "bad/commit comment SHA does not match tag commit" ,
380+ fields : fields {sourceProjectID : 200 },
381+ args : args {
382+ event : gitlab .EventTypeNote ,
383+ payload : sample .CommitNoteEventAsJSON ("/test tag:v1.0.0-mismatch" , "create" , "{}" ),
384+ },
385+ wantErrMsg : "provided SHA sha is not the tagged commit for the tag v1.0.0-mismatch" ,
386+ wantKubeClient : true ,
387+ wantClient : true ,
388+ },
310389 }
311390 for _ , tt := range tests {
312391 t .Run (tt .name , func (t * testing.T ) {
@@ -375,6 +454,32 @@ func TestParsePayload(t *testing.T) {
375454 bytes , _ := json .Marshal (branch )
376455 _ , _ = rw .Write (bytes )
377456 })
457+ // Mock tag API for v1.0.0 (valid tag with matching SHA)
458+ mux .HandleFunc ("/projects/200/repository/tags/v1.0.0" ,
459+ func (rw http.ResponseWriter , _ * http.Request ) {
460+ tag := & gitlab.Tag {
461+ Name : "v1.0.0" ,
462+ Commit : & gitlab.Commit {ID : "sha" },
463+ }
464+ bytes , _ := json .Marshal (tag )
465+ _ , _ = rw .Write (bytes )
466+ })
467+ // Mock tag API for v1.0.0-mismatch (tag with non-matching SHA)
468+ mux .HandleFunc ("/projects/200/repository/tags/v1.0.0-mismatch" ,
469+ func (rw http.ResponseWriter , _ * http.Request ) {
470+ tag := & gitlab.Tag {
471+ Name : "v1.0.0-mismatch" ,
472+ Commit : & gitlab.Commit {ID : "different-sha" },
473+ }
474+ bytes , _ := json .Marshal (tag )
475+ _ , _ = rw .Write (bytes )
476+ })
477+ // Mock tag API for nonexistent (return 404)
478+ mux .HandleFunc ("/projects/200/repository/tags/nonexistent" ,
479+ func (rw http.ResponseWriter , _ * http.Request ) {
480+ rw .WriteHeader (http .StatusNotFound )
481+ _ , _ = rw .Write ([]byte (`{"message":"404 Tag Not Found"}` ))
482+ })
378483 defer tearDown ()
379484 }
380485
@@ -398,6 +503,12 @@ func TestParsePayload(t *testing.T) {
398503 if tt .want .TargetCancelPipelineRun != "" {
399504 assert .Equal (t , tt .want .TargetCancelPipelineRun , got .TargetCancelPipelineRun )
400505 }
506+ if tt .want .HeadBranch != "" {
507+ assert .Equal (t , tt .want .HeadBranch , got .HeadBranch )
508+ }
509+ if tt .want .BaseBranch != "" {
510+ assert .Equal (t , tt .want .BaseBranch , got .BaseBranch )
511+ }
401512 }
402513 })
403514 }
0 commit comments