@@ -390,48 +390,49 @@ func (v *Provider) handleCommitCommentEvent(ctx context.Context, event *github.C
390390 runevent .EventType = "push"
391391 runevent .TriggerTarget = "push"
392392
393- // by default head and base branch is main
394- runevent .HeadBranch = "main"
395- runevent .BaseBranch = "main"
396-
393+ // Set main as default branch to runevent.HeadBranch, runevent.BaseBranch
394+ runevent .HeadBranch , runevent .BaseBranch = "main" , "main"
397395 var (
398396 branchName string
399397 prName string
400398 err error
401399 )
402400
403- // if it is a /test or /retest comment with pipelinerun name figure out the pipelinerun name
401+ // If it is a /test or /retest comment with pipelinerun name figure out the pipelinerun name
404402 if provider .IsTestRetestComment (event .GetComment ().GetBody ()) {
405403 prName , branchName , err = provider .GetPipelineRunAndBranchNameFromTestComment (event .GetComment ().GetBody ())
406404 if err != nil {
407405 return runevent , err
408406 }
409407 runevent .TargetTestPipelineRun = prName
410408 }
409+ // Check for /cancel comment
411410 if provider .IsCancelComment (event .GetComment ().GetBody ()) {
412411 action = "cancellation"
413412 prName , branchName , err = provider .GetPipelineRunAndBranchNameFromCancelComment (event .GetComment ().GetBody ())
414413 if err != nil {
415414 return runevent , err
416415 }
416+ runevent .CancelPipelineRuns = true
417417 runevent .TargetCancelPipelineRun = prName
418418 }
419419
420- if branchName != "" {
421- if err = v .isBranchContainsCommit (ctx , runevent , branchName ); err != nil {
422- return runevent , err
423- }
424- runevent .HeadBranch = branchName
425- runevent .BaseBranch = branchName
420+ // If no branch is specified in GitOps comments, use runevent.HeadBranch
421+ if branchName == "" {
422+ branchName = runevent .HeadBranch
426423 }
427424
428- if provider .IsCancelComment (event .GetComment ().GetBody ()) {
429- if err = v .isBranchContainsCommit (ctx , runevent , runevent .HeadBranch ); err != nil {
425+ // Check if the specified branch contains the commit
426+ if err = v .isBranchContainsCommit (ctx , runevent , branchName ); err != nil {
427+ if provider .IsCancelComment (event .GetComment ().GetBody ()) {
430428 runevent .CancelPipelineRuns = false
431- return runevent , err
432429 }
433- runevent . CancelPipelineRuns = true
430+ return runevent , err
434431 }
432+ // Finally update branch information to runevent.HeadBranch and runevent.BaseBranch
433+ runevent .HeadBranch = branchName
434+ runevent .BaseBranch = branchName
435+
435436 v .Logger .Infof ("commit_comment: pipelinerun %s on %s/%s#%s has been requested" , action , runevent .Organization , runevent .Repository , runevent .SHA )
436437 return runevent , nil
437438}
0 commit comments