Skip to content

Commit 7663fb1

Browse files
chmouelsavitaashture
authored andcommitted
fix: Correct event-type setting for on-comment prs
This commit fixes the event-type setting for PipelineRuns that match the `on-comment` annotation. Previously, the `event_type` was set to `no-ops-comment` instead of `on-comment` when a git provider's issue comment event matched a comment in an annotation. This fix ensures that the `event_type` is correctly set. on-comment is a brand new TP feature, so no worries that we may have breaking things for users relying on that behaviour. Issue: https://issue.redhat.com/browse/SRVKP-5779 Signed-off-by: Chmouel Boudjnah <chmouel@redhat.com>
1 parent be424e4 commit 7663fb1

File tree

4 files changed

+27
-1
lines changed

4 files changed

+27
-1
lines changed

pkg/pipelineascode/match.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,25 @@ func (p *PacRun) getPipelineRunsFromRepo(ctx context.Context, repo *v1alpha1.Rep
178178
p.event.AccountID = ""
179179
}
180180

181+
// NOTE(chmouel): Initially, matching is performed here to accurately
182+
// expand dynamic matching in events. This expansion is crucial for
183+
// applying dynamic variables, such as setting the `event_type` to
184+
// `on-comment` when matching a git provider's issue comment event with a
185+
// comment in an annotation. Although matching occurs three times within
186+
// this loop, which might seem inefficient, it's essential to maintain
187+
// current functionality without introducing potential errors or behavior
188+
// changes. Refactoring for optimization could lead to significant
189+
// challenges in tracking down issues. Despite the repetition, the
190+
// performance impact is minimal, involving only a loop and a few
191+
// conditions.
192+
if p.event.TargetTestPipelineRun == "" {
193+
rtypes, err := resolve.ReadTektonTypes(ctx, p.logger, rawTemplates)
194+
if err != nil {
195+
return nil, err
196+
}
197+
// Don't fail or do anything if we don't have a match yet, we will do it properly later in this function
198+
_, _ = matcher.MatchPipelinerunByAnnotation(ctx, p.logger, rtypes.PipelineRuns, p.run, p.event, p.vcx)
199+
}
181200
// Replace those {{var}} placeholders user has in her template to the run.Info variable
182201
allTemplates := p.makeTemplate(ctx, repo, rawTemplates)
183202

test/github_pullrequest_test_comment_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,14 @@ func TestGithubSecondOnCommentAnnotation(t *testing.T) {
8787
repo, err := twait.UntilRepositoryUpdated(ctx, g.Cnx.Clients, waitOpts)
8888
assert.NilError(t, err)
8989
g.Cnx.Clients.Log.Infof("Check if we have the repository set as succeeded")
90-
assert.Assert(t, repo.Status[len(repo.Status)-1].Conditions[0].Status == corev1.ConditionTrue)
90+
assert.Equal(t, repo.Status[len(repo.Status)-1].Conditions[0].Status, corev1.ConditionTrue)
91+
assert.Equal(t, *repo.Status[len(repo.Status)-1].EventType, opscomments.OnCommentEventType.String())
9192
lastPrName := repo.Status[len(repo.Status)-1].PipelineRunName
9293

9394
err = twait.RegexpMatchingInPodLog(context.Background(), g.Cnx, g.TargetNamespace, fmt.Sprintf("tekton.dev/pipelineRun=%s", lastPrName), "step-task", *regexp.MustCompile(triggerComment), "", 2)
9495
assert.NilError(t, err)
96+
97+
err = twait.RegexpMatchingInPodLog(context.Background(), g.Cnx, g.TargetNamespace, fmt.Sprintf("tekton.dev/pipelineRun=%s", lastPrName), "step-task", *regexp.MustCompile(fmt.Sprintf(
98+
"The event is %s", opscomments.OnCommentEventType.String())), "", 2)
99+
assert.NilError(t, err)
95100
}

test/testdata/TestGiteaOnCommentAnnotation.golden

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
The comment is:
22
/hello-world revision=main custom1=thisone custom2="another one" custom3="a \"quote\""
3+
The event is on-comment
34
The revision is main
45
The custom1 value is thisone
56
The custom2 value is another one

test/testdata/pipelinerun-on-comment-annotation.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ spec:
2020
cat <<EOF
2121
{{ trigger_comment }}
2222
EOF
23+
echo "The event is {{ event_type }}"
2324
echo "The revision is {{ revision }}"
2425
echo "The custom1 value is {{ custom1 }}"
2526
echo "The custom2 value is {{ custom2 }}"

0 commit comments

Comments
 (0)