-
Notifications
You must be signed in to change notification settings - Fork 89
/
gitea_params_test.go
518 lines (479 loc) · 20.9 KB
/
gitea_params_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
//go:build e2e
// +build e2e
package test
import (
"context"
"fmt"
"os"
"regexp"
"strings"
"testing"
"time"
"code.gitea.io/sdk/gitea"
"github.com/openshift-pipelines/pipelines-as-code/pkg/apis/pipelinesascode/v1alpha1"
"github.com/openshift-pipelines/pipelines-as-code/pkg/params/info"
"github.com/openshift-pipelines/pipelines-as-code/pkg/params/triggertype"
"github.com/openshift-pipelines/pipelines-as-code/pkg/sort"
"github.com/openshift-pipelines/pipelines-as-code/test/pkg/cctx"
"github.com/openshift-pipelines/pipelines-as-code/test/pkg/configmap"
tgitea "github.com/openshift-pipelines/pipelines-as-code/test/pkg/gitea"
pacrepo "github.com/openshift-pipelines/pipelines-as-code/test/pkg/repository"
"github.com/openshift-pipelines/pipelines-as-code/test/pkg/scm"
"github.com/openshift-pipelines/pipelines-as-code/test/pkg/secret"
twait "github.com/openshift-pipelines/pipelines-as-code/test/pkg/wait"
"github.com/tektoncd/pipeline/pkg/names"
"gotest.tools/v3/assert"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
func TestGiteaParamsStandardCheckForPushAndPullEvent(t *testing.T) {
var (
repoURL string
sourceURL string
sourceBranch string
targetBranch string
)
topts := &tgitea.TestOpts{
Regexp: successRegexp,
TargetEvent: "pull_request, push",
YAMLFiles: map[string]string{
".tekton/pr.yaml": "testdata/pipelinerun-standard-params-display.yaml",
},
CheckForStatus: "success",
ExpectEvents: false,
}
_, f := tgitea.TestPR(t, topts)
defer f()
merged, resp, err := topts.GiteaCNX.Client.MergePullRequest(topts.Opts.Organization, topts.Opts.Repo, topts.PullRequest.Index,
gitea.MergePullRequestOption{
Title: "Merged with Panache",
Style: "merge",
},
)
assert.NilError(t, err)
assert.Assert(t, resp.StatusCode < 400, resp)
assert.Assert(t, merged)
tgitea.WaitForStatus(t, topts, topts.PullRequest.Head.Sha, "", false)
time.Sleep(5 * time.Second)
// get standard parameter info for pull_request
_, _, sourceBranch, targetBranch = tgitea.GetStandardParams(t, topts, "pull_request")
// sourceBranch and targetBranch are different for pull_request
if sourceBranch == targetBranch {
assert.Error(t, fmt.Errorf(`source_branch %s is same as target_branch %s for pull_request`, sourceBranch, targetBranch), fmt.Sprintf(`source_branch %s should be different from target_branch %s for pull_request`, sourceBranch, targetBranch))
}
// get standard parameter info for push
repoURL, sourceURL, sourceBranch, targetBranch = tgitea.GetStandardParams(t, topts, "push")
// sourceBranch and targetBranch are same for push
if sourceBranch != targetBranch {
assert.Error(t, fmt.Errorf(`source_branch %s is different from target_branch %s for push`, sourceBranch, targetBranch), fmt.Sprintf(`source_branch %s is same as target_branch %s for push`, sourceBranch, targetBranch))
}
// sourceURL and repoURL are same for push
if repoURL != sourceURL {
assert.Error(t, fmt.Errorf(`source_url %s is different from repo_url %s for push`, repoURL, sourceURL), fmt.Sprintf(`source_url %s is same as repo_url %s for push`, repoURL, sourceURL))
}
}
func TestGiteaParamsOnRepoCRWithCustomConsole(t *testing.T) {
t.Skip("Skipping test changing the global config map for now")
ctx := context.Background()
topts := &tgitea.TestOpts{
CheckForStatus: "success",
SkipEventsCheck: true,
TargetEvent: triggertype.PullRequest.String(),
YAMLFiles: map[string]string{
".tekton/pr.yaml": "testdata/params.yaml",
},
RepoCRParams: &[]v1alpha1.Params{
{
Name: "custom",
Value: "myconsole",
},
},
StatusOnlyLatest: true,
}
topts.TargetRefName = names.SimpleNameGenerator.RestrictLengthWithRandomSuffix("pac-e2e-test")
topts.TargetNS = topts.TargetRefName
topts.ParamsRun, topts.Opts, topts.GiteaCNX, _ = tgitea.Setup(ctx)
assert.NilError(t, topts.ParamsRun.Clients.NewClients(ctx, &topts.ParamsRun.Info))
ctx, err := cctx.GetControllerCtxInfo(ctx, topts.ParamsRun)
assert.NilError(t, err)
assert.NilError(t, pacrepo.CreateNS(ctx, topts.TargetNS, topts.ParamsRun))
cfgMapData := map[string]string{
"custom-console-name": "Custom Console",
"custom-console-url": "https://url",
"custom-console-url-pr-details": "https://url/detail/{{ custom }}",
"custom-console-url-pr-tasklog": "https://url/log/{{ custom }}",
"tekton-dashboard-url": "",
}
defer configmap.ChangeGlobalConfig(ctx, t, topts.ParamsRun, cfgMapData)()
_, f := tgitea.TestPR(t, topts)
defer f()
// topts.Regexp = regexp.MustCompile(`(?m).*Custom Console.*https://url/detail/myconsole.*https://url/log/myconsole`)
topts.Regexp = regexp.MustCompile(`(?m).*Custom Console.*https://url/detail/myconsole`)
tgitea.WaitForPullRequestCommentMatch(t, topts)
topts.Regexp = regexp.MustCompile(`(?m).*https://url/log/myconsole`)
tgitea.WaitForPullRequestCommentMatch(t, topts)
}
func TestGiteaGlobalRepoParams(t *testing.T) {
topts := &tgitea.TestOpts{
CheckForStatus: "success",
SkipEventsCheck: true,
TargetEvent: triggertype.PullRequest.String(),
YAMLFiles: map[string]string{
".tekton/pr.yaml": "testdata/params.yaml",
},
GlobalRepoCRParams: &[]v1alpha1.Params{
{
Name: "no_filter",
Value: "I come from the global params",
},
},
}
topts.TargetRefName = names.SimpleNameGenerator.RestrictLengthWithRandomSuffix("pac-e2e-test")
topts.TargetNS = topts.TargetRefName
ctx := context.Background()
topts.ParamsRun, topts.Opts, topts.GiteaCNX, _ = tgitea.Setup(ctx)
assert.NilError(t, topts.ParamsRun.Clients.NewClients(ctx, &topts.ParamsRun.Info))
ctx, err := cctx.GetControllerCtxInfo(ctx, topts.ParamsRun)
assert.NilError(t, err)
assert.NilError(t, pacrepo.CreateNS(ctx, topts.TargetNS, topts.ParamsRun))
_, f := tgitea.TestPR(t, topts)
defer f()
waitOpts := twait.Opts{
RepoName: topts.TargetNS,
Namespace: topts.TargetNS,
MinNumberStatus: 1,
PollTimeout: twait.DefaultTimeout,
}
repo, err := twait.UntilRepositoryUpdated(context.Background(), topts.ParamsRun.Clients, waitOpts)
assert.NilError(t, err)
last := repo.Status[len(repo.Status)-1]
err = twait.RegexpMatchingInPodLog(
context.Background(),
topts.ParamsRun,
topts.TargetNS,
fmt.Sprintf("tekton.dev/pipelineRun=%s", last.PipelineRunName),
"step-test-params-value",
regexp.Regexp{},
t.Name(),
2,
)
assert.NilError(t, err)
}
// TestGiteaGlobalRepoUseLocalDef will test when having params from the global
// and local repository or gitprovider secret on both it uses the local first.
func TestGiteaGlobalRepoUseLocalDef(t *testing.T) {
topts := &tgitea.TestOpts{
CheckForStatus: "success",
SkipEventsCheck: true,
TargetEvent: triggertype.PullRequest.String(),
YAMLFiles: map[string]string{
".tekton/pr.yaml": "testdata/params.yaml",
},
RepoCRParams: &[]v1alpha1.Params{
{
Name: "no_filter",
Value: "I come from the local params",
},
},
}
topts.TargetRefName = names.SimpleNameGenerator.RestrictLengthWithRandomSuffix("pac-e2e-test")
topts.TargetNS = topts.TargetRefName
ctx := context.Background()
topts.ParamsRun, topts.Opts, topts.GiteaCNX, _ = tgitea.Setup(ctx)
assert.NilError(t, topts.ParamsRun.Clients.NewClients(ctx, &topts.ParamsRun.Info))
ctx, err := cctx.GetControllerCtxInfo(ctx, topts.ParamsRun)
assert.NilError(t, err)
assert.NilError(t, pacrepo.CreateNS(ctx, topts.TargetNS, topts.ParamsRun))
globalNs := info.GetNS(ctx)
err = tgitea.CreateCRD(ctx, topts,
v1alpha1.RepositorySpec{
GitProvider: &v1alpha1.GitProvider{
Secret: &v1alpha1.Secret{
Name: "notreallyhere",
},
},
Params: &[]v1alpha1.Params{
{
Name: "no_filter",
Value: "I come from the global params",
},
},
},
true)
assert.NilError(t, err)
defer (func() {
if os.Getenv("TEST_NOCLEANUP") != "true" {
topts.ParamsRun.Clients.Log.Infof("Cleaning up global repo %s in %s", info.DefaultGlobalRepoName, globalNs)
_ = topts.ParamsRun.Clients.PipelineAsCode.PipelinesascodeV1alpha1().Repositories(globalNs).Delete(
context.Background(), info.DefaultGlobalRepoName, metav1.DeleteOptions{})
}
})()
_, f := tgitea.TestPR(t, topts)
defer f()
waitOpts := twait.Opts{
RepoName: topts.TargetNS,
Namespace: topts.TargetNS,
MinNumberStatus: 1,
PollTimeout: twait.DefaultTimeout,
}
repo, err := twait.UntilRepositoryUpdated(context.Background(), topts.ParamsRun.Clients, waitOpts)
assert.NilError(t, err)
last := repo.Status[len(repo.Status)-1]
err = twait.RegexpMatchingInPodLog(
context.Background(),
topts.ParamsRun,
topts.TargetNS,
fmt.Sprintf("tekton.dev/pipelineRun=%s", last.PipelineRunName),
"step-test-params-value",
regexp.Regexp{},
t.Name(),
2,
)
assert.NilError(t, err)
}
func TestGiteaParamsOnRepoCR(t *testing.T) {
topts := &tgitea.TestOpts{
CheckForStatus: "success",
SkipEventsCheck: true,
TargetEvent: triggertype.PullRequest.String(),
YAMLFiles: map[string]string{
".tekton/pr.yaml": "testdata/params.yaml",
},
RepoCRParams: &[]v1alpha1.Params{
{
Name: "no_filter",
Value: "Follow me on my ig #nofilter",
},
{
Name: "event_type_match",
Value: "I am the most Kawaī params",
Filter: `pac.event_type == "pull_request"`,
},
{
Name: "event_type_match",
Value: "Nobody should see me, i am superseded by the previous params with same name 😠",
Filter: `pac.event_type == "pull_request"`,
},
{
Name: "no_match",
Value: "Am I being ignored?",
Filter: `pac.event_type == "xxxxxxx"`,
},
{
Name: "filter_on_body",
Value: "Hey I show up from a payload match",
Filter: `body.action == "opened"`,
},
{
Name: "secret value",
SecretRef: &v1alpha1.Secret{
Name: "param-secret",
Key: "secret",
},
},
{
Name: "secret_nothere",
SecretRef: &v1alpha1.Secret{
Name: "param-secret-not-present",
Key: "unknowsecret",
},
},
},
}
topts.TargetRefName = names.SimpleNameGenerator.RestrictLengthWithRandomSuffix("pac-e2e-test")
topts.TargetNS = topts.TargetRefName
ctx := context.Background()
topts.ParamsRun, topts.Opts, topts.GiteaCNX, _ = tgitea.Setup(ctx)
assert.NilError(t, topts.ParamsRun.Clients.NewClients(ctx, &topts.ParamsRun.Info))
ctx, err := cctx.GetControllerCtxInfo(ctx, topts.ParamsRun)
assert.NilError(t, err)
assert.NilError(t, pacrepo.CreateNS(ctx, topts.TargetNS, topts.ParamsRun))
assert.NilError(t, secret.Create(ctx, topts.ParamsRun, map[string]string{"secret": "SHHHHHHH"}, topts.TargetNS,
"param-secret"))
_, f := tgitea.TestPR(t, topts)
defer f()
repo, err := topts.ParamsRun.Clients.PipelineAsCode.PipelinesascodeV1alpha1().Repositories(topts.TargetNS).Get(context.Background(), topts.TargetNS, metav1.GetOptions{})
assert.NilError(t, err)
assert.Assert(t, len(repo.Status) != 0)
assert.NilError(t,
twait.RegexpMatchingInPodLog(context.Background(), topts.ParamsRun, topts.TargetNS, fmt.Sprintf("tekton.dev/pipelineRun=%s,tekton.dev/pipelineTask=params",
repo.Status[0].PipelineRunName), "step-test-params-value", *regexp.MustCompile(
"I am the most Kawaī params\nSHHHHHHH\nFollow me on my ig #nofilter\n{{ no_match }}\nHey I show up from a payload match\n{{ secret_nothere }}"), "", 2))
}
// TestGiteaParamsBodyHeadersCEL Test that we can access the pull request body and headers in params
// as a CEL expression and cel filter.
func TestGiteaParamsBodyHeadersCEL(t *testing.T) {
// Setup a repo and create a pull request with two pipelinerun in tekton
// dir, one matching pull via cel filtering expression and one for push
// and make it succeed
topts := &tgitea.TestOpts{
Regexp: successRegexp,
TargetEvent: "pull_request",
YAMLFiles: map[string]string{
".tekton/pullrequest.yaml": "testdata/pipelinerun-cel-params-pullrequest.yaml",
".tekton/push.yaml": "testdata/pipelinerun-cel-params-push.yaml",
},
CheckForStatus: "success",
ExpectEvents: false,
}
_, f := tgitea.TestPR(t, topts)
defer f()
// check the repos CR only one pr should have run
repo, err := topts.ParamsRun.Clients.PipelineAsCode.PipelinesascodeV1alpha1().Repositories(topts.TargetNS).Get(context.Background(), topts.TargetNS, metav1.GetOptions{})
assert.NilError(t, err)
assert.Equal(t, len(repo.Status), 1, repo.Status)
// check the output logs if the CEL body headers has expanded properly
output := `Look mum I know that we are acting on a pull_request
my email is a true beauty and like groot, I AM pac`
err = twait.RegexpMatchingInPodLog(context.Background(), topts.ParamsRun, topts.TargetNS, fmt.Sprintf("tekton.dev/pipelineRun=%s,tekton.dev/pipelineTask=cel-pullrequest-params",
repo.Status[0].PipelineRunName), "step-test-cel-params-value", *regexp.MustCompile(output), "", 2)
assert.NilError(t, err)
// Merge the pull request so we can generate a push event and wait that it is updated
merged, resp, err := topts.GiteaCNX.Client.MergePullRequest(topts.Opts.Organization, topts.Opts.Repo, topts.PullRequest.Index,
gitea.MergePullRequestOption{
Title: "Merged with Panache",
Style: "merge",
},
)
assert.NilError(t, err)
assert.Assert(t, resp.StatusCode < 400, resp)
assert.Assert(t, merged)
waitOpts := twait.Opts{
RepoName: topts.TargetNS,
Namespace: topts.TargetNS,
MinNumberStatus: 2, // 1 means 2 🙃
PollTimeout: twait.DefaultTimeout,
TargetSHA: topts.PullRequest.Head.Sha,
}
_, err = twait.UntilRepositoryUpdated(context.Background(), topts.ParamsRun.Clients, waitOpts)
assert.NilError(t, err)
time.Sleep(5 * time.Second)
// check the repository CR now we should have two status the previous pull request and new one on push
repo, err = topts.ParamsRun.Clients.PipelineAsCode.PipelinesascodeV1alpha1().Repositories(topts.TargetNS).Get(context.Background(), topts.TargetNS, metav1.GetOptions{})
assert.NilError(t, err)
assert.Equal(t, len(repo.Status), 2, repo.Status)
// sort status to make sure we get the latest PipelineRun that has been created
sortedstatus := sort.RepositorySortRunStatus(repo.Status)
// check the output of the last status PipelineRun which should be a
// push matching the expanded CEL body and headers values
output = `Look mum I know that we are acting on a push
my email is a true beauty and you can call me pacman`
err = twait.RegexpMatchingInPodLog(context.Background(), topts.ParamsRun, topts.TargetNS, fmt.Sprintf("tekton.dev/pipelineRun=%s,tekton.dev/pipelineTask=cel-push-params", sortedstatus[0].PipelineRunName), "step-test-cel-params-value", *regexp.MustCompile(output), "", 2)
assert.NilError(t, err)
}
// TestGiteaParamsChangedFilesCEL Test that we can access the pull request body and headers in params
// as a CEL expression and cel filter.
func TestGiteaParamsChangedFilesCEL(t *testing.T) {
topts := &tgitea.TestOpts{
Regexp: successRegexp,
TargetEvent: "pull_request",
YAMLFiles: map[string]string{
".tekton/pullrequest.yaml": "testdata/pipelinerun-changed-files-pullrequest.yaml",
".tekton/push.yaml": "testdata/pipelinerun-changed-files-push.yaml",
"deleted.txt": "testdata/changed_files_deleted",
"modified.txt": "testdata/changed_files_modified",
"renamed.txt": "testdata/changed_files_renamed",
},
CheckForStatus: "success",
ExpectEvents: false,
FileChanges: []scm.FileChange{
{
FileName: "deleted.txt",
ChangeType: "delete",
},
{
FileName: "modified.txt",
ChangeType: "modify",
NewContent: "this file has been modified",
},
{
FileName: "renamed.txt",
ChangeType: "rename",
NewName: "hasbeenrenamed.txt",
},
},
}
_, f := tgitea.TestPR(t, topts)
defer f()
// check the repos CR only one pr should have run
repo, err := topts.ParamsRun.Clients.PipelineAsCode.PipelinesascodeV1alpha1().Repositories(topts.TargetNS).Get(context.Background(), topts.TargetNS, metav1.GetOptions{})
assert.NilError(t, err)
assert.Equal(t, len(repo.Status), 1, repo.Status)
twait.GoldenPodLog(context.Background(), t, topts.ParamsRun, topts.TargetNS,
fmt.Sprintf("tekton.dev/pipelineRun=%s,tekton.dev/pipelineTask=changed-files-pullrequest-params", repo.Status[0].PipelineRunName),
"step-test-changed-files-params-pull", strings.ReplaceAll(fmt.Sprintf("%s-changed-files-pullrequest-params-1.golden", t.Name()), "/", "-"), 2)
// ======================================================================================================================
// Merge the pull request so we can generate a push event and wait that it is updated
// ======================================================================================================================
merged, resp, err := topts.GiteaCNX.Client.MergePullRequest(topts.Opts.Organization, topts.Opts.Repo, topts.PullRequest.Index,
gitea.MergePullRequestOption{
Title: "Merged with Panache",
Style: "merge",
},
)
assert.NilError(t, err)
assert.Assert(t, resp.StatusCode < 400, resp)
assert.Assert(t, merged)
waitOpts := twait.Opts{
RepoName: topts.TargetNS,
Namespace: topts.TargetNS,
MinNumberStatus: 2, // 1 means 2 🙃
PollTimeout: twait.DefaultTimeout,
TargetSHA: topts.PullRequest.Head.Sha,
}
_, err = twait.UntilRepositoryUpdated(context.Background(), topts.ParamsRun.Clients, waitOpts)
assert.NilError(t, err)
time.Sleep(5 * time.Second)
// check the repository CR now we should have two status the previous pull request and new one on push
repo, err = topts.ParamsRun.Clients.PipelineAsCode.PipelinesascodeV1alpha1().Repositories(topts.TargetNS).Get(context.Background(), topts.TargetNS, metav1.GetOptions{})
assert.NilError(t, err)
assert.Equal(t, len(repo.Status), 2, repo.Status)
// sort status to make sure we get the latest PipelineRun that has been created
sortedstatus := sort.RepositorySortRunStatus(repo.Status)
twait.GoldenPodLog(context.Background(), t, topts.ParamsRun, topts.TargetNS,
fmt.Sprintf("tekton.dev/pipelineRun=%s,tekton.dev/pipelineTask=changed-files-push-params", sortedstatus[0].PipelineRunName),
"step-test-changed-files-params-push", strings.ReplaceAll(fmt.Sprintf("%s-changed-files-push-params-1.golden", t.Name()), "/", "-"), 2)
// ======================================================================================================================
// Create second pull request with all change types
// ======================================================================================================================
tgitea.NewPR(t, topts)
// check the repository CR now we should have three status the previous pull request and push plus a new pull request
repo, err = topts.ParamsRun.Clients.PipelineAsCode.PipelinesascodeV1alpha1().Repositories(topts.TargetNS).Get(context.Background(), topts.TargetNS, metav1.GetOptions{})
assert.NilError(t, err)
assert.Equal(t, len(repo.Status), 3, repo.Status)
twait.GoldenPodLog(context.Background(), t, topts.ParamsRun, topts.TargetNS,
fmt.Sprintf("tekton.dev/pipelineRun=%s,tekton.dev/pipelineTask=changed-files-pullrequest-params", repo.Status[2].PipelineRunName),
"step-test-changed-files-params-pull", strings.ReplaceAll(fmt.Sprintf("%s-changed-files-pullrequest-params-2.golden", t.Name()), "/", "-"), 2)
// ======================================================================================================================
// Merge the pull request so we can generate a second push event and wait that it is updated
// ======================================================================================================================
merged, resp, err = topts.GiteaCNX.Client.MergePullRequest(topts.Opts.Organization, topts.Opts.Repo, topts.PullRequest.Index,
gitea.MergePullRequestOption{
Title: "Merged with Panache",
Style: "merge",
},
)
assert.NilError(t, err)
assert.Assert(t, resp.StatusCode < 400, resp)
assert.Assert(t, merged)
waitOpts = twait.Opts{
RepoName: topts.TargetNS,
Namespace: topts.TargetNS,
MinNumberStatus: 4, // 1 means 2 🙃
PollTimeout: twait.DefaultTimeout,
TargetSHA: topts.PullRequest.Head.Sha,
}
_, err = twait.UntilRepositoryUpdated(context.Background(), topts.ParamsRun.Clients, waitOpts)
assert.NilError(t, err)
time.Sleep(5 * time.Second)
// check the repository CR now we should have two status the previous pull request and new one on push
repo, err = topts.ParamsRun.Clients.PipelineAsCode.PipelinesascodeV1alpha1().Repositories(topts.TargetNS).Get(context.Background(), topts.TargetNS, metav1.GetOptions{})
assert.NilError(t, err)
assert.Equal(t, len(repo.Status), 4, repo.Status)
// sort status to make sure we get the latest PipelineRun that has been created
sortedstatus = sort.RepositorySortRunStatus(repo.Status)
// check the output of the last status PipelineRun which should be a
// push matching the expanded CEL body and headers values
twait.GoldenPodLog(context.Background(), t, topts.ParamsRun, topts.TargetNS,
fmt.Sprintf("tekton.dev/pipelineRun=%s,tekton.dev/pipelineTask=changed-files-push-params", sortedstatus[0].PipelineRunName),
"step-test-changed-files-params-push", strings.ReplaceAll(fmt.Sprintf("%s-changed-files-push-params-2.golden", t.Name()), "/", "-"), 2)
}