@@ -130,6 +130,57 @@ func TestGiteaOnCommentAnnotation(t *testing.T) {
130130 assert .NilError (t , err )
131131}
132132
133+ // TestGiteaOnCommentTestOverride tests that a PipelineRun with
134+ // on-comment: "^/test.*" is triggered when posting "/test custom1=value".
135+ // This verifies that key=value arguments are not mistaken for a PipelineRun
136+ // name, which would bypass the on-comment annotation matching entirely.
137+ func TestGiteaOnCommentTestOverride (t * testing.T ) {
138+ var err error
139+ ctx := context .Background ()
140+ topts := & tgitea.TestOpts {
141+ TargetRefName : names .SimpleNameGenerator .RestrictLengthWithRandomSuffix ("pac-e2e-test" ),
142+ RepoCRParams : & []v1alpha1.Params {
143+ {
144+ Name : "custom1" ,
145+ Value : "default" ,
146+ },
147+ },
148+ }
149+ topts .TargetNS = topts .TargetRefName
150+ topts .ParamsRun , topts .Opts , topts .GiteaCNX , err = tgitea .Setup (ctx )
151+ assert .NilError (t , err , fmt .Errorf ("cannot do gitea setup: %w" , err ))
152+ ctx , err = cctx .GetControllerCtxInfo (ctx , topts .ParamsRun )
153+ assert .NilError (t , err )
154+ assert .NilError (t , pacrepo .CreateNS (ctx , topts .TargetNS , topts .ParamsRun ))
155+ assert .NilError (t , secret .Create (ctx , topts .ParamsRun , map [string ]string {"secret" : "SHHHHHHH" }, topts .TargetNS , "pac-secret" ))
156+ topts .TargetEvent = triggertype .PullRequest .String ()
157+ topts .YAMLFiles = map [string ]string {
158+ ".tekton/on-comment-test-override.yaml" : "testdata/pipelinerun-on-comment-test-override.yaml" ,
159+ }
160+ topts .ExpectEvents = false
161+ _ , f := tgitea .TestPR (t , topts )
162+ defer f ()
163+
164+ tgitea .PostCommentOnPullRequest (t , topts , "/test custom1=overridden" )
165+ waitOpts := twait.Opts {
166+ RepoName : topts .TargetNS ,
167+ Namespace : topts .TargetNS ,
168+ MinNumberStatus : 1 ,
169+ PollTimeout : twait .DefaultTimeout ,
170+ }
171+ repo , err := twait .UntilRepositoryUpdated (context .Background (), topts .ParamsRun .Clients , waitOpts )
172+ assert .NilError (t , err )
173+ assert .Equal (t , len (repo .Status ), 1 , "should have exactly 1 status" )
174+ assert .Equal (t , * repo .Status [0 ].EventType , opscomments .OnCommentEventType .String (),
175+ "should have matched via on-comment annotation, not built-in /test handler" )
176+
177+ last := repo .Status [0 ]
178+ err = twait .RegexpMatchingInPodLog (context .Background (), topts .ParamsRun , topts .TargetNS ,
179+ fmt .Sprintf ("tekton.dev/pipelineRun=%s" , last .PipelineRunName ), "step-task" ,
180+ * regexp .MustCompile ("custom1 is overridden" ), "" , 2 , nil )
181+ assert .NilError (t , err )
182+ }
183+
133184// TestGiteaTestPipelineRunExplicitlyWithTestComment will test a pipelinerun
134185// even if it hasn't matched when we are doing a /test comment.
135186func TestGiteaTestPipelineRunExplicitlyWithTestComment (t * testing.T ) {
0 commit comments