From 38bef0be7b07c6d023c3687ed9e7b690a99291af Mon Sep 17 00:00:00 2001 From: Ken Cloutier Date: Mon, 3 Jul 2023 12:08:53 -0400 Subject: [PATCH] improve get changed files This change will add support for separating the files by the change type i.e. added, modified, deleted and renamed for a giving source control event. This provides the ability to target only added files or only renamed files. Note that this change still supports all changed files in case specifics types of changes are not needed. In addition, this change will also allow the changed file information to be passed down using templating variables. The following templated variables have been added - {{all_changed_files}} - {{added_files}} - {{deleted_files}} - {{modified_files}} - {{renamed_files}} --- docs/content/docs/guide/authoringprs.md | 19 ++ pkg/customparams/customparams.go | 7 +- pkg/customparams/customparams_test.go | 2 +- pkg/customparams/standard.go | 43 ++- pkg/customparams/standard_test.go | 40 ++- pkg/formatting/array.go | 13 + pkg/formatting/array_test.go | 40 +++ pkg/matcher/annotation_matcher_test.go | 257 +++++++++++++++++- pkg/matcher/cel.go | 48 +++- pkg/pipelineascode/pipelineascode.go | 2 +- pkg/pipelineascode/template.go | 2 +- pkg/provider/bitbucketcloud/bitbucket.go | 4 +- .../bitbucketserver/bitbucketserver.go | 4 +- pkg/provider/gitea/gitea.go | 4 +- pkg/provider/github/github.go | 47 +++- pkg/provider/github/github_test.go | 95 +++++-- pkg/provider/gitlab/gitlab.go | 47 +++- pkg/provider/gitlab/gitlab_test.go | 144 +++++++--- pkg/provider/interface.go | 10 +- pkg/reconciler/reconciler.go | 2 +- pkg/test/provider/testwebvcs.go | 15 +- 21 files changed, 706 insertions(+), 139 deletions(-) create mode 100644 pkg/formatting/array.go create mode 100644 pkg/formatting/array_test.go diff --git a/docs/content/docs/guide/authoringprs.md b/docs/content/docs/guide/authoringprs.md index e78e969a5..885cf507f 100644 --- a/docs/content/docs/guide/authoringprs.md +++ b/docs/content/docs/guide/authoringprs.md @@ -39,6 +39,11 @@ weight: 3 * `{{target_branch}}`: The branch name on which the event targets (same as `source_branch` for push events). * `{{pull_request_number}}`: The pull or merge request number, only defined when we are in a `pull_request` event type. * `{{git_auth_secret}}`: The secret name auto generated with provider token to check out private repos. + * `{{all_changed_files}}`: The list of all files changed in the event (added, deleted, modified and renamed) separated by a comma. On pull request every file belonging to the pull request will be listed. + * `{{added_files}}`: The list of added files in the event separated by a comma. On pull request every added file belonging to the pull request will be listed. + * `{{deleted_files}}`: The list of deleted files in the event separated by a comma. On pull request every deleted file belonging to the pull request will be listed. + * `{{modified_files}}`: The list of modified files in the event separated by a comma. On pull request every modified file belonging to the pull request will be listed. + * `{{renamed_files}}`: The list of renamed files in the event separated by a comma. On pull request every renamed file belonging to the pull request will be listed. * For Pipelines-as-Code to process your `PipelineRun`, you must have either an embedded `PipelineSpec` or a separate `Pipeline` object that references a YAML @@ -136,6 +141,20 @@ suffix) in the `docs` directory : event == "pull_request" && "docs/*.md".pathChanged() ``` +This example will match any changed file (added, modified, removed or renamed) that was in the `tmp` directory: + +```yaml + pipelinesascode.tekton.dev/on-cel-expression: | + all_changed_files.matches('tmp/') +``` + +This example will match any added file that was in the `src` directory: + +```yaml + pipelinesascode.tekton.dev/on-cel-expression: | + added_files.matches('src/') +``` + This example will match all pull request starting with the title `[DOWNSTREAM]`: ```yaml diff --git a/pkg/customparams/customparams.go b/pkg/customparams/customparams.go index 52257e097..df1fb8321 100644 --- a/pkg/customparams/customparams.go +++ b/pkg/customparams/customparams.go @@ -9,6 +9,7 @@ import ( "github.com/openshift-pipelines/pipelines-as-code/pkg/kubeinteraction" "github.com/openshift-pipelines/pipelines-as-code/pkg/params" "github.com/openshift-pipelines/pipelines-as-code/pkg/params/info" + "github.com/openshift-pipelines/pipelines-as-code/pkg/provider" sectypes "github.com/openshift-pipelines/pipelines-as-code/pkg/secrets/types" "go.uber.org/zap" ) @@ -19,15 +20,17 @@ type CustomParams struct { k8int kubeinteraction.Interface eventEmitter *events.EventEmitter repo *v1alpha1.Repository + vcx provider.Interface } -func NewCustomParams(event *info.Event, repo *v1alpha1.Repository, run *params.Run, k8int kubeinteraction.Interface, eventEmitter *events.EventEmitter) CustomParams { +func NewCustomParams(event *info.Event, repo *v1alpha1.Repository, run *params.Run, k8int kubeinteraction.Interface, eventEmitter *events.EventEmitter, prov provider.Interface) CustomParams { return CustomParams{ event: event, repo: repo, run: run, k8int: k8int, eventEmitter: eventEmitter, + vcx: prov, } } @@ -38,7 +41,7 @@ func NewCustomParams(event *info.Event, repo *v1alpha1.Repository, run *params.R // if multiple params name has a filter we pick up the first one that has // matched true. func (p *CustomParams) GetParams(ctx context.Context) (map[string]string, error) { - stdParams := p.makeStandardParamsFromEvent() + stdParams := p.makeStandardParamsFromEvent(ctx) if p.repo.Spec.Params == nil { return stdParams, nil } diff --git a/pkg/customparams/customparams_test.go b/pkg/customparams/customparams_test.go index 1c5b083fe..ee46967a6 100644 --- a/pkg/customparams/customparams_test.go +++ b/pkg/customparams/customparams_test.go @@ -280,7 +280,7 @@ func TestProcessTemplates(t *testing.T) { if tt.event == nil { tt.event = &info.Event{} } - p := NewCustomParams(tt.event, repo, run, &kitesthelper.KinterfaceTest{GetSecretResult: tt.secretData}, nil) + p := NewCustomParams(tt.event, repo, run, &kitesthelper.KinterfaceTest{GetSecretResult: tt.secretData}, nil, nil) stdata, _ := testclient.SeedTestData(t, ctx, testclient.Data{}) p.eventEmitter = events.NewEventEmitter(stdata.Kube, logger) ret, err := p.GetParams(ctx) diff --git a/pkg/customparams/standard.go b/pkg/customparams/standard.go index 7df222ca3..da0327f02 100644 --- a/pkg/customparams/standard.go +++ b/pkg/customparams/standard.go @@ -1,29 +1,50 @@ package customparams import ( + "context" + "fmt" "strings" "github.com/openshift-pipelines/pipelines-as-code/pkg/formatting" + "github.com/openshift-pipelines/pipelines-as-code/pkg/provider" + "go.uber.org/zap" ) +func (p *CustomParams) getChangedFilesCommaSeparated(ctx context.Context) provider.ChangedFiles { + if p.vcx == nil { + return provider.ChangedFiles{} + } + changedFiles, err := p.vcx.GetFiles(ctx, p.event) + if err != nil { + p.eventEmitter.EmitMessage(p.repo, zap.ErrorLevel, "ParamsError", fmt.Sprintf("error getting changed files: %s", err.Error())) + } + + return changedFiles +} + // makeStandardParamsFromEvent will create a map of standard params out of the event -func (p *CustomParams) makeStandardParamsFromEvent() map[string]string { +func (p *CustomParams) makeStandardParamsFromEvent(ctx context.Context) map[string]string { repoURL := p.event.URL // On bitbucket server you are have a special url for checking it out, they // seemed to fix it in 2.0 but i guess we have to live with this until then. if p.event.CloneURL != "" { repoURL = p.event.CloneURL } - + changedFiles := p.getChangedFilesCommaSeparated(ctx) return map[string]string{ - "revision": p.event.SHA, - "repo_url": repoURL, - "repo_owner": strings.ToLower(p.event.Organization), - "repo_name": strings.ToLower(p.event.Repository), - "target_branch": formatting.SanitizeBranch(p.event.BaseBranch), - "source_branch": formatting.SanitizeBranch(p.event.HeadBranch), - "sender": strings.ToLower(p.event.Sender), - "target_namespace": p.repo.GetNamespace(), - "event_type": p.event.EventType, + "revision": p.event.SHA, + "repo_url": repoURL, + "repo_owner": strings.ToLower(p.event.Organization), + "repo_name": strings.ToLower(p.event.Repository), + "target_branch": formatting.SanitizeBranch(p.event.BaseBranch), + "source_branch": formatting.SanitizeBranch(p.event.HeadBranch), + "sender": strings.ToLower(p.event.Sender), + "target_namespace": p.repo.GetNamespace(), + "event_type": p.event.EventType, + "all_changed_files": strings.Join(formatting.UniqueStringArray(changedFiles.All), ","), + "added_files": strings.Join(formatting.UniqueStringArray(changedFiles.Added), ","), + "deleted_files": strings.Join(formatting.UniqueStringArray(changedFiles.Deleted), ","), + "modified_files": strings.Join(formatting.UniqueStringArray(changedFiles.Modified), ","), + "renamed_files": strings.Join(formatting.UniqueStringArray(changedFiles.Renamed), ","), } } diff --git a/pkg/customparams/standard_test.go b/pkg/customparams/standard_test.go index 31d60a9a4..290a1961f 100644 --- a/pkg/customparams/standard_test.go +++ b/pkg/customparams/standard_test.go @@ -5,8 +5,10 @@ import ( "github.com/openshift-pipelines/pipelines-as-code/pkg/apis/pipelinesascode/v1alpha1" "github.com/openshift-pipelines/pipelines-as-code/pkg/params/info" + testprovider "github.com/openshift-pipelines/pipelines-as-code/pkg/test/provider" "gotest.tools/v3/assert" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + rectesting "knative.dev/pkg/reconciler/testing" ) func TestMakeStandardParamsFromEvent(t *testing.T) { @@ -22,15 +24,20 @@ func TestMakeStandardParamsFromEvent(t *testing.T) { } result := map[string]string{ - "event_type": "pull_request", - "repo_name": "repo", - "repo_owner": "org", - "repo_url": "https://paris.com", - "revision": "1234567890", - "sender": "sender", - "source_branch": "foo", - "target_branch": "main", - "target_namespace": "myns", + "event_type": "pull_request", + "repo_name": "repo", + "repo_owner": "org", + "repo_url": "https://paris.com", + "revision": "1234567890", + "sender": "sender", + "source_branch": "foo", + "target_branch": "main", + "target_namespace": "myns", + "all_changed_files": "added.go,deleted.go,modified.go,renamed.go", + "added_files": "added.go", + "deleted_files": "deleted.go", + "modified_files": "modified.go", + "renamed_files": "renamed.go", } repo := &v1alpha1.Repository{ @@ -40,15 +47,24 @@ func TestMakeStandardParamsFromEvent(t *testing.T) { }, } - p := NewCustomParams(event, repo, nil, nil, nil) - params := p.makeStandardParamsFromEvent() + ctx, _ := rectesting.SetupFakeContext(t) + vcx := &testprovider.TestProviderImp{ + WantAllChangedFiles: []string{"added.go", "deleted.go", "modified.go", "renamed.go"}, + WantAddedFiles: []string{"added.go"}, + WantDeletedFiles: []string{"deleted.go"}, + WantModifiedFiles: []string{"modified.go"}, + WantRenamedFiles: []string{"renamed.go"}, + } + + p := NewCustomParams(event, repo, nil, nil, nil, vcx) + params := p.makeStandardParamsFromEvent(ctx) assert.DeepEqual(t, params, result) nevent := &info.Event{} event.DeepCopyInto(nevent) nevent.CloneURL = "https://blahblah" p.event = nevent - nparams := p.makeStandardParamsFromEvent() + nparams := p.makeStandardParamsFromEvent(ctx) result["repo_url"] = nevent.CloneURL assert.DeepEqual(t, nparams, result) } diff --git a/pkg/formatting/array.go b/pkg/formatting/array.go new file mode 100644 index 000000000..48a7a071e --- /dev/null +++ b/pkg/formatting/array.go @@ -0,0 +1,13 @@ +package formatting + +func UniqueStringArray(slice []string) []string { + keys := make(map[string]bool) + list := []string{} + for _, entry := range slice { + if _, value := keys[entry]; !value { + keys[entry] = true + list = append(list, entry) + } + } + return list +} diff --git a/pkg/formatting/array_test.go b/pkg/formatting/array_test.go new file mode 100644 index 000000000..513b14594 --- /dev/null +++ b/pkg/formatting/array_test.go @@ -0,0 +1,40 @@ +package formatting + +import ( + "reflect" + "testing" +) + +func TestUniqueStringArray(t *testing.T) { + type args struct { + slice []string + } + tests := []struct { + name string + args args + want []string + }{ + { + name: "no duplicates", + args: args{ + slice: []string{"1", "2"}, + }, + want: []string{"1", "2"}, + }, + + { + name: "with duplicates", + args: args{ + slice: []string{"1", "2", "1", "2", "1", "2", "3", "2", "5", "5"}, + }, + want: []string{"1", "2", "3", "5"}, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := UniqueStringArray(tt.args.slice); !reflect.DeepEqual(got, tt.want) { + t.Errorf("UniqueStringArray() = %v, want %v", got, tt.want) + } + }) + } +} diff --git a/pkg/matcher/annotation_matcher_test.go b/pkg/matcher/annotation_matcher_test.go index da39818d5..7335fb256 100644 --- a/pkg/matcher/annotation_matcher_test.go +++ b/pkg/matcher/annotation_matcher_test.go @@ -37,10 +37,16 @@ import ( const pipelineTargetNSName = "pipeline-target-ns" type annotationTestArgs struct { - fileChanged []string - pruns []*tektonv1.PipelineRun - runevent info.Event - data testclient.Data + fileChanged []struct { + FileName string + Status string + NewFile bool + RenamedFile bool + DeletedFile bool + } + pruns []*tektonv1.PipelineRun + runevent info.Event + data testclient.Data } type annotationTest struct { @@ -68,6 +74,45 @@ func makePipelineRunTargetNS(event, targetNS string) *tektonv1.PipelineRun { func TestMatchPipelinerunAnnotationAndRepositories(t *testing.T) { cw := clockwork.NewFakeClock() + + filesChanged := []struct { + FileName string + Status string + NewFile bool + RenamedFile bool + DeletedFile bool + }{ + { + FileName: "src/added.go", + Status: "added", + NewFile: true, + RenamedFile: false, + DeletedFile: false, + }, + { + FileName: "src/modified.go", + Status: "modified", + NewFile: false, + RenamedFile: false, + DeletedFile: false, + }, + { + FileName: "src/removed.go", + Status: "removed", + NewFile: false, + RenamedFile: false, + DeletedFile: true, + }, + + { + FileName: "src/renamed.go", + Status: "renamed", + NewFile: false, + RenamedFile: true, + DeletedFile: false, + }, + } + tests := []annotationTest{ { name: "match a repository with target NS", @@ -132,7 +177,22 @@ func TestMatchPipelinerunAnnotationAndRepositories(t *testing.T) { name: "cel/match path by glob", wantPRName: pipelineTargetNSName, args: annotationTestArgs{ - fileChanged: []string{".tekton/pull_request.yaml"}, + // fileChanged: []string{".tekton/pull_request.yaml"}, + fileChanged: []struct { + FileName string + Status string + NewFile bool + RenamedFile bool + DeletedFile bool + }{ + { + FileName: ".tekton/pull_request.yaml", + Status: "added", + NewFile: true, + RenamedFile: false, + DeletedFile: false, + }, + }, pruns: []*tektonv1.PipelineRun{ { ObjectMeta: metav1.ObjectMeta{ @@ -286,8 +346,20 @@ func TestMatchPipelinerunAnnotationAndRepositories(t *testing.T) { name: "cel/no match path by glob", wantErr: true, args: annotationTestArgs{ - fileChanged: []string{ - ".tekton/foo.json", + fileChanged: []struct { + FileName string + Status string + NewFile bool + RenamedFile bool + DeletedFile bool + }{ + { + FileName: ".tekton/foo.json", + Status: "added", + NewFile: true, + RenamedFile: false, + DeletedFile: false, + }, }, pruns: []*tektonv1.PipelineRun{ { @@ -328,8 +400,20 @@ func TestMatchPipelinerunAnnotationAndRepositories(t *testing.T) { name: "cel/match by direct path", wantPRName: pipelineTargetNSName, args: annotationTestArgs{ - fileChanged: []string{ - ".tekton/pull_request.yaml", + fileChanged: []struct { + FileName string + Status string + NewFile bool + RenamedFile bool + DeletedFile bool + }{ + { + FileName: ".tekton/pull_request.yaml", + Status: "added", + NewFile: true, + RenamedFile: false, + DeletedFile: false, + }, }, pruns: []*tektonv1.PipelineRun{ { @@ -631,7 +715,21 @@ func TestMatchPipelinerunAnnotationAndRepositories(t *testing.T) { name: "cel/match path by glob along with push event and target_branch info", wantPRName: pipelineTargetNSName, args: annotationTestArgs{ - fileChanged: []string{".tekton/push.yaml"}, + fileChanged: []struct { + FileName string + Status string + NewFile bool + RenamedFile bool + DeletedFile bool + }{ + { + FileName: ".tekton/push.yaml", + Status: "added", + NewFile: true, + RenamedFile: false, + DeletedFile: false, + }, + }, pruns: []*tektonv1.PipelineRun{ { ObjectMeta: metav1.ObjectMeta{ @@ -666,6 +764,126 @@ func TestMatchPipelinerunAnnotationAndRepositories(t *testing.T) { }, }, }, + + { + name: "cel match on all changed files", + wantErr: false, + args: annotationTestArgs{ + fileChanged: filesChanged, + pruns: []*tektonv1.PipelineRun{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: pipelineTargetNSName, + Annotations: map[string]string{ + keys.OnCelExpression: "all_changed_files.matches(\"added.go\")", + }, + }, + }, + }, + runevent: info.Event{ + URL: targetURL, + TriggerTarget: "pull_request", + EventType: "pull_request", + BaseBranch: mainBranch, + HeadBranch: "unittests", + PullRequestNumber: 1000, + PullRequestTitle: "[DOWNSTREAM] don't test me cause i'm famous", + Organization: "mylittle", + Repository: "pony", + }, + data: testclient.Data{ + Repositories: []*v1alpha1.Repository{ + testnewrepo.NewRepo( + testnewrepo.RepoTestcreationOpts{ + Name: "test-good", + URL: targetURL, + InstallNamespace: targetNamespace, + }, + ), + }, + }, + }, + }, + + { + name: "cel NOT match on all changed files", + wantErr: true, + args: annotationTestArgs{ + fileChanged: filesChanged, + pruns: []*tektonv1.PipelineRun{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: pipelineTargetNSName, + Annotations: map[string]string{ + keys.OnCelExpression: "all_changed_files.matches(\"notmatch.go\")", + }, + }, + }, + }, + runevent: info.Event{ + URL: targetURL, + TriggerTarget: "pull_request", + EventType: "pull_request", + BaseBranch: mainBranch, + HeadBranch: "unittests", + PullRequestNumber: 1000, + PullRequestTitle: "[DOWNSTREAM] don't test me cause i'm famous", + Organization: "mylittle", + Repository: "pony", + }, + data: testclient.Data{ + Repositories: []*v1alpha1.Repository{ + testnewrepo.NewRepo( + testnewrepo.RepoTestcreationOpts{ + Name: "test-good", + URL: targetURL, + InstallNamespace: targetNamespace, + }, + ), + }, + }, + }, + }, + + { + name: "cel match on added, modified, deleted and renamed files", + wantErr: false, + args: annotationTestArgs{ + fileChanged: filesChanged, + pruns: []*tektonv1.PipelineRun{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: pipelineTargetNSName, + Annotations: map[string]string{ + keys.OnCelExpression: "added_files.matches(\"added.go\") && deleted_files.matches(\"removed.go\") && modified_files.matches(\"modified.go\") && renamed_files.matches(\"renamed.go\")", + }, + }, + }, + }, + runevent: info.Event{ + URL: targetURL, + TriggerTarget: "pull_request", + EventType: "pull_request", + BaseBranch: mainBranch, + HeadBranch: "unittests", + PullRequestNumber: 1000, + PullRequestTitle: "[DOWNSTREAM] don't test me cause i'm famous", + Organization: "mylittle", + Repository: "pony", + }, + data: testclient.Data{ + Repositories: []*v1alpha1.Repository{ + testnewrepo.NewRepo( + testnewrepo.RepoTestcreationOpts{ + Name: "test-good", + URL: targetURL, + InstallNamespace: targetNamespace, + }, + ), + }, + }, + }, + }, } for _, tt := range tests { @@ -680,7 +898,10 @@ func TestMatchPipelinerunAnnotationAndRepositories(t *testing.T) { if len(tt.args.fileChanged) > 0 { commitFiles := []*github.CommitFile{} for _, v := range tt.args.fileChanged { - commitFiles = append(commitFiles, &github.CommitFile{Filename: github.String(v)}) + commitFiles = append(commitFiles, &github.CommitFile{ + Filename: github.String(v.FileName), + Status: github.String(v.Status), + }) } if tt.args.runevent.TriggerTarget == "push" { mux.HandleFunc(fmt.Sprintf("/repos/%s/%s/commits/%s", @@ -724,7 +945,12 @@ func TestMatchPipelinerunAnnotationAndRepositories(t *testing.T) { pushFileChanges := []*gitlab.Diff{} if tt.args.runevent.TriggerTarget == "push" { for _, v := range tt.args.fileChanged { - pushFileChanges = append(pushFileChanges, &gitlab.Diff{NewPath: v}) + pushFileChanges = append(pushFileChanges, &gitlab.Diff{ + NewPath: v.FileName, + RenamedFile: v.RenamedFile, + DeletedFile: v.DeletedFile, + NewFile: v.NewFile, + }) } glMux.HandleFunc(fmt.Sprintf("/projects/0/repository/commits/%s/diff", tt.args.runevent.SHA), func(rw http.ResponseWriter, r *http.Request) { @@ -744,7 +970,12 @@ func TestMatchPipelinerunAnnotationAndRepositories(t *testing.T) { NewFile bool `json:"new_file"` RenamedFile bool `json:"renamed_file"` DeletedFile bool `json:"deleted_file"` - }{NewPath: v}) + }{ + NewPath: v.FileName, + RenamedFile: v.RenamedFile, + DeletedFile: v.DeletedFile, + NewFile: v.NewFile, + }) } url := fmt.Sprintf("/projects/0/merge_requests/%d/changes", tt.args.runevent.PullRequestNumber) glMux.HandleFunc(url, func(w http.ResponseWriter, r *http.Request) { diff --git a/pkg/matcher/cel.go b/pkg/matcher/cel.go index 15645e9f4..4e8df2ce5 100644 --- a/pkg/matcher/cel.go +++ b/pkg/matcher/cel.go @@ -3,6 +3,7 @@ package matcher import ( "context" "fmt" + "regexp" "strings" "github.com/gobwas/glob" @@ -10,10 +11,17 @@ import ( "github.com/google/cel-go/checker/decls" "github.com/google/cel-go/common/types" "github.com/google/cel-go/common/types/ref" + "github.com/openshift-pipelines/pipelines-as-code/pkg/formatting" "github.com/openshift-pipelines/pipelines-as-code/pkg/params/info" "github.com/openshift-pipelines/pipelines-as-code/pkg/provider" ) +const ( + // regex allows GetFiles function to execute only when a property requiring + // GetFiles is used in the cel expression + changedFilesTags = "all_changed_files|added_files|deleted_files|modified_files|renamed_files" +) + func celEvaluate(ctx context.Context, expr string, event *info.Event, vcx provider.Interface) (ref.Val, error) { eventTitle := event.PullRequestTitle if event.TriggerTarget == "push" { @@ -38,13 +46,28 @@ func celEvaluate(ctx context.Context, expr string, event *info.Event, vcx provid } } + r := regexp.MustCompile(changedFilesTags) + changedFiles := provider.ChangedFiles{} + var err error + if r.MatchString(expr) { + changedFiles, err = vcx.GetFiles(ctx, event) + if err != nil { + return nil, err + } + } + data := map[string]interface{}{ - "event": event.TriggerTarget, - "event_title": eventTitle, - "target_branch": event.BaseBranch, - "source_branch": event.HeadBranch, - "target_url": event.BaseURL, - "source_url": event.HeadURL, + "event": event.TriggerTarget, + "event_title": eventTitle, + "target_branch": event.BaseBranch, + "source_branch": event.HeadBranch, + "target_url": event.BaseURL, + "source_url": event.HeadURL, + "all_changed_files": strings.Join(formatting.UniqueStringArray(changedFiles.All), ","), + "added_files": strings.Join(formatting.UniqueStringArray(changedFiles.Added), ","), + "deleted_files": strings.Join(formatting.UniqueStringArray(changedFiles.Deleted), ","), + "modified_files": strings.Join(formatting.UniqueStringArray(changedFiles.Modified), ","), + "renamed_files": strings.Join(formatting.UniqueStringArray(changedFiles.Renamed), ","), } env, err := cel.NewEnv( @@ -55,7 +78,12 @@ func celEvaluate(ctx context.Context, expr string, event *info.Event, vcx provid decls.NewVar("target_branch", decls.String), decls.NewVar("source_branch", decls.String), decls.NewVar("target_url", decls.String), - decls.NewVar("source_url", decls.String))) + decls.NewVar("source_url", decls.String), + decls.NewVar("all_changed_files", decls.String), + decls.NewVar("added_files", decls.String), + decls.NewVar("deleted_files", decls.String), + decls.NewVar("modified_files", decls.String), + decls.NewVar("renamed_files", decls.String))) if err != nil { return nil, err } @@ -94,14 +122,14 @@ func (t celPac) ProgramOptions() []cel.ProgramOption { func (t celPac) pathChanged(vals ref.Val) ref.Val { var match types.Bool - fileList, err := t.vcx.GetFiles(t.ctx, t.event) + changedFiles, err := t.vcx.GetFiles(t.ctx, t.event) if err != nil { return types.Bool(false) } - for i := range fileList { + for i := range changedFiles.All { if v, ok := vals.Value().(string); ok { g := glob.MustCompile(v) - if g.Match(fileList[i]) { + if g.Match(changedFiles.All[i]) { return types.Bool(true) } } diff --git a/pkg/pipelineascode/pipelineascode.go b/pkg/pipelineascode/pipelineascode.go index 31ca10026..a20cbe085 100644 --- a/pkg/pipelineascode/pipelineascode.go +++ b/pkg/pipelineascode/pipelineascode.go @@ -66,7 +66,7 @@ func (p *PacRun) Run(ctx context.Context) error { } // set params for the console driver, only used for the custom console ones - cp := customparams.NewCustomParams(p.event, repo, p.run, p.k8int, p.eventEmitter) + cp := customparams.NewCustomParams(p.event, repo, p.run, p.k8int, p.eventEmitter, p.vcx) maptemplate, err := cp.GetParams(ctx) if err != nil { p.eventEmitter.EmitMessage(repo, zap.ErrorLevel, "ParamsError", diff --git a/pkg/pipelineascode/template.go b/pkg/pipelineascode/template.go index b5d81b115..1069f180a 100644 --- a/pkg/pipelineascode/template.go +++ b/pkg/pipelineascode/template.go @@ -13,7 +13,7 @@ import ( // makeTemplate will process all templates replacing the value from the event and from the // params as set on Repo CR func (p *PacRun) makeTemplate(ctx context.Context, repo *v1alpha1.Repository, template string) string { - cp := customparams.NewCustomParams(p.event, repo, p.run, p.k8int, p.eventEmitter) + cp := customparams.NewCustomParams(p.event, repo, p.run, p.k8int, p.eventEmitter, p.vcx) maptemplate, err := cp.GetParams(ctx) if err != nil { p.eventEmitter.EmitMessage(repo, zap.ErrorLevel, "ParamsError", diff --git a/pkg/provider/bitbucketcloud/bitbucket.go b/pkg/provider/bitbucketcloud/bitbucket.go index fd6c29d48..4f572de8a 100644 --- a/pkg/provider/bitbucketcloud/bitbucket.go +++ b/pkg/provider/bitbucketcloud/bitbucket.go @@ -267,8 +267,8 @@ func (v *Provider) getBlob(runevent *info.Event, ref, path string) (string, erro return blob.String(), nil } -func (v *Provider) GetFiles(_ context.Context, _ *info.Event) ([]string, error) { - return []string{}, nil +func (v *Provider) GetFiles(_ context.Context, _ *info.Event) (provider.ChangedFiles, error) { + return provider.ChangedFiles{}, nil } func (v *Provider) CreateToken(_ context.Context, _ []string, _ *params.Run, _ *info.Event) (string, error) { diff --git a/pkg/provider/bitbucketserver/bitbucketserver.go b/pkg/provider/bitbucketserver/bitbucketserver.go index ea22bb31e..3ab455cc2 100644 --- a/pkg/provider/bitbucketserver/bitbucketserver.go +++ b/pkg/provider/bitbucketserver/bitbucketserver.go @@ -263,8 +263,8 @@ func (v *Provider) GetConfig() *info.ProviderConfig { } } -func (v *Provider) GetFiles(_ context.Context, _ *info.Event) ([]string, error) { - return []string{}, nil +func (v *Provider) GetFiles(_ context.Context, _ *info.Event) (provider.ChangedFiles, error) { + return provider.ChangedFiles{}, nil } func (v *Provider) CreateToken(_ context.Context, _ []string, _ *params.Run, _ *info.Event) (string, error) { diff --git a/pkg/provider/gitea/gitea.go b/pkg/provider/gitea/gitea.go index c5189a764..deacb8603 100644 --- a/pkg/provider/gitea/gitea.go +++ b/pkg/provider/gitea/gitea.go @@ -304,9 +304,9 @@ func (v *Provider) GetCommitInfo(_ context.Context, runevent *info.Event) error return nil } -func (v *Provider) GetFiles(_ context.Context, _ *info.Event) ([]string, error) { +func (v *Provider) GetFiles(_ context.Context, _ *info.Event) (provider.ChangedFiles, error) { // TODO: figure out a way - return []string{}, fmt.Errorf("GetFiles is not supported on Gitea") + return provider.ChangedFiles{}, nil } func (v *Provider) CreateToken(_ context.Context, _ []string, _ *params.Run, _ *info.Event) (string, error) { diff --git a/pkg/provider/github/github.go b/pkg/provider/github/github.go index 4efe72d3a..96b7b922b 100644 --- a/pkg/provider/github/github.go +++ b/pkg/provider/github/github.go @@ -407,31 +407,58 @@ func (v *Provider) getPullRequest(ctx context.Context, runevent *info.Event) (*i } // GetFiles get a files from pull request -func (v *Provider) GetFiles(ctx context.Context, runevent *info.Event) ([]string, error) { +func (v *Provider) GetFiles(ctx context.Context, runevent *info.Event) (provider.ChangedFiles, error) { if runevent.TriggerTarget == "pull_request" { repoCommit, _, err := v.Client.PullRequests.ListFiles(ctx, runevent.Organization, runevent.Repository, runevent.PullRequestNumber, &github.ListOptions{}) if err != nil { - return []string{}, err + return provider.ChangedFiles{}, err } - result := []string{} + changedFiles := provider.ChangedFiles{} + for j := range repoCommit { - result = append(result, *repoCommit[j].Filename) + changedFiles.All = append(changedFiles.All, *repoCommit[j].Filename) + if *repoCommit[j].Status == "added" { + changedFiles.Added = append(changedFiles.Added, *repoCommit[j].Filename) + } + if *repoCommit[j].Status == "removed" { + changedFiles.Deleted = append(changedFiles.Deleted, *repoCommit[j].Filename) + } + if *repoCommit[j].Status == "modified" { + changedFiles.Modified = append(changedFiles.Modified, *repoCommit[j].Filename) + } + if *repoCommit[j].Status == "renamed" { + changedFiles.Renamed = append(changedFiles.Renamed, *repoCommit[j].Filename) + } } - return result, nil + return changedFiles, nil } if runevent.TriggerTarget == "push" { - result := []string{} + changedFiles := provider.ChangedFiles{} + rC, _, err := v.Client.Repositories.GetCommit(ctx, runevent.Organization, runevent.Repository, runevent.SHA, &github.ListOptions{}) if err != nil { - return []string{}, err + return provider.ChangedFiles{}, err } + for i := range rC.Files { - result = append(result, *rC.Files[i].Filename) + changedFiles.All = append(changedFiles.All, *rC.Files[i].Filename) + if *rC.Files[i].Status == "added" { + changedFiles.Added = append(changedFiles.Added, *rC.Files[i].Filename) + } + if *rC.Files[i].Status == "removed" { + changedFiles.Deleted = append(changedFiles.Deleted, *rC.Files[i].Filename) + } + if *rC.Files[i].Status == "modified" { + changedFiles.Modified = append(changedFiles.Modified, *rC.Files[i].Filename) + } + if *rC.Files[i].Status == "renamed" { + changedFiles.Renamed = append(changedFiles.Renamed, *rC.Files[i].Filename) + } } - return result, nil + return changedFiles, nil } - return []string{}, nil + return provider.ChangedFiles{}, nil } // getObject Get an object from a repository diff --git a/pkg/provider/github/github_test.go b/pkg/provider/github/github_test.go index bb5848879..a3fd7878d 100644 --- a/pkg/provider/github/github_test.go +++ b/pkg/provider/github/github_test.go @@ -568,10 +568,14 @@ func TestValidate(t *testing.T) { func TestGetFiles(t *testing.T) { tests := []struct { - name string - event *info.Event - commitFiles []*github.CommitFile - commit *github.RepositoryCommit + name string + event *info.Event + commitFiles []*github.CommitFile + commit *github.RepositoryCommit + wantAddedFilesCount int + wantDeletedFilesCount int + wantModifiedFilesCount int + wantRenamedFilesCount int }{ { name: "pull-request", @@ -583,11 +587,23 @@ func TestGetFiles(t *testing.T) { }, commitFiles: []*github.CommitFile{ { - Filename: ptr.String("first.yaml"), + Filename: ptr.String("modified.yaml"), + Status: ptr.String("modified"), + }, { + Filename: ptr.String("added.doc"), + Status: ptr.String("added"), }, { - Filename: ptr.String("second.doc"), + Filename: ptr.String("removed.yaml"), + Status: ptr.String("removed"), + }, { + Filename: ptr.String("renamed.doc"), + Status: ptr.String("renamed"), }, }, + wantAddedFilesCount: 1, + wantDeletedFilesCount: 1, + wantModifiedFilesCount: 1, + wantRenamedFilesCount: 1, }, { name: "push", @@ -600,29 +616,66 @@ func TestGetFiles(t *testing.T) { commit: &github.RepositoryCommit{ Files: []*github.CommitFile{ { - Filename: ptr.String("first.yaml"), + Filename: ptr.String("modified.yaml"), + Status: ptr.String("modified"), + }, { + Filename: ptr.String("added.doc"), + Status: ptr.String("added"), }, { - Filename: ptr.String("second.doc"), + Filename: ptr.String("removed.yaml"), + Status: ptr.String("removed"), + }, { + Filename: ptr.String("renamed.doc"), + Status: ptr.String("renamed"), }, }, }, + wantAddedFilesCount: 1, + wantDeletedFilesCount: 1, + wantModifiedFilesCount: 1, + wantRenamedFilesCount: 1, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { fakeclient, mux, _, teardown := ghtesthelper.SetupGH() defer teardown() - commitFiles := []*github.CommitFile{ + prCommitFiles := []*github.CommitFile{ + { + Filename: ptr.String("modified.yaml"), + Status: ptr.String("modified"), + }, { + Filename: ptr.String("added.doc"), + Status: ptr.String("added"), + }, { + Filename: ptr.String("removed.yaml"), + Status: ptr.String("removed"), + }, { + Filename: ptr.String("renamed.doc"), + Status: ptr.String("renamed"), + }, + } + + pushCommitFiles := []*github.CommitFile{ { - Filename: ptr.String("first.yaml"), + Filename: ptr.String("modified.yaml"), + Status: ptr.String("modified"), + }, { + Filename: ptr.String("added.doc"), + Status: ptr.String("added"), }, { - Filename: ptr.String("second.doc"), + Filename: ptr.String("removed.yaml"), + Status: ptr.String("removed"), + }, { + Filename: ptr.String("renamed.doc"), + Status: ptr.String("renamed"), }, } + if tt.event.TriggerTarget == "pull_request" { mux.HandleFunc(fmt.Sprintf("/repos/%s/%s/pulls/%d/files", tt.event.Organization, tt.event.Repository, tt.event.PullRequestNumber), func(rw http.ResponseWriter, r *http.Request) { - b, _ := json.Marshal(commitFiles) + b, _ := json.Marshal(prCommitFiles) fmt.Fprint(rw, string(b)) }) } @@ -630,7 +683,7 @@ func TestGetFiles(t *testing.T) { mux.HandleFunc(fmt.Sprintf("/repos/%s/%s/commits/%s", tt.event.Organization, tt.event.Repository, tt.event.SHA), func(rw http.ResponseWriter, r *http.Request) { c := &github.RepositoryCommit{ - Files: commitFiles, + Files: pushCommitFiles, } b, _ := json.Marshal(c) fmt.Fprint(rw, string(b)) @@ -639,16 +692,22 @@ func TestGetFiles(t *testing.T) { ctx, _ := rtesting.SetupFakeContext(t) provider := &Provider{Client: fakeclient} - fileData, err := provider.GetFiles(ctx, tt.event) + changedFiles, err := provider.GetFiles(ctx, tt.event) assert.NilError(t, err, nil) + + assert.Equal(t, tt.wantAddedFilesCount, len(changedFiles.Added)) + assert.Equal(t, tt.wantDeletedFilesCount, len(changedFiles.Deleted)) + assert.Equal(t, tt.wantModifiedFilesCount, len(changedFiles.Modified)) + assert.Equal(t, tt.wantRenamedFilesCount, len(changedFiles.Renamed)) + if tt.event.TriggerTarget == "pull_request" { - for i := range fileData { - assert.Equal(t, *tt.commitFiles[i].Filename, fileData[i]) + for i := range changedFiles.All { + assert.Equal(t, *tt.commitFiles[i].Filename, changedFiles.All[i]) } } if tt.event.TriggerTarget == "push" { - for i := range fileData { - assert.Equal(t, *tt.commit.Files[i].Filename, fileData[i]) + for i := range changedFiles.All { + assert.Equal(t, *tt.commit.Files[i].Filename, changedFiles.All[i]) } } }) diff --git a/pkg/provider/gitlab/gitlab.go b/pkg/provider/gitlab/gitlab.go index d43e3b259..9a4a66734 100644 --- a/pkg/provider/gitlab/gitlab.go +++ b/pkg/provider/gitlab/gitlab.go @@ -297,36 +297,59 @@ func (v *Provider) GetCommitInfo(_ context.Context, runevent *info.Event) error return nil } -func (v *Provider) GetFiles(_ context.Context, runevent *info.Event) ([]string, error) { +func (v *Provider) GetFiles(_ context.Context, runevent *info.Event) (provider.ChangedFiles, error) { if v.Client == nil { - return []string{}, fmt.Errorf("no gitlab client has been initiliazed, " + + return provider.ChangedFiles{}, fmt.Errorf("no gitlab client has been initialized, " + "exiting... (hint: did you forget setting a secret on your repo?)") } if runevent.TriggerTarget == "pull_request" { mrchanges, _, err := v.Client.MergeRequests.GetMergeRequestChanges(v.sourceProjectID, runevent.PullRequestNumber, &gitlab.GetMergeRequestChangesOptions{}) if err != nil { - return []string{}, err + return provider.ChangedFiles{}, err } - - result := []string{} + changedFiles := provider.ChangedFiles{} for _, change := range mrchanges.Changes { - result = append(result, change.NewPath) + changedFiles.All = append(changedFiles.All, change.NewPath) + if change.NewFile { + changedFiles.Added = append(changedFiles.Added, change.NewPath) + } + if change.DeletedFile { + changedFiles.Deleted = append(changedFiles.Deleted, change.NewPath) + } + if !change.RenamedFile && !change.DeletedFile && !change.NewFile { + changedFiles.Modified = append(changedFiles.Modified, change.NewPath) + } + if change.RenamedFile { + changedFiles.Renamed = append(changedFiles.Renamed, change.NewPath) + } } - return result, nil + return changedFiles, nil } if runevent.TriggerTarget == "push" { pushChanges, _, err := v.Client.Commits.GetCommitDiff(v.sourceProjectID, runevent.SHA, &gitlab.GetCommitDiffOptions{}) if err != nil { - return []string{}, err + return provider.ChangedFiles{}, err } - result := []string{} + changedFiles := provider.ChangedFiles{} for _, change := range pushChanges { - result = append(result, change.NewPath) + changedFiles.All = append(changedFiles.All, change.NewPath) + if change.NewFile { + changedFiles.Added = append(changedFiles.Added, change.NewPath) + } + if change.DeletedFile { + changedFiles.Deleted = append(changedFiles.Deleted, change.NewPath) + } + if !change.RenamedFile && !change.DeletedFile && !change.NewFile { + changedFiles.Modified = append(changedFiles.Modified, change.NewPath) + } + if change.RenamedFile { + changedFiles.Renamed = append(changedFiles.Renamed, change.NewPath) + } } - return result, nil + return changedFiles, nil } - return []string{}, nil + return provider.ChangedFiles{}, nil } func (v *Provider) CreateToken(_ context.Context, _ []string, _ *params.Run, _ *info.Event) (string, error) { diff --git a/pkg/provider/gitlab/gitlab_test.go b/pkg/provider/gitlab/gitlab_test.go index d7a921890..fca05c543 100644 --- a/pkg/provider/gitlab/gitlab_test.go +++ b/pkg/provider/gitlab/gitlab_test.go @@ -446,12 +446,15 @@ func TestValidate(t *testing.T) { } func TestGetFiles(t *testing.T) { - commitFiles := &gitlab.MergeRequest{} tests := []struct { - name string - event *info.Event - mrchanges *gitlab.MergeRequest - pushChanges []*gitlab.Diff + name string + event *info.Event + mrchanges *gitlab.MergeRequest + pushChanges []*gitlab.Diff + wantAddedFilesCount int + wantDeletedFilesCount int + wantModifiedFilesCount int + wantRenamedFilesCount int }{ { name: "pull-request", @@ -462,18 +465,37 @@ func TestGetFiles(t *testing.T) { PullRequestNumber: 10, }, mrchanges: &gitlab.MergeRequest{ - Changes: append(commitFiles.Changes, - struct { - OldPath string `json:"old_path"` - NewPath string `json:"new_path"` - AMode string `json:"a_mode"` - BMode string `json:"b_mode"` - Diff string `json:"diff"` - NewFile bool `json:"new_file"` - RenamedFile bool `json:"renamed_file"` - DeletedFile bool `json:"deleted_file"` - }{NewPath: "test.txt"}), + Changes: []struct { + OldPath string `json:"old_path"` + NewPath string `json:"new_path"` + AMode string `json:"a_mode"` + BMode string `json:"b_mode"` + Diff string `json:"diff"` + NewFile bool `json:"new_file"` + RenamedFile bool `json:"renamed_file"` + DeletedFile bool `json:"deleted_file"` + }{ + { + NewPath: "modified.yaml", + }, + { + NewPath: "added.doc", + NewFile: true, + }, + { + NewPath: "removed.yaml", + DeletedFile: true, + }, + { + NewPath: "renamed.doc", + RenamedFile: true, + }, + }, }, + wantAddedFilesCount: 1, + wantDeletedFilesCount: 1, + wantModifiedFilesCount: 1, + wantRenamedFilesCount: 1, }, { name: "push", @@ -485,11 +507,25 @@ func TestGetFiles(t *testing.T) { }, pushChanges: []*gitlab.Diff{ { - NewPath: "first.txt", - }, { - NewPath: "second.yaml", + NewPath: "modified.yaml", + }, + { + NewPath: "added.doc", + NewFile: true, + }, + { + NewPath: "removed.yaml", + DeletedFile: true, + }, + { + NewPath: "renamed.doc", + RenamedFile: true, }, }, + wantAddedFilesCount: 1, + wantDeletedFilesCount: 1, + wantModifiedFilesCount: 1, + wantRenamedFilesCount: 1, }, } for _, tt := range tests { @@ -498,18 +534,34 @@ func TestGetFiles(t *testing.T) { fakeclient, mux, teardown := thelp.Setup(t) defer teardown() mergeFileChanges := &gitlab.MergeRequest{ - Changes: append(commitFiles.Changes, - struct { - OldPath string `json:"old_path"` - NewPath string `json:"new_path"` - AMode string `json:"a_mode"` - BMode string `json:"b_mode"` - Diff string `json:"diff"` - NewFile bool `json:"new_file"` - RenamedFile bool `json:"renamed_file"` - DeletedFile bool `json:"deleted_file"` - }{NewPath: "test.txt"}), + Changes: []struct { + OldPath string `json:"old_path"` + NewPath string `json:"new_path"` + AMode string `json:"a_mode"` + BMode string `json:"b_mode"` + Diff string `json:"diff"` + NewFile bool `json:"new_file"` + RenamedFile bool `json:"renamed_file"` + DeletedFile bool `json:"deleted_file"` + }{ + { + NewPath: "modified.yaml", + }, + { + NewPath: "added.doc", + NewFile: true, + }, + { + NewPath: "removed.yaml", + DeletedFile: true, + }, + { + NewPath: "renamed.doc", + RenamedFile: true, + }, + }, } + if tt.event.TriggerTarget == "pull_request" { mux.HandleFunc(fmt.Sprintf("/projects/0/merge_requests/%d/changes", tt.event.PullRequestNumber), func(rw http.ResponseWriter, r *http.Request) { @@ -520,9 +572,19 @@ func TestGetFiles(t *testing.T) { } pushFileChanges := []*gitlab.Diff{ { - NewPath: "first.txt", - }, { - NewPath: "second.yaml", + NewPath: "modified.yaml", + }, + { + NewPath: "added.doc", + NewFile: true, + }, + { + NewPath: "removed.yaml", + DeletedFile: true, + }, + { + NewPath: "renamed.doc", + RenamedFile: true, }, } if tt.event.TriggerTarget == "push" { @@ -535,16 +597,22 @@ func TestGetFiles(t *testing.T) { } providerInfo := &Provider{Client: fakeclient} - fileData, err := providerInfo.GetFiles(ctx, tt.event) + changedFiles, err := providerInfo.GetFiles(ctx, tt.event) assert.NilError(t, err, nil) + + assert.Equal(t, tt.wantAddedFilesCount, len(changedFiles.Added)) + assert.Equal(t, tt.wantDeletedFilesCount, len(changedFiles.Deleted)) + assert.Equal(t, tt.wantModifiedFilesCount, len(changedFiles.Modified)) + assert.Equal(t, tt.wantRenamedFilesCount, len(changedFiles.Renamed)) + if tt.event.TriggerTarget == "pull_request" { - for i := range fileData { - assert.Equal(t, tt.mrchanges.Changes[i].NewPath, fileData[i]) + for i := range changedFiles.All { + assert.Equal(t, tt.mrchanges.Changes[i].NewPath, changedFiles.All[i]) } } if tt.event.TriggerTarget == "push" { - for i := range fileData { - assert.Equal(t, tt.pushChanges[i].NewPath, fileData[i]) + for i := range changedFiles.All { + assert.Equal(t, tt.pushChanges[i].NewPath, changedFiles.All[i]) } } }) diff --git a/pkg/provider/interface.go b/pkg/provider/interface.go index 89b23f301..1ef681480 100644 --- a/pkg/provider/interface.go +++ b/pkg/provider/interface.go @@ -35,9 +35,17 @@ type Interface interface { SetClient(context.Context, *params.Run, *info.Event) error GetCommitInfo(context.Context, *info.Event) error GetConfig() *info.ProviderConfig - GetFiles(context.Context, *info.Event) ([]string, error) + GetFiles(context.Context, *info.Event) (ChangedFiles, error) GetTaskURI(ctx context.Context, params *params.Run, event *info.Event, uri string) (bool, string, error) CreateToken(context.Context, []string, *params.Run, *info.Event) (string, error) } const DefaultProviderAPIUser = "git" + +type ChangedFiles struct { + All []string + Added []string + Deleted []string + Modified []string + Renamed []string +} diff --git a/pkg/reconciler/reconciler.go b/pkg/reconciler/reconciler.go index 82e9928c5..e819eb766 100644 --- a/pkg/reconciler/reconciler.go +++ b/pkg/reconciler/reconciler.go @@ -100,7 +100,7 @@ func (r *Reconciler) reportFinalStatus(ctx context.Context, logger *zap.SugaredL return nil, fmt.Errorf("reportFinalStatus: %w", err) } - cp := customparams.NewCustomParams(event, repo, r.run, r.kinteract, r.eventEmitter) + cp := customparams.NewCustomParams(event, repo, r.run, r.kinteract, r.eventEmitter, nil) maptemplate, err := cp.GetParams(ctx) if err != nil { r.eventEmitter.EmitMessage(repo, zap.ErrorLevel, "ParamsError", diff --git a/pkg/test/provider/testwebvcs.go b/pkg/test/provider/testwebvcs.go index 0ab28525a..ecfa20de7 100644 --- a/pkg/test/provider/testwebvcs.go +++ b/pkg/test/provider/testwebvcs.go @@ -21,6 +21,11 @@ type TestProviderImp struct { CreateStatusErorring bool FilesInsideRepo map[string]string WantProviderRemoteTask bool + WantAllChangedFiles []string + WantAddedFiles []string + WantDeletedFiles []string + WantModifiedFiles []string + WantRenamedFiles []string } func (v *TestProviderImp) SetLogger(_ *zap.SugaredLogger) { @@ -79,8 +84,14 @@ func (v *TestProviderImp) GetFileInsideRepo(_ context.Context, _ *info.Event, fi return "", fmt.Errorf("could not find %s in tests", file) } -func (v *TestProviderImp) GetFiles(_ context.Context, _ *info.Event) ([]string, error) { - return []string{}, nil +func (v *TestProviderImp) GetFiles(_ context.Context, _ *info.Event) (provider.ChangedFiles, error) { + return provider.ChangedFiles{ + All: v.WantAllChangedFiles, + Added: v.WantAddedFiles, + Deleted: v.WantDeletedFiles, + Modified: v.WantModifiedFiles, + Renamed: v.WantRenamedFiles, + }, nil } func (v *TestProviderImp) CreateToken(_ context.Context, _ []string, _ *params.Run, _ *info.Event) (string, error) {