Skip to content

Commit 906f1db

Browse files
zakiskchmouel
authored andcommitted
fix(github): use correct name for failed checkruns on retest
after /retest or /test command failed check run was being wiped out because we didn't used correct pipelinerun name before when reporting failure in startPR func. now this uses the generateName if name is not available for a pipelinerun. this also adds an e2e tests to ensure that checkrun for tekton validation failed pipelinerun is not wiped out. https://issues.redhat.com/browse/SRVKP-10741 Signed-off-by: Zaki Shaikh <zashaikh@redhat.com>
1 parent 9b81c6c commit 906f1db

File tree

4 files changed

+88
-2
lines changed

4 files changed

+88
-2
lines changed

pkg/pipelineascode/pipelineascode.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,17 @@ func (p *PacRun) Run(ctx context.Context) error {
157157
errMsg := fmt.Sprintf("There was an error starting the PipelineRun %s, %s", match.PipelineRun.GetGenerateName(), err.Error())
158158
errMsgM := fmt.Sprintf("There was an error creating the PipelineRun: <b>%s</b>\n\n%s", match.PipelineRun.GetGenerateName(), err.Error())
159159
p.eventEmitter.EmitMessage(repo, zap.ErrorLevel, "RepositoryPipelineRun", errMsg)
160+
prName := match.PipelineRun.GetName()
161+
if prName == "" {
162+
prName = match.PipelineRun.GetGenerateName()
163+
}
160164
createStatusErr := p.vcx.CreateStatus(ctx, p.event, provider.StatusOpts{
161-
PipelineRunName: match.PipelineRun.GetName(),
165+
PipelineRunName: prName,
162166
PipelineRun: match.PipelineRun,
163167
OriginalPipelineRunName: match.PipelineRun.GetAnnotations()[keys.OriginalPRName],
164168
Status: CompletedStatus,
165169
Conclusion: failureConclusion,
170+
Title: "pipelinerun start failure",
166171
Text: errMsgM,
167172
DetailsURL: p.run.Clients.ConsoleUI().URL(),
168173
InstanceCountForCheckRun: i,

pkg/provider/github/status.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,9 @@ func (v *Provider) CreateStatus(ctx context.Context, runevent *info.Event, statu
397397
statusOpts.Title = "Success"
398398
statusOpts.Summary = "has <b>successfully</b> validated your commit."
399399
case "failure":
400-
statusOpts.Title = "Failed"
400+
if statusOpts.Title == "" {
401+
statusOpts.Title = "Failed"
402+
}
401403
statusOpts.Summary = "has <b>failed</b>."
402404
case "pending":
403405
// for concurrency set title as pending

test/github_pullrequest_retest_test.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"context"
77
"fmt"
88
"os"
9+
"strings"
910
"testing"
1011

1112
"github.com/google/go-github/v81/github"
@@ -145,3 +146,61 @@ func TestGithubSecondPullRequestGitopsCommentCancel(t *testing.T) {
145146
assert.Equal(t, succeededCount, 2, "should have two succeeded PipelineRuns")
146147
assert.Equal(t, unknownCount, 0, "should have zero unknown PipelineRuns: %+v", pruns.Items)
147148
}
149+
150+
func TestGithubRetestWithMultipleFailedPipelineRuns(t *testing.T) {
151+
ctx := context.Background()
152+
g := &tgithub.PRTest{
153+
Label: "Github Retest with multiple failed PipelineRuns",
154+
YamlFiles: []string{
155+
"testdata/pipelinerun-tekton-validation.yaml",
156+
"testdata/failures/pipelinerun-exit-1.yaml", // failed pipelinerun to be re-trigger after retest
157+
},
158+
NoStatusCheck: true,
159+
}
160+
g.RunPullRequest(ctx, t)
161+
defer g.TearDown(ctx, t)
162+
163+
err := twait.UntilPipelineRunCreated(ctx, g.Cnx.Clients, twait.Opts{
164+
RepoName: g.TargetNamespace,
165+
Namespace: g.TargetNamespace,
166+
MinNumberStatus: 1,
167+
TargetSHA: g.SHA,
168+
PollTimeout: twait.DefaultTimeout,
169+
})
170+
assert.NilError(t, err)
171+
172+
pruns, err := g.Cnx.Clients.Tekton.TektonV1().PipelineRuns(g.TargetNamespace).List(ctx, metav1.ListOptions{
173+
LabelSelector: fmt.Sprintf("%s=%s", keys.SHA, g.SHA),
174+
})
175+
assert.NilError(t, err)
176+
assert.Equal(t, len(pruns.Items), 1)
177+
178+
_, _, err = g.Provider.Client().Issues.CreateComment(ctx,
179+
g.Options.Organization,
180+
g.Options.Repo,
181+
g.PRNumber,
182+
&github.IssueComment{Body: github.Ptr("/retest")},
183+
)
184+
assert.NilError(t, err)
185+
186+
// here we only need to check that we have two failed check runs and nothing is gone
187+
// after making the retest comment.
188+
res, _, err := g.Provider.Client().Checks.ListCheckRunsForRef(ctx,
189+
g.Options.Organization,
190+
g.Options.Repo,
191+
g.SHA,
192+
&github.ListCheckRunsOptions{},
193+
)
194+
assert.NilError(t, err)
195+
196+
assert.Equal(t, len(res.CheckRuns), 2)
197+
198+
containsFailedPLRName := false
199+
for _, checkRun := range res.CheckRuns {
200+
// check if the check run is for the validation failed pipelinerun
201+
if strings.Contains(checkRun.GetExternalID(), "pipelinerun-tekton-validation") {
202+
containsFailedPLRName = true
203+
}
204+
}
205+
assert.Equal(t, containsFailedPLRName, true)
206+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
apiVersion: tekton.dev/v1beta1
3+
kind: PipelineRun
4+
metadata:
5+
name: "\\ .PipelineName //"
6+
annotations:
7+
pipelinesascode.tekton.dev/target-namespace: "\\ .TargetNamespace //"
8+
pipelinesascode.tekton.dev/on-target-branch: "[\\ .TargetBranch //]"
9+
pipelinesascode.tekton.dev/on-event: "[\\ .TargetEvent //]"
10+
spec:
11+
pipelineSpec:
12+
tasks:
13+
- name: task
14+
taskSpec:
15+
stepsos:
16+
- name: step
17+
image: registry.access.redhat.com/ubi9/ubi-micro
18+
script: |
19+
echo "HELLOMOTO"
20+
exit 0

0 commit comments

Comments
 (0)