Skip to content

Commit 1f9ba8c

Browse files
zakiskchmouel
authored andcommitted
fix: use correct event type in log in GetTektonDir func
this fixes logs message in GetTektonDir func for event type. Signed-off-by: Zaki Shaikh <[email protected]>
1 parent 527ebbf commit 1f9ba8c

File tree

8 files changed

+73
-20
lines changed

8 files changed

+73
-20
lines changed

pkg/provider/bitbucketcloud/bitbucket.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ func (v *Provider) getDir(event *info.Event, path string) ([]bitbucket.Repositor
171171
revision = event.DefaultBranch
172172
v.Logger.Infof("Using PipelineRun definition from default_branch: %s", event.DefaultBranch)
173173
} else {
174-
v.Logger.Infof("Using PipelineRun definition from source pull request SHA: %s", event.SHA)
174+
v.Logger.Infof("Using PipelineRun definition from source %s commit SHA: %s", event.TriggerTarget.String(), event.SHA)
175175
}
176176
repoFileOpts := &bitbucket.RepositoryFilesOptions{
177177
Owner: event.Organization,

pkg/provider/bitbucketcloud/bitbucket_test.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/openshift-pipelines/pipelines-as-code/pkg/params"
99
"github.com/openshift-pipelines/pipelines-as-code/pkg/params/info"
1010
"github.com/openshift-pipelines/pipelines-as-code/pkg/params/settings"
11+
"github.com/openshift-pipelines/pipelines-as-code/pkg/params/triggertype"
1112
"github.com/openshift-pipelines/pipelines-as-code/pkg/provider"
1213
bbcloudtest "github.com/openshift-pipelines/pipelines-as-code/pkg/provider/bitbucketcloud/test"
1314
"github.com/openshift-pipelines/pipelines-as-code/pkg/provider/bitbucketcloud/types"
@@ -35,11 +36,18 @@ func TestGetTektonDir(t *testing.T) {
3536
filterMessageSnippet string
3637
}{
3738
{
38-
name: "Get Tekton Directory",
39-
event: bbcloudtest.MakeEvent(nil),
39+
name: "Get Tekton Directory on pull request",
40+
event: bbcloudtest.MakeEvent(&info.Event{TriggerTarget: triggertype.PullRequest}),
4041
testDirPath: "../../pipelineascode/testdata/pull_request/.tekton",
4142
contentContains: "kind: PipelineRun",
42-
filterMessageSnippet: "Using PipelineRun definition from source pull request SHA",
43+
filterMessageSnippet: "Using PipelineRun definition from source pull_request commit SHA",
44+
},
45+
{
46+
name: "Get Tekton Directory on push",
47+
event: bbcloudtest.MakeEvent(&info.Event{TriggerTarget: triggertype.Push}),
48+
testDirPath: "../../pipelineascode/testdata/pull_request/.tekton",
49+
contentContains: "kind: PipelineRun",
50+
filterMessageSnippet: "Using PipelineRun definition from source push commit SHA",
4351
},
4452
{
4553
name: "Get Tekton Directory Mainbranch",

pkg/provider/bitbucketdatacenter/bitbucketdatacenter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ func (v *Provider) GetTektonDir(ctx context.Context, event *info.Event, path, pr
212212
at := ""
213213
if v.provenance == "source" {
214214
at = event.SHA
215-
v.Logger.Infof("Using PipelineRun definition from source pull request SHA: %s", event.SHA)
215+
v.Logger.Infof("Using PipelineRun definition from source %s commit SHA: %s", event.TriggerTarget.String(), event.SHA)
216216
} else {
217217
v.Logger.Infof("Using PipelineRun definition from default_branch: %s", event.DefaultBranch)
218218
}

pkg/provider/gitea/gitea.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ func (v *Provider) GetTektonDir(_ context.Context, event *info.Event, path, prov
254254
revision = event.DefaultBranch
255255
v.Logger.Infof("Using PipelineRun definition from default_branch: %s", event.DefaultBranch)
256256
} else {
257-
v.Logger.Infof("Using PipelineRun definition from source pull request SHA: %s", event.SHA)
257+
v.Logger.Infof("Using PipelineRun definition from source %s commit SHA: %s", event.TriggerTarget.String(), event.SHA)
258258
}
259259

260260
tektonDirSha := ""

pkg/provider/github/github.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,11 @@ func (v *Provider) GetTektonDir(ctx context.Context, runevent *info.Event, path,
324324
revision = runevent.DefaultBranch
325325
v.Logger.Infof("Using PipelineRun definition from default_branch: %s", runevent.DefaultBranch)
326326
} else {
327-
v.Logger.Infof("Using PipelineRun definition from source pull request %s/%s#%d SHA on %s", runevent.Organization, runevent.Repository, runevent.PullRequestNumber, runevent.SHA)
327+
prInfo := ""
328+
if runevent.TriggerTarget == triggertype.PullRequest {
329+
prInfo = fmt.Sprintf("%s/%s#%d", runevent.Organization, runevent.Repository, runevent.PullRequestNumber)
330+
}
331+
v.Logger.Infof("Using PipelineRun definition from source %s %s on commit SHA %s", runevent.TriggerTarget.String(), prInfo, runevent.SHA)
328332
}
329333

330334
rootobjects, _, err := v.Client().Git.GetTree(ctx, runevent.Organization, runevent.Repository, revision, false)

pkg/provider/github/github_test.go

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -240,15 +240,32 @@ func TestGetTektonDir(t *testing.T) {
240240
expectedGHApiCalls int64
241241
}{
242242
{
243-
name: "test no subtree",
243+
name: "test no subtree on pull request",
244244
event: &info.Event{
245-
Organization: "tekton",
246-
Repository: "cat",
247-
SHA: "123",
245+
Organization: "tekton",
246+
Repository: "cat",
247+
SHA: "123",
248+
TriggerTarget: triggertype.PullRequest,
249+
},
250+
expectedString: "PipelineRun",
251+
treepath: "testdata/tree/simple",
252+
filterMessageSnippet: "Using PipelineRun definition from source pull_request tekton/cat#0",
253+
// 1. Get Repo root objects
254+
// 2. Get Tekton Dir objects
255+
// 3/4. Get object content for each object (pipelinerun.yaml, pipeline.yaml)
256+
expectedGHApiCalls: 4,
257+
},
258+
{
259+
name: "test no subtree on push",
260+
event: &info.Event{
261+
Organization: "tekton",
262+
Repository: "cat",
263+
SHA: "123",
264+
TriggerTarget: triggertype.Push,
248265
},
249266
expectedString: "PipelineRun",
250267
treepath: "testdata/tree/simple",
251-
filterMessageSnippet: "Using PipelineRun definition from source pull request tekton/cat#0",
268+
filterMessageSnippet: "Using PipelineRun definition from source push",
252269
// 1. Get Repo root objects
253270
// 2. Get Tekton Dir objects
254271
// 3/4. Get object content for each object (pipelinerun.yaml, pipeline.yaml)
@@ -302,13 +319,14 @@ func TestGetTektonDir(t *testing.T) {
302319
{
303320
name: "test no tekton directory",
304321
event: &info.Event{
305-
Organization: "tekton",
306-
Repository: "cat",
307-
SHA: "123",
322+
Organization: "tekton",
323+
Repository: "cat",
324+
SHA: "123",
325+
TriggerTarget: triggertype.PullRequest,
308326
},
309327
expectedString: "",
310328
treepath: "testdata/tree/notektondir",
311-
filterMessageSnippet: "Using PipelineRun definition from source pull request tekton/cat#0",
329+
filterMessageSnippet: "Using PipelineRun definition from source pull_request tekton/cat#0",
312330
// 1. Get Repo root objects
313331
// _. No tekton dir to fetch
314332
expectedGHApiCalls: 1,

pkg/provider/gitlab/gitlab.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,11 @@ func (v *Provider) GetTektonDir(_ context.Context, event *info.Event, path, prov
329329
revision = event.DefaultBranch
330330
v.Logger.Infof("Using PipelineRun definition from default_branch: %s", event.DefaultBranch)
331331
} else {
332-
v.Logger.Infof("Using PipelineRun definition from source merge request SHA: %s", event.SHA)
332+
trigger := event.TriggerTarget.String()
333+
if event.TriggerTarget == triggertype.PullRequest {
334+
trigger = "merge request"
335+
}
336+
v.Logger.Infof("Using PipelineRun definition from source %s on commit SHA: %s", trigger, event.SHA)
333337
}
334338

335339
opt := &gitlab.ListTreeOptions{

pkg/provider/gitlab/gitlab_test.go

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/openshift-pipelines/pipelines-as-code/pkg/params/clients"
1616
"github.com/openshift-pipelines/pipelines-as-code/pkg/params/info"
1717
"github.com/openshift-pipelines/pipelines-as-code/pkg/params/settings"
18+
"github.com/openshift-pipelines/pipelines-as-code/pkg/params/triggertype"
1819
"github.com/openshift-pipelines/pipelines-as-code/pkg/provider"
1920
thelp "github.com/openshift-pipelines/pipelines-as-code/pkg/provider/gitlab/test"
2021
testclient "github.com/openshift-pipelines/pipelines-as-code/pkg/test/clients"
@@ -460,20 +461,38 @@ func TestGetTektonDir(t *testing.T) {
460461
wantErr: "error unmarshalling yaml file pr.yaml: yaml: line 4: could not find expected ':'",
461462
},
462463
{
463-
name: "list tekton dir",
464+
name: "list tekton dir on pull request",
464465
prcontent: string(samplePR),
465466
args: args{
466467
path: ".tekton",
467468
event: &info.Event{
468-
HeadBranch: "main",
469+
HeadBranch: "main",
470+
TriggerTarget: triggertype.PullRequest,
471+
},
472+
},
473+
fields: fields{
474+
sourceProjectID: 100,
475+
},
476+
wantClient: true,
477+
wantStr: "kind: PipelineRun",
478+
filterMessageSnippet: `Using PipelineRun definition from source merge request on commit SHA`,
479+
},
480+
{
481+
name: "list tekton dir on push",
482+
prcontent: string(samplePR),
483+
args: args{
484+
path: ".tekton",
485+
event: &info.Event{
486+
HeadBranch: "main",
487+
TriggerTarget: triggertype.Push,
469488
},
470489
},
471490
fields: fields{
472491
sourceProjectID: 100,
473492
},
474493
wantClient: true,
475494
wantStr: "kind: PipelineRun",
476-
filterMessageSnippet: `Using PipelineRun definition from source merge request SHA`,
495+
filterMessageSnippet: `Using PipelineRun definition from source push on commit SHA`,
477496
},
478497
{
479498
name: "list tekton dir on default_branch",

0 commit comments

Comments
 (0)