From 12e24cd3fcfebd9d3b2619c7b1193508c1eb20d4 Mon Sep 17 00:00:00 2001 From: Easton Crupper <65553218+ecrupper@users.noreply.github.com> Date: Thu, 11 Apr 2024 14:32:26 -0400 Subject: [PATCH] refactor: use nested repository type in worker code (#571) * init commit * remove user from executor config * validate comment fix --- .github/workflows/validate.yml | 5 +- api/executor.go | 8 +- cmd/vela-worker/exec.go | 6 +- executor/context_test.go | 4 - executor/engine.go | 3 +- executor/executor_test.go | 60 ++++++++------ executor/linux/api.go | 3 +- executor/linux/build.go | 2 +- executor/linux/build_test.go | 40 +--------- executor/linux/driver_test.go | 1 - executor/linux/linux.go | 12 ++- executor/linux/linux_test.go | 62 ++++----------- executor/linux/opts.go | 20 +---- executor/linux/opts_test.go | 51 +----------- executor/linux/secret_test.go | 87 +++++++++++++++++---- executor/linux/service_test.go | 10 --- executor/linux/stage_test.go | 12 +-- executor/linux/step_test.go | 10 --- executor/local/api.go | 3 +- executor/local/build_test.go | 24 ++---- executor/local/local.go | 5 +- executor/local/local_test.go | 37 ++++----- executor/local/opts.go | 13 +-- executor/local/opts_test.go | 36 +-------- executor/local/service_test.go | 10 --- executor/local/stage_test.go | 10 +-- executor/local/step_test.go | 10 --- executor/setup.go | 9 +-- executor/setup_test.go | 19 +---- go.mod | 12 +-- go.sum | 16 ++-- internal/build/snapshot.go | 3 +- internal/build/snapshot_test.go | 41 +++++----- internal/build/upload.go | 3 +- internal/build/upload_test.go | 41 +++++----- internal/service/environment.go | 3 +- internal/service/environment_test.go | 11 +-- internal/service/snapshot.go | 3 +- internal/service/snapshot_test.go | 10 +-- internal/service/upload.go | 3 +- internal/service/upload_test.go | 10 +-- internal/step/environment.go | 3 +- internal/step/environment_test.go | 11 +-- internal/step/skip.go | 3 +- internal/step/skip_test.go | 10 +-- internal/step/snapshot.go | 5 +- internal/step/snapshot_test.go | 19 ++--- internal/step/upload.go | 3 +- internal/step/upload_test.go | 10 +-- mock/worker/repo.go | 4 +- router/middleware/executor/executor_test.go | 13 ++- 51 files changed, 311 insertions(+), 498 deletions(-) diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index bf701933..0163c991 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -32,7 +32,10 @@ jobs: # Check that go fmt ./... produces a zero diff; clean up any changes afterwards. go fmt ./... && git diff --exit-code; code=$?; git checkout -- .; (exit $code) # Check that go fix ./... produces a zero diff; clean up any changes afterwards. - go fix ./... && git diff --exit-code; code=$?; git checkout -- .; (exit $code) + # + # Renable this after https://github.com/golang/go/commit/7fd62ba821b1044e8e4077df052b0a1232672d57 + # has been released. + # go fix ./... && git diff --exit-code; code=$?; git checkout -- .; (exit $code) - name: validate spec run: | diff --git a/api/executor.go b/api/executor.go index 3bde86b0..50ca3aeb 100644 --- a/api/executor.go +++ b/api/executor.go @@ -8,8 +8,8 @@ import ( "github.com/gin-gonic/gin" + api "github.com/go-vela/server/api/types" "github.com/go-vela/types" - "github.com/go-vela/types/library" "github.com/go-vela/worker/executor" exec "github.com/go-vela/worker/router/middleware/executor" ) @@ -45,7 +45,7 @@ func GetExecutor(c *gin.Context) { var err error e := exec.Retrieve(c) - executor := &library.Executor{} + executor := &api.Executor{} // TODO: Add this information from the context or helpers on executor // tmp.SetHost(executor.GetHost()) @@ -129,11 +129,11 @@ func GetExecutors(c *gin.Context) { return } - executors := []*library.Executor{} + executors := []*api.Executor{} for id, executor := range e { // create a temporary executor to append results to response - tmp := &library.Executor{} + tmp := &api.Executor{} // TODO: Add this information from the context or helpers on executor // tmp.SetHost(executor.GetHost()) diff --git a/cmd/vela-worker/exec.go b/cmd/vela-worker/exec.go index 584d8069..a88f26a2 100644 --- a/cmd/vela-worker/exec.go +++ b/cmd/vela-worker/exec.go @@ -12,6 +12,7 @@ import ( "github.com/sirupsen/logrus" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/queue/models" "github.com/go-vela/types" "github.com/go-vela/types/constants" "github.com/go-vela/types/pipeline" @@ -99,7 +100,7 @@ func (w *Worker) exec(index int, config *api.Worker) error { "host": w.Config.API.Address.Hostname(), "repo": item.Repo.GetFullName(), "runtime": w.Config.Runtime.Driver, - "user": item.User.GetName(), + "user": item.Repo.GetOwner().GetName(), "version": v.Semantic(), }) @@ -125,7 +126,7 @@ func (w *Worker) exec(index int, config *api.Worker) error { } // handle stale item queued before a Vela upgrade or downgrade. - if item.ItemVersion != types.ItemVersion { + if item.ItemVersion != models.ItemVersion { // If the ItemVersion is older or newer than what we expect, then it might // not be safe to process the build. Fail the build and loop to the next item. // TODO: Ask the server to re-compile and requeue the build instead of failing it. @@ -181,7 +182,6 @@ func (w *Worker) exec(index int, config *api.Worker) error { Build: item.Build, Pipeline: pipeline.Sanitize(w.Config.Runtime.Driver), Repo: item.Repo, - User: item.User, Version: v.Semantic(), }) diff --git a/executor/context_test.go b/executor/context_test.go index c98c4169..e2286c70 100644 --- a/executor/context_test.go +++ b/executor/context_test.go @@ -40,7 +40,6 @@ func TestExecutor_FromContext(t *testing.T) { linux.WithPipeline(_pipeline), linux.WithRepo(_repo), linux.WithRuntime(_runtime), - linux.WithUser(_user), linux.WithVelaClient(_client), ) if err != nil { @@ -105,7 +104,6 @@ func TestExecutor_FromGinContext(t *testing.T) { linux.WithPipeline(_pipeline), linux.WithRepo(_repo), linux.WithRuntime(_runtime), - linux.WithUser(_user), linux.WithVelaClient(_client), ) if err != nil { @@ -176,7 +174,6 @@ func TestExecutor_WithContext(t *testing.T) { linux.WithPipeline(_pipeline), linux.WithRepo(_repo), linux.WithRuntime(_runtime), - linux.WithUser(_user), linux.WithVelaClient(_client), ) if err != nil { @@ -215,7 +212,6 @@ func TestExecutor_WithGinContext(t *testing.T) { linux.WithPipeline(_pipeline), linux.WithRepo(_repo), linux.WithRuntime(_runtime), - linux.WithUser(_user), linux.WithVelaClient(_client), ) if err != nil { diff --git a/executor/engine.go b/executor/engine.go index f81b72d0..d427b4a0 100644 --- a/executor/engine.go +++ b/executor/engine.go @@ -6,6 +6,7 @@ import ( "context" "sync" + api "github.com/go-vela/server/api/types" "github.com/go-vela/types/library" "github.com/go-vela/types/pipeline" ) @@ -30,7 +31,7 @@ type Engine interface { GetPipeline() (*pipeline.Build, error) // GetRepo defines a function for the API // that gets the current repo in execution. - GetRepo() (*library.Repo, error) + GetRepo() (*api.Repo, error) // CancelBuild defines a function for the API // that Cancels the current build in execution. CancelBuild() (*library.Build, error) diff --git a/executor/executor_test.go b/executor/executor_test.go index a26b079c..4ead7490 100644 --- a/executor/executor_test.go +++ b/executor/executor_test.go @@ -10,6 +10,8 @@ import ( "github.com/gin-gonic/gin" "github.com/google/go-cmp/cmp" + api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/api/types/actions" "github.com/go-vela/server/mock/server" "github.com/go-vela/worker/executor/linux" @@ -47,7 +49,6 @@ func TestExecutor_New(t *testing.T) { linux.WithPipeline(_pipeline), linux.WithRepo(_repo), linux.WithRuntime(_runtime), - linux.WithUser(_user), linux.WithVelaClient(_client), linux.WithVersion("v1.0.0"), ) @@ -61,7 +62,6 @@ func TestExecutor_New(t *testing.T) { local.WithPipeline(_pipeline), local.WithRepo(_repo), local.WithRuntime(_runtime), - local.WithUser(_user), local.WithVelaClient(_client), local.WithVersion("v1.0.0"), ) @@ -87,7 +87,6 @@ func TestExecutor_New(t *testing.T) { Pipeline: _pipeline, Repo: _repo, Runtime: _runtime, - User: _user, Version: "v1.0.0", }, want: nil, @@ -104,7 +103,6 @@ func TestExecutor_New(t *testing.T) { Pipeline: _pipeline, Repo: _repo, Runtime: _runtime, - User: _user, Version: "v1.0.0", }, want: _linux, @@ -120,7 +118,6 @@ func TestExecutor_New(t *testing.T) { Pipeline: _pipeline, Repo: _repo, Runtime: _runtime, - User: _user, Version: "v1.0.0", }, want: _local, @@ -136,7 +133,6 @@ func TestExecutor_New(t *testing.T) { Pipeline: _pipeline, Repo: _repo, Runtime: _runtime, - User: _user, Version: "v1.0.0", }, want: nil, @@ -152,7 +148,6 @@ func TestExecutor_New(t *testing.T) { Pipeline: _pipeline, Repo: _repo, Runtime: _runtime, - User: _user, Version: "v1.0.0", }, want: nil, @@ -168,7 +163,6 @@ func TestExecutor_New(t *testing.T) { Pipeline: _pipeline, Repo: _repo, Runtime: _runtime, - User: _user, Version: "v1.0.0", }, want: nil, @@ -267,7 +261,39 @@ var ( }, } - _repo = &library.Repo{ + _user = &library.User{ + ID: vela.Int64(1), + Name: vela.String("octocat"), + Token: vela.String("superSecretToken"), + Hash: vela.String("MzM4N2MzMDAtNmY4Mi00OTA5LWFhZDAtNWIzMTlkNTJkODMy"), + Favorites: vela.Strings([]string{"github/octocat"}), + Active: vela.Bool(true), + Admin: vela.Bool(false), + } + + _allowEvents = &api.Events{ + Push: &actions.Push{ + Branch: vela.Bool(true), + Tag: vela.Bool(true), + }, + PullRequest: &actions.Pull{ + Opened: vela.Bool(true), + Synchronize: vela.Bool(true), + Edited: vela.Bool(true), + Reopened: vela.Bool(true), + Labeled: vela.Bool(true), + Unlabeled: vela.Bool(true), + }, + Comment: &actions.Comment{ + Created: vela.Bool(true), + Edited: vela.Bool(true), + }, + Deployment: &actions.Deploy{ + Created: vela.Bool(true), + }, + } + + _repo = &api.Repo{ ID: vela.Int64(1), Org: vela.String("github"), Name: vela.String("octocat"), @@ -280,19 +306,7 @@ var ( Private: vela.Bool(false), Trusted: vela.Bool(false), Active: vela.Bool(true), - AllowPull: vela.Bool(false), - AllowPush: vela.Bool(true), - AllowDeploy: vela.Bool(false), - AllowTag: vela.Bool(false), - } - - _user = &library.User{ - ID: vela.Int64(1), - Name: vela.String("octocat"), - Token: vela.String("superSecretToken"), - Hash: vela.String("MzM4N2MzMDAtNmY4Mi00OTA5LWFhZDAtNWIzMTlkNTJkODMy"), - Favorites: vela.Strings([]string{"github/octocat"}), - Active: vela.Bool(true), - Admin: vela.Bool(false), + AllowEvents: _allowEvents, + Owner: _user, } ) diff --git a/executor/linux/api.go b/executor/linux/api.go index 5df1c399..a4aa33fa 100644 --- a/executor/linux/api.go +++ b/executor/linux/api.go @@ -7,6 +7,7 @@ import ( "fmt" "time" + api "github.com/go-vela/server/api/types" "github.com/go-vela/types/constants" "github.com/go-vela/types/library" "github.com/go-vela/types/pipeline" @@ -35,7 +36,7 @@ func (c *client) GetPipeline() (*pipeline.Build, error) { } // GetRepo gets the current repo in execution. -func (c *client) GetRepo() (*library.Repo, error) { +func (c *client) GetRepo() (*api.Repo, error) { // check if the repo resource is available if c.repo == nil { return nil, fmt.Errorf("repo resource not found") diff --git a/executor/linux/build.go b/executor/linux/build.go index eca06238..f6adee4c 100644 --- a/executor/linux/build.go +++ b/executor/linux/build.go @@ -553,7 +553,7 @@ func (c *client) ExecBuild(ctx context.Context) error { // load any lazy secrets into the container environment c.err = loadLazySecrets(c, _step) - if err != nil { + if c.err != nil { return fmt.Errorf("unable to plan step: %w", c.err) } diff --git a/executor/linux/build_test.go b/executor/linux/build_test.go index 449dd91d..3b1125e2 100644 --- a/executor/linux/build_test.go +++ b/executor/linux/build_test.go @@ -14,6 +14,7 @@ import ( "github.com/gin-gonic/gin" "github.com/go-vela/sdk-go/vela" + api "github.com/go-vela/server/api/types" "github.com/go-vela/server/compiler/native" "github.com/go-vela/server/mock/server" "github.com/go-vela/types/constants" @@ -36,8 +37,6 @@ func TestLinux_CreateBuild(t *testing.T) { _build := testBuild() _repo := testRepo() - _user := testUser() - _metadata := testMetadata() testLogger := logrus.New() loggerHook := logrusTest.NewLocal(testLogger) @@ -151,8 +150,6 @@ func TestLinux_CreateBuild(t *testing.T) { Duplicate(). WithBuild(_build). WithRepo(_repo). - WithMetadata(_metadata). - WithUser(_user). Compile(test.pipeline) if err != nil { t.Errorf("unable to compile %s pipeline %s: %v", test.name, test.pipeline, err) @@ -183,7 +180,7 @@ func TestLinux_CreateBuild(t *testing.T) { WithPipeline(_pipeline), WithRepo(_repo), WithRuntime(_runtime), - WithUser(_user), + WithVelaClient(_client), ) if err != nil { @@ -236,8 +233,7 @@ func TestLinux_AssembleBuild_EnforceTrustedRepos(t *testing.T) { // test repo is not trusted by default _untrustedRepo := testRepo() - _user := testUser() - _metadata := testMetadata() + // to be matched with the image used by testdata/build/steps/basic.yml _privilegedImagesStepsPipeline := []string{"alpine"} // to be matched with the image used by testdata/build/services/basic.yml @@ -262,7 +258,7 @@ func TestLinux_AssembleBuild_EnforceTrustedRepos(t *testing.T) { failure bool runtime string build *library.Build - repo *library.Repo + repo *api.Repo pipeline string privilegedImages []string enforceTrustedRepos bool @@ -996,8 +992,6 @@ func TestLinux_AssembleBuild_EnforceTrustedRepos(t *testing.T) { Duplicate(). WithBuild(_build). WithRepo(test.repo). - WithMetadata(_metadata). - WithUser(_user). Compile(test.pipeline) if err != nil { t.Errorf("unable to compile pipeline %s: %v", test.pipeline, err) @@ -1018,7 +1012,6 @@ func TestLinux_AssembleBuild_EnforceTrustedRepos(t *testing.T) { WithPipeline(_pipeline), WithRepo(test.repo), WithRuntime(_runtime), - WithUser(_user), WithVelaClient(_client), WithPrivilegedImages(test.privilegedImages), WithEnforceTrustedRepos(test.enforceTrustedRepos), @@ -1061,8 +1054,6 @@ func TestLinux_PlanBuild(t *testing.T) { _build := testBuild() _repo := testRepo() - _user := testUser() - _metadata := testMetadata() testLogger := logrus.New() loggerHook := logrusTest.NewLocal(testLogger) @@ -1165,8 +1156,6 @@ func TestLinux_PlanBuild(t *testing.T) { Duplicate(). WithBuild(_build). WithRepo(_repo). - WithMetadata(_metadata). - WithUser(_user). Compile(test.pipeline) if err != nil { t.Errorf("unable to compile %s pipeline %s: %v", test.name, test.pipeline, err) @@ -1197,7 +1186,6 @@ func TestLinux_PlanBuild(t *testing.T) { WithPipeline(_pipeline), WithRepo(_repo), WithRuntime(_runtime), - WithUser(_user), WithVelaClient(_client), ) if err != nil { @@ -1250,8 +1238,6 @@ func TestLinux_AssembleBuild(t *testing.T) { _build := testBuild() _repo := testRepo() - _user := testUser() - _metadata := testMetadata() testLogger := logrus.New() loggerHook := logrusTest.NewLocal(testLogger) @@ -1455,8 +1441,6 @@ func TestLinux_AssembleBuild(t *testing.T) { Duplicate(). WithBuild(_build). WithRepo(_repo). - WithMetadata(_metadata). - WithUser(_user). Compile(test.pipeline) if err != nil { t.Errorf("unable to compile %s pipeline %s: %v", test.name, test.pipeline, err) @@ -1486,7 +1470,6 @@ func TestLinux_AssembleBuild(t *testing.T) { WithPipeline(_pipeline), WithRepo(_repo), WithRuntime(_runtime), - WithUser(_user), WithVelaClient(_client), withStreamRequests(streamRequests), ) @@ -1564,8 +1547,6 @@ func TestLinux_ExecBuild(t *testing.T) { _build := testBuild() _repo := testRepo() - _user := testUser() - _metadata := testMetadata() testLogger := logrus.New() loggerHook := logrusTest.NewLocal(testLogger) @@ -1696,8 +1677,6 @@ func TestLinux_ExecBuild(t *testing.T) { Duplicate(). WithBuild(_build). WithRepo(_repo). - WithMetadata(_metadata). - WithUser(_user). Compile(test.pipeline) if err != nil { t.Errorf("unable to compile %s pipeline %s: %v", test.name, test.pipeline, err) @@ -1734,7 +1713,6 @@ func TestLinux_ExecBuild(t *testing.T) { WithPipeline(_pipeline), WithRepo(_repo), WithRuntime(_runtime), - WithUser(_user), WithVelaClient(_client), withStreamRequests(streamRequests), ) @@ -1860,8 +1838,6 @@ func TestLinux_StreamBuild(t *testing.T) { _build := testBuild() _repo := testRepo() - _user := testUser() - _metadata := testMetadata() testLogger := logrus.New() loggerHook := logrusTest.NewLocal(testLogger) @@ -2345,8 +2321,6 @@ func TestLinux_StreamBuild(t *testing.T) { Duplicate(). WithBuild(_build). WithRepo(_repo). - WithMetadata(_metadata). - WithUser(_user). Compile(test.pipeline) if err != nil { t.Errorf("unable to compile %s pipeline %s: %v", test.name, test.pipeline, err) @@ -2378,7 +2352,6 @@ func TestLinux_StreamBuild(t *testing.T) { WithRepo(_repo), WithRuntime(_runtime), WithLogStreamingTimeout(1*time.Second), - WithUser(_user), WithVelaClient(_client), withStreamRequests(streamRequests), ) @@ -2480,8 +2453,6 @@ func TestLinux_DestroyBuild(t *testing.T) { _build := testBuild() _repo := testRepo() - _user := testUser() - _metadata := testMetadata() testLogger := logrus.New() loggerHook := logrusTest.NewLocal(testLogger) @@ -2626,8 +2597,6 @@ func TestLinux_DestroyBuild(t *testing.T) { Duplicate(). WithBuild(_build). WithRepo(_repo). - WithMetadata(_metadata). - WithUser(_user). Compile(test.pipeline) if err != nil { t.Errorf("unable to compile %s pipeline %s: %v", test.name, test.pipeline, err) @@ -2658,7 +2627,6 @@ func TestLinux_DestroyBuild(t *testing.T) { WithPipeline(_pipeline), WithRepo(_repo), WithRuntime(_runtime), - WithUser(_user), WithVelaClient(_client), ) if err != nil { diff --git a/executor/linux/driver_test.go b/executor/linux/driver_test.go index 9f12d86b..4f9d1fca 100644 --- a/executor/linux/driver_test.go +++ b/executor/linux/driver_test.go @@ -38,7 +38,6 @@ func TestLinux_Driver(t *testing.T) { WithPipeline(testSteps(constants.DriverDocker)), WithRepo(testRepo()), WithRuntime(_runtime), - WithUser(testUser()), WithVelaClient(_client), ) if err != nil { diff --git a/executor/linux/linux.go b/executor/linux/linux.go index dac4ede2..4cfa71e6 100644 --- a/executor/linux/linux.go +++ b/executor/linux/linux.go @@ -3,11 +3,13 @@ package linux import ( + "errors" "reflect" "sync" "time" "github.com/go-vela/sdk-go/vela" + api "github.com/go-vela/server/api/types" "github.com/go-vela/types/library" "github.com/go-vela/types/pipeline" "github.com/go-vela/worker/internal/message" @@ -38,7 +40,7 @@ type ( enforceTrustedRepos bool build *library.Build pipeline *pipeline.Build - repo *library.Repo + repo *api.Repo secrets sync.Map services sync.Map serviceLogs sync.Map @@ -47,12 +49,10 @@ type ( streamRequests chan message.StreamRequest - user *library.User - err error + err error } svc struct { - //nolint:structcheck // false positive client *client } ) @@ -83,9 +83,7 @@ func Equal(a, b *client) bool { reflect.DeepEqual(&a.serviceLogs, &b.serviceLogs) && reflect.DeepEqual(&a.steps, &b.steps) && reflect.DeepEqual(&a.stepLogs, &b.stepLogs) && - // do not compare streamRequests channel - reflect.DeepEqual(a.user, b.user) && - reflect.DeepEqual(a.err, b.err) + errors.Is(a.err, b.err) } // New returns an Executor implementation that integrates with a Linux instance. diff --git a/executor/linux/linux_test.go b/executor/linux/linux_test.go index 7fa65d59..bbf4f82d 100644 --- a/executor/linux/linux_test.go +++ b/executor/linux/linux_test.go @@ -12,8 +12,8 @@ import ( "github.com/gin-gonic/gin" "github.com/go-vela/sdk-go/vela" + api "github.com/go-vela/server/api/types" "github.com/go-vela/server/mock/server" - "github.com/go-vela/types" "github.com/go-vela/types/constants" "github.com/go-vela/types/library" "github.com/go-vela/types/pipeline" @@ -42,7 +42,6 @@ func TestEqual(t *testing.T) { WithPipeline(testSteps(constants.DriverDocker)), WithRepo(testRepo()), WithRuntime(_runtime), - WithUser(testUser()), WithVelaClient(_client), ) if err != nil { @@ -55,7 +54,6 @@ func TestEqual(t *testing.T) { WithPipeline(testSteps(constants.DriverDocker)), WithRepo(testRepo()), WithRuntime(_runtime), - WithUser(testUser()), WithVelaClient(_client), ) if err != nil { @@ -151,7 +149,6 @@ func TestLinux_New(t *testing.T) { WithPipeline(testSteps(constants.DriverDocker)), WithRepo(testRepo()), WithRuntime(_runtime), - WithUser(testUser()), WithVelaClient(_client), ) @@ -203,24 +200,21 @@ func testBuild() *library.Build { // testRepo is a test helper function to create a Repo // type with all fields set to a fake value. -func testRepo() *library.Repo { - return &library.Repo{ - ID: vela.Int64(1), - Org: vela.String("github"), - Name: vela.String("octocat"), - FullName: vela.String("github/octocat"), - Link: vela.String("https://github.com/github/octocat"), - Clone: vela.String("https://github.com/github/octocat.git"), - Branch: vela.String("main"), - Timeout: vela.Int64(60), - Visibility: vela.String("public"), - Private: vela.Bool(false), - Trusted: vela.Bool(false), - Active: vela.Bool(true), - AllowPull: vela.Bool(false), - AllowPush: vela.Bool(true), - AllowDeploy: vela.Bool(false), - AllowTag: vela.Bool(false), +func testRepo() *api.Repo { + return &api.Repo{ + ID: vela.Int64(1), + Org: vela.String("github"), + Name: vela.String("octocat"), + FullName: vela.String("github/octocat"), + Link: vela.String("https://github.com/github/octocat"), + Clone: vela.String("https://github.com/github/octocat.git"), + Branch: vela.String("main"), + Timeout: vela.Int64(60), + Visibility: vela.String("public"), + Private: vela.Bool(false), + Trusted: vela.Bool(false), + Active: vela.Bool(true), + Owner: testUser(), } } @@ -238,30 +232,6 @@ func testUser() *library.User { } } -// testMetadata is a test helper function to create a metadata -// type with all fields set to a fake value. -func testMetadata() *types.Metadata { - return &types.Metadata{ - Database: &types.Database{ - Driver: "foo", - Host: "foo", - }, - Queue: &types.Queue{ - Channel: "foo", - Driver: "foo", - Host: "foo", - }, - Source: &types.Source{ - Driver: "foo", - Host: "foo", - }, - Vela: &types.Vela{ - Address: "foo", - WebAddress: "foo", - }, - } -} - // testSteps is a test helper function to create a steps // pipeline with fake steps. func testSteps(runtime string) *pipeline.Build { diff --git a/executor/linux/opts.go b/executor/linux/opts.go index 0695a70e..be9902e4 100644 --- a/executor/linux/opts.go +++ b/executor/linux/opts.go @@ -7,6 +7,7 @@ import ( "time" "github.com/go-vela/sdk-go/vela" + api "github.com/go-vela/server/api/types" "github.com/go-vela/types/library" "github.com/go-vela/types/pipeline" "github.com/go-vela/worker/internal/message" @@ -133,7 +134,7 @@ func WithPipeline(p *pipeline.Build) Opt { } // WithRepo sets the library repo in the executor client for Linux. -func WithRepo(r *library.Repo) Opt { +func WithRepo(r *api.Repo) Opt { return func(c *client) error { c.Logger.Trace("configuring repository in linux executor client") @@ -166,23 +167,6 @@ func WithRuntime(r runtime.Engine) Opt { } } -// WithUser sets the library user in the executor client for Linux. -func WithUser(u *library.User) Opt { - return func(c *client) error { - c.Logger.Trace("configuring user in linux executor client") - - // check if the user provided is empty - if u == nil { - return fmt.Errorf("empty user provided") - } - - // set the user in the client - c.user = u - - return nil - } -} - // WithVelaClient sets the Vela client in the executor client for Linux. func WithVelaClient(cli *vela.Client) Opt { return func(c *client) error { diff --git a/executor/linux/opts_test.go b/executor/linux/opts_test.go index 7eb8f606..6aec5d80 100644 --- a/executor/linux/opts_test.go +++ b/executor/linux/opts_test.go @@ -10,6 +10,7 @@ import ( "github.com/gin-gonic/gin" "github.com/go-vela/sdk-go/vela" + api "github.com/go-vela/server/api/types" "github.com/go-vela/server/mock/server" "github.com/go-vela/types/constants" "github.com/go-vela/types/library" @@ -384,7 +385,7 @@ func TestLinux_Opt_WithRepo(t *testing.T) { tests := []struct { name string failure bool - repo *library.Repo + repo *api.Repo }{ { name: "repo", @@ -485,54 +486,6 @@ func TestLinux_Opt_WithRuntime(t *testing.T) { } } -func TestLinux_Opt_WithUser(t *testing.T) { - // setup types - _user := testUser() - - // setup tests - tests := []struct { - name string - failure bool - user *library.User - }{ - { - name: "user", - failure: false, - user: _user, - }, - { - name: "nil user", - failure: true, - user: nil, - }, - } - - // run tests - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - _engine, err := New( - WithUser(test.user), - ) - - if test.failure { - if err == nil { - t.Errorf("WithUser should have returned err") - } - - return // continue to next test - } - - if err != nil { - t.Errorf("WithUser returned err: %v", err) - } - - if !reflect.DeepEqual(_engine.user, _user) { - t.Errorf("WithUser is %v, want %v", _engine.user, _user) - } - }) - } -} - func TestLinux_Opt_WithVelaClient(t *testing.T) { // setup types gin.SetMode(gin.TestMode) diff --git a/executor/linux/secret_test.go b/executor/linux/secret_test.go index cac475df..5b458415 100644 --- a/executor/linux/secret_test.go +++ b/executor/linux/secret_test.go @@ -29,7 +29,6 @@ func TestLinux_Secret_create(t *testing.T) { // setup types _build := testBuild() _repo := testRepo() - _user := testUser() _steps := testSteps(constants.DriverDocker) gin.SetMode(gin.TestMode) @@ -124,7 +123,6 @@ func TestLinux_Secret_create(t *testing.T) { WithPipeline(_steps), WithRepo(_repo), WithRuntime(test.runtime), - WithUser(_user), WithVelaClient(_client), ) if err != nil { @@ -152,7 +150,6 @@ func TestLinux_Secret_delete(t *testing.T) { // setup types _build := testBuild() _repo := testRepo() - _user := testUser() _dockerSteps := testSteps(constants.DriverDocker) _kubernetesSteps := testSteps(constants.DriverKubernetes) @@ -327,7 +324,6 @@ func TestLinux_Secret_delete(t *testing.T) { WithPipeline(test.steps), WithRepo(_repo), WithRuntime(test.runtime), - WithUser(_user), WithVelaClient(_client), ) if err != nil { @@ -373,7 +369,6 @@ func TestLinux_Secret_exec(t *testing.T) { _build := testBuild() _repo := testRepo() _user := testUser() - _metadata := testMetadata() gin.SetMode(gin.TestMode) @@ -430,7 +425,6 @@ func TestLinux_Secret_exec(t *testing.T) { WithBuild(_build). WithRepo(_repo). WithUser(_user). - WithMetadata(_metadata). Compile(file) if err != nil { t.Errorf("unable to compile pipeline %s: %v", test.pipeline, err) @@ -460,7 +454,6 @@ func TestLinux_Secret_exec(t *testing.T) { WithPipeline(p), WithRepo(_repo), WithRuntime(_runtime), - WithUser(_user), WithVelaClient(_client), withStreamRequests(streamRequests), ) @@ -504,7 +497,6 @@ func TestLinux_Secret_pull(t *testing.T) { // setup types _build := testBuild() _repo := testRepo() - _user := testUser() gin.SetMode(gin.TestMode) @@ -776,7 +768,6 @@ func TestLinux_Secret_pull(t *testing.T) { WithPipeline(testSteps(constants.DriverDocker)), WithRepo(_repo), WithRuntime(test.runtime), - WithUser(_user), WithVelaClient(_client), ) if err != nil { @@ -804,7 +795,6 @@ func TestLinux_Secret_stream(t *testing.T) { // setup types _build := testBuild() _repo := testRepo() - _user := testUser() _steps := testSteps(constants.DriverDocker) gin.SetMode(gin.TestMode) @@ -904,7 +894,6 @@ func TestLinux_Secret_stream(t *testing.T) { WithPipeline(_steps), WithRepo(_repo), WithRuntime(test.runtime), - WithUser(_user), WithVelaClient(_client), ) if err != nil { @@ -1059,7 +1048,17 @@ func TestLinux_Secret_injectSecret(t *testing.T) { Environment: map[string]string{"VELA_BUILD_EVENT": "push"}, Secrets: pipeline.StepSecretSlice{{Source: "FOO", Target: "FOO"}}, }, - msec: map[string]*library.Secret{"FOO": {Name: &v, Value: &v, Events: &[]string{"deployment"}}}, + msec: map[string]*library.Secret{ + "FOO": { + Name: &v, + Value: &v, + AllowEvents: &library.Events{ + Deployment: &actions.Deploy{ + Created: &tBool, + }, + }, + }, + }, want: &pipeline.Container{ Image: "alpine:latest", Environment: map[string]string{"VELA_BUILD_EVENT": "push"}, @@ -1096,7 +1095,17 @@ func TestLinux_Secret_injectSecret(t *testing.T) { Environment: map[string]string{"VELA_BUILD_EVENT": "pull_request"}, Secrets: pipeline.StepSecretSlice{{Source: "FOO", Target: "FOO"}}, }, - msec: map[string]*library.Secret{"FOO": {Name: &v, Value: &v, Events: &[]string{"deployment"}}}, + msec: map[string]*library.Secret{ + "FOO": { + Name: &v, + Value: &v, + AllowEvents: &library.Events{ + Deployment: &actions.Deploy{ + Created: &tBool, + }, + }, + }, + }, want: &pipeline.Container{ Image: "alpine:latest", Environment: map[string]string{"VELA_BUILD_EVENT": "pull_request"}, @@ -1133,7 +1142,17 @@ func TestLinux_Secret_injectSecret(t *testing.T) { Environment: map[string]string{"VELA_BUILD_EVENT": "tag"}, Secrets: pipeline.StepSecretSlice{{Source: "FOO", Target: "FOO"}}, }, - msec: map[string]*library.Secret{"FOO": {Name: &v, Value: &v, Events: &[]string{"deployment"}}}, + msec: map[string]*library.Secret{ + "FOO": { + Name: &v, + Value: &v, + AllowEvents: &library.Events{ + Deployment: &actions.Deploy{ + Created: &tBool, + }, + }, + }, + }, want: &pipeline.Container{ Image: "alpine:latest", Environment: map[string]string{"VELA_BUILD_EVENT": "tag"}, @@ -1170,7 +1189,17 @@ func TestLinux_Secret_injectSecret(t *testing.T) { Environment: map[string]string{"VELA_BUILD_EVENT": "deployment"}, Secrets: pipeline.StepSecretSlice{{Source: "FOO", Target: "FOO"}}, }, - msec: map[string]*library.Secret{"FOO": {Name: &v, Value: &v, Events: &[]string{"tag"}}}, + msec: map[string]*library.Secret{ + "FOO": { + Name: &v, + Value: &v, + AllowEvents: &library.Events{ + Push: &actions.Push{ + Tag: &tBool, + }, + }, + }, + }, want: &pipeline.Container{ Image: "alpine:latest", Environment: map[string]string{"VELA_BUILD_EVENT": "deployment"}, @@ -1185,7 +1214,18 @@ func TestLinux_Secret_injectSecret(t *testing.T) { Environment: map[string]string{"VELA_BUILD_EVENT": "push"}, Secrets: pipeline.StepSecretSlice{{Source: "FOO", Target: "FOO"}}, }, - msec: map[string]*library.Secret{"FOO": {Name: &v, Value: &v, Events: &[]string{"push"}, Images: &[]string{"centos"}}}, + msec: map[string]*library.Secret{ + "FOO": { + Name: &v, + Value: &v, + AllowEvents: &library.Events{ + Push: &actions.Push{ + Branch: &tBool, + }, + }, + Images: &[]string{"centos"}, + }, + }, want: &pipeline.Container{ Image: "alpine:latest", Environment: map[string]string{"VELA_BUILD_EVENT": "push"}, @@ -1198,7 +1238,20 @@ func TestLinux_Secret_injectSecret(t *testing.T) { Environment: map[string]string{"VELA_BUILD_EVENT": "push"}, Secrets: pipeline.StepSecretSlice{{Source: "FOO", Target: "FOO"}}, }, - msec: map[string]*library.Secret{"FOO": {Name: &v, Value: &v, Events: &[]string{"pull_request"}, Images: &[]string{"centos"}}}, + msec: map[string]*library.Secret{ + "FOO": { + Name: &v, + Value: &v, + AllowEvents: &library.Events{ + PullRequest: &actions.Pull{ + Opened: &tBool, + Synchronize: &tBool, + Reopened: &tBool, + }, + }, + Images: &[]string{"centos"}, + }, + }, want: &pipeline.Container{ Image: "centos:latest", Environment: map[string]string{"VELA_BUILD_EVENT": "push"}, diff --git a/executor/linux/service_test.go b/executor/linux/service_test.go index eed5b02c..ec667658 100644 --- a/executor/linux/service_test.go +++ b/executor/linux/service_test.go @@ -22,7 +22,6 @@ func TestLinux_CreateService(t *testing.T) { // setup types _build := testBuild() _repo := testRepo() - _user := testUser() gin.SetMode(gin.TestMode) @@ -136,7 +135,6 @@ func TestLinux_CreateService(t *testing.T) { WithPipeline(new(pipeline.Build)), WithRepo(_repo), WithRuntime(test.runtime), - WithUser(_user), WithVelaClient(_client), ) if err != nil { @@ -164,7 +162,6 @@ func TestLinux_PlanService(t *testing.T) { // setup types _build := testBuild() _repo := testRepo() - _user := testUser() gin.SetMode(gin.TestMode) @@ -278,7 +275,6 @@ func TestLinux_PlanService(t *testing.T) { WithPipeline(new(pipeline.Build)), WithRepo(_repo), WithRuntime(test.runtime), - WithUser(_user), WithVelaClient(_client), ) if err != nil { @@ -306,7 +302,6 @@ func TestLinux_ExecService(t *testing.T) { // setup types _build := testBuild() _repo := testRepo() - _user := testUser() gin.SetMode(gin.TestMode) @@ -423,7 +418,6 @@ func TestLinux_ExecService(t *testing.T) { WithPipeline(new(pipeline.Build)), WithRepo(_repo), WithRuntime(test.runtime), - WithUser(_user), WithVelaClient(_client), withStreamRequests(streamRequests), ) @@ -457,7 +451,6 @@ func TestLinux_StreamService(t *testing.T) { // setup types _build := testBuild() _repo := testRepo() - _user := testUser() gin.SetMode(gin.TestMode) @@ -571,7 +564,6 @@ func TestLinux_StreamService(t *testing.T) { WithPipeline(new(pipeline.Build)), WithRepo(_repo), WithRuntime(test.runtime), - WithUser(_user), WithVelaClient(_client), ) if err != nil { @@ -604,7 +596,6 @@ func TestLinux_DestroyService(t *testing.T) { // setup types _build := testBuild() _repo := testRepo() - _user := testUser() gin.SetMode(gin.TestMode) @@ -706,7 +697,6 @@ func TestLinux_DestroyService(t *testing.T) { WithPipeline(new(pipeline.Build)), WithRepo(_repo), WithRuntime(test.runtime), - WithUser(_user), WithVelaClient(_client), ) if err != nil { diff --git a/executor/linux/stage_test.go b/executor/linux/stage_test.go index f79e2155..cc904261 100644 --- a/executor/linux/stage_test.go +++ b/executor/linux/stage_test.go @@ -27,8 +27,6 @@ func TestLinux_CreateStage(t *testing.T) { _file := "testdata/build/stages/basic.yml" _build := testBuild() _repo := testRepo() - _user := testUser() - _metadata := testMetadata() set := flag.NewFlagSet("test", 0) set.String("clone-image", "target/vela-git:latest", "doc") @@ -38,8 +36,7 @@ func TestLinux_CreateStage(t *testing.T) { Duplicate(). WithBuild(_build). WithRepo(_repo). - WithMetadata(_metadata). - WithUser(_user). + WithUser(_repo.GetOwner()). Compile(_file) if err != nil { t.Errorf("unable to compile pipeline %s: %v", _file, err) @@ -169,7 +166,6 @@ func TestLinux_CreateStage(t *testing.T) { WithPipeline(_pipeline), WithRepo(_repo), WithRuntime(test.runtime), - WithUser(_user), WithVelaClient(_client), ) if err != nil { @@ -205,7 +201,6 @@ func TestLinux_PlanStage(t *testing.T) { // setup types _build := testBuild() _repo := testRepo() - _user := testUser() gin.SetMode(gin.TestMode) @@ -396,7 +391,6 @@ func TestLinux_PlanStage(t *testing.T) { WithPipeline(new(pipeline.Build)), WithRepo(_repo), WithRuntime(test.runtime), - WithUser(_user), WithVelaClient(_client), ) if err != nil { @@ -424,7 +418,6 @@ func TestLinux_ExecStage(t *testing.T) { // setup types _build := testBuild() _repo := testRepo() - _user := testUser() gin.SetMode(gin.TestMode) @@ -587,7 +580,6 @@ func TestLinux_ExecStage(t *testing.T) { WithPipeline(new(pipeline.Build)), WithRepo(_repo), WithRuntime(test.runtime), - WithUser(_user), WithVelaClient(_client), withStreamRequests(streamRequests), ) @@ -616,7 +608,6 @@ func TestLinux_DestroyStage(t *testing.T) { // setup types _build := testBuild() _repo := testRepo() - _user := testUser() gin.SetMode(gin.TestMode) @@ -692,7 +683,6 @@ func TestLinux_DestroyStage(t *testing.T) { WithPipeline(new(pipeline.Build)), WithRepo(_repo), WithRuntime(test.runtime), - WithUser(_user), WithVelaClient(_client), ) if err != nil { diff --git a/executor/linux/step_test.go b/executor/linux/step_test.go index 061a82a1..b8e1eb3b 100644 --- a/executor/linux/step_test.go +++ b/executor/linux/step_test.go @@ -24,7 +24,6 @@ func TestLinux_CreateStep(t *testing.T) { // setup types _build := testBuild() _repo := testRepo() - _user := testUser() gin.SetMode(gin.TestMode) @@ -158,7 +157,6 @@ func TestLinux_CreateStep(t *testing.T) { WithPipeline(new(pipeline.Build)), WithRepo(_repo), WithRuntime(test.runtime), - WithUser(_user), WithVelaClient(_client), ) if err != nil { @@ -186,7 +184,6 @@ func TestLinux_PlanStep(t *testing.T) { // setup types _build := testBuild() _repo := testRepo() - _user := testUser() gin.SetMode(gin.TestMode) @@ -292,7 +289,6 @@ func TestLinux_PlanStep(t *testing.T) { WithPipeline(new(pipeline.Build)), WithRepo(_repo), WithRuntime(test.runtime), - WithUser(_user), WithVelaClient(_client), ) if err != nil { @@ -320,7 +316,6 @@ func TestLinux_ExecStep(t *testing.T) { // setup types _build := testBuild() _repo := testRepo() - _user := testUser() gin.SetMode(gin.TestMode) @@ -489,7 +484,6 @@ func TestLinux_ExecStep(t *testing.T) { WithPipeline(new(pipeline.Build)), WithRepo(_repo), WithRuntime(test.runtime), - WithUser(_user), WithVelaClient(_client), withStreamRequests(streamRequests), ) @@ -523,7 +517,6 @@ func TestLinux_StreamStep(t *testing.T) { // setup types _build := testBuild() _repo := testRepo() - _user := testUser() _logs := new(library.Log) // fill log with bytes @@ -671,7 +664,6 @@ func TestLinux_StreamStep(t *testing.T) { WithMaxLogSize(10), WithRepo(_repo), WithRuntime(test.runtime), - WithUser(_user), WithVelaClient(_client), ) if err != nil { @@ -704,7 +696,6 @@ func TestLinux_DestroyStep(t *testing.T) { // setup types _build := testBuild() _repo := testRepo() - _user := testUser() gin.SetMode(gin.TestMode) @@ -826,7 +817,6 @@ func TestLinux_DestroyStep(t *testing.T) { WithPipeline(new(pipeline.Build)), WithRepo(_repo), WithRuntime(test.runtime), - WithUser(_user), WithVelaClient(_client), ) if err != nil { diff --git a/executor/local/api.go b/executor/local/api.go index b90b7e6a..6312f711 100644 --- a/executor/local/api.go +++ b/executor/local/api.go @@ -7,6 +7,7 @@ import ( "fmt" "time" + api "github.com/go-vela/server/api/types" "github.com/go-vela/types/constants" "github.com/go-vela/types/library" "github.com/go-vela/types/pipeline" @@ -35,7 +36,7 @@ func (c *client) GetPipeline() (*pipeline.Build, error) { } // GetRepo gets the current repo in execution. -func (c *client) GetRepo() (*library.Repo, error) { +func (c *client) GetRepo() (*api.Repo, error) { // check if the repo resource is available if c.repo == nil { return nil, fmt.Errorf("repo resource not found") diff --git a/executor/local/build_test.go b/executor/local/build_test.go index 099f99dc..64d62778 100644 --- a/executor/local/build_test.go +++ b/executor/local/build_test.go @@ -22,7 +22,6 @@ func TestLocal_CreateBuild(t *testing.T) { _build := testBuild() _repo := testRepo() - _user := testUser() _runtime, err := docker.NewMock() if err != nil { @@ -59,7 +58,7 @@ func TestLocal_CreateBuild(t *testing.T) { WithBuild(_build). WithRepo(_repo). WithLocal(true). - WithUser(_user). + WithUser(_repo.GetOwner()). Compile(test.pipeline) if err != nil { t.Errorf("unable to compile pipeline %s: %v", test.pipeline, err) @@ -70,7 +69,6 @@ func TestLocal_CreateBuild(t *testing.T) { WithPipeline(_pipeline), WithRepo(_repo), WithRuntime(_runtime), - WithUser(_user), ) if err != nil { t.Errorf("unable to create executor engine: %v", err) @@ -99,7 +97,6 @@ func TestLocal_PlanBuild(t *testing.T) { _build := testBuild() _repo := testRepo() - _user := testUser() _runtime, err := docker.NewMock() if err != nil { @@ -136,7 +133,7 @@ func TestLocal_PlanBuild(t *testing.T) { WithBuild(_build). WithRepo(_repo). WithLocal(true). - WithUser(_user). + WithUser(_repo.GetOwner()). Compile(test.pipeline) if err != nil { t.Errorf("unable to compile pipeline %s: %v", test.pipeline, err) @@ -147,7 +144,6 @@ func TestLocal_PlanBuild(t *testing.T) { WithPipeline(_pipeline), WithRepo(_repo), WithRuntime(_runtime), - WithUser(_user), ) if err != nil { t.Errorf("unable to create executor engine: %v", err) @@ -182,7 +178,6 @@ func TestLocal_AssembleBuild(t *testing.T) { _build := testBuild() _repo := testRepo() - _user := testUser() _runtime, err := docker.NewMock() if err != nil { @@ -252,7 +247,7 @@ func TestLocal_AssembleBuild(t *testing.T) { WithBuild(_build). WithRepo(_repo). WithLocal(true). - WithUser(_user). + WithUser(_repo.GetOwner()). Compile(test.pipeline) if err != nil { t.Errorf("unable to compile pipeline %s: %v", test.pipeline, err) @@ -263,7 +258,6 @@ func TestLocal_AssembleBuild(t *testing.T) { WithPipeline(_pipeline), WithRepo(_repo), WithRuntime(_runtime), - WithUser(_user), withStreamRequests(streamRequests), ) if err != nil { @@ -299,7 +293,6 @@ func TestLocal_ExecBuild(t *testing.T) { _build := testBuild() _repo := testRepo() - _user := testUser() _runtime, err := docker.NewMock() if err != nil { @@ -354,7 +347,7 @@ func TestLocal_ExecBuild(t *testing.T) { WithBuild(_build). WithRepo(_repo). WithLocal(true). - WithUser(_user). + WithUser(_repo.GetOwner()). Compile(test.pipeline) if err != nil { t.Errorf("unable to compile pipeline %s: %v", test.pipeline, err) @@ -365,7 +358,6 @@ func TestLocal_ExecBuild(t *testing.T) { WithPipeline(_pipeline), WithRepo(_repo), WithRuntime(_runtime), - WithUser(_user), withStreamRequests(streamRequests), ) if err != nil { @@ -401,7 +393,6 @@ func TestLocal_StreamBuild(t *testing.T) { _build := testBuild() _repo := testRepo() - _user := testUser() _runtime, err := docker.NewMock() if err != nil { @@ -548,7 +539,7 @@ func TestLocal_StreamBuild(t *testing.T) { WithBuild(_build). WithRepo(_repo). WithLocal(true). - WithUser(_user). + WithUser(_repo.GetOwner()). Compile(test.pipeline) if err != nil { t.Errorf("unable to compile pipeline %s: %v", test.pipeline, err) @@ -559,7 +550,6 @@ func TestLocal_StreamBuild(t *testing.T) { WithPipeline(_pipeline), WithRepo(_repo), WithRuntime(_runtime), - WithUser(_user), withStreamRequests(streamRequests), ) if err != nil { @@ -615,7 +605,6 @@ func TestLocal_DestroyBuild(t *testing.T) { _build := testBuild() _repo := testRepo() - _user := testUser() _runtime, err := docker.NewMock() if err != nil { @@ -667,7 +656,7 @@ func TestLocal_DestroyBuild(t *testing.T) { WithBuild(_build). WithRepo(_repo). WithLocal(true). - WithUser(_user). + WithUser(_repo.GetOwner()). Compile(test.pipeline) if err != nil { t.Errorf("unable to compile pipeline %s: %v", test.pipeline, err) @@ -678,7 +667,6 @@ func TestLocal_DestroyBuild(t *testing.T) { WithPipeline(_pipeline), WithRepo(_repo), WithRuntime(_runtime), - WithUser(_user), ) if err != nil { t.Errorf("unable to create executor engine: %v", err) diff --git a/executor/local/local.go b/executor/local/local.go index bcadbdc4..930f1ebd 100644 --- a/executor/local/local.go +++ b/executor/local/local.go @@ -8,6 +8,7 @@ import ( "sync" "github.com/go-vela/sdk-go/vela" + api "github.com/go-vela/server/api/types" "github.com/go-vela/types/library" "github.com/go-vela/types/pipeline" "github.com/go-vela/worker/internal/message" @@ -26,10 +27,9 @@ type ( init *pipeline.Container build *library.Build pipeline *pipeline.Build - repo *library.Repo + repo *api.Repo services sync.Map steps sync.Map - user *library.User err error streamRequests chan message.StreamRequest @@ -67,7 +67,6 @@ func Equal(a, b *client) bool { reflect.DeepEqual(a.repo, b.repo) && reflect.DeepEqual(&a.services, &b.services) && reflect.DeepEqual(&a.steps, &b.steps) && - reflect.DeepEqual(a.user, b.user) && reflect.DeepEqual(a.err, b.err) } diff --git a/executor/local/local_test.go b/executor/local/local_test.go index f240e312..ab6adb8e 100644 --- a/executor/local/local_test.go +++ b/executor/local/local_test.go @@ -8,6 +8,7 @@ import ( "github.com/gin-gonic/gin" + api "github.com/go-vela/server/api/types" "github.com/go-vela/server/mock/server" "github.com/go-vela/worker/runtime/docker" @@ -40,7 +41,6 @@ func TestEqual(t *testing.T) { WithPipeline(testSteps()), WithRepo(testRepo()), WithRuntime(_runtime), - WithUser(testUser()), WithVelaClient(_client), ) if err != nil { @@ -53,7 +53,6 @@ func TestEqual(t *testing.T) { WithPipeline(testSteps()), WithRepo(testRepo()), WithRuntime(_runtime), - WithUser(testUser()), WithVelaClient(_client), ) if err != nil { @@ -149,7 +148,6 @@ func TestLocal_New(t *testing.T) { WithPipeline(test.pipeline), WithRepo(testRepo()), WithRuntime(_runtime), - WithUser(testUser()), WithVelaClient(_client), ) @@ -201,24 +199,21 @@ func testBuild() *library.Build { // testRepo is a test helper function to create a Repo // type with all fields set to a fake value. -func testRepo() *library.Repo { - return &library.Repo{ - ID: vela.Int64(1), - Org: vela.String("github"), - Name: vela.String("octocat"), - FullName: vela.String("github/octocat"), - Link: vela.String("https://github.com/github/octocat"), - Clone: vela.String("https://github.com/github/octocat.git"), - Branch: vela.String("main"), - Timeout: vela.Int64(60), - Visibility: vela.String("public"), - Private: vela.Bool(false), - Trusted: vela.Bool(false), - Active: vela.Bool(true), - AllowPull: vela.Bool(false), - AllowPush: vela.Bool(true), - AllowDeploy: vela.Bool(false), - AllowTag: vela.Bool(false), +func testRepo() *api.Repo { + return &api.Repo{ + ID: vela.Int64(1), + Org: vela.String("github"), + Name: vela.String("octocat"), + FullName: vela.String("github/octocat"), + Link: vela.String("https://github.com/github/octocat"), + Clone: vela.String("https://github.com/github/octocat.git"), + Branch: vela.String("main"), + Timeout: vela.Int64(60), + Visibility: vela.String("public"), + Private: vela.Bool(false), + Trusted: vela.Bool(false), + Active: vela.Bool(true), + Owner: testUser(), } } diff --git a/executor/local/opts.go b/executor/local/opts.go index 8e13510d..5bef81df 100644 --- a/executor/local/opts.go +++ b/executor/local/opts.go @@ -6,6 +6,7 @@ import ( "fmt" "os" + api "github.com/go-vela/server/api/types" "github.com/go-vela/worker/internal/message" "github.com/go-vela/worker/runtime" @@ -60,7 +61,7 @@ func WithPipeline(p *pipeline.Build) Opt { } // WithRepo sets the library repo in the executor client for Local. -func WithRepo(r *library.Repo) Opt { +func WithRepo(r *api.Repo) Opt { return func(c *client) error { // set the repo in the client c.repo = r @@ -84,16 +85,6 @@ func WithRuntime(r runtime.Engine) Opt { } } -// WithUser sets the library user in the executor client for Local. -func WithUser(u *library.User) Opt { - return func(c *client) error { - // set the user in the client - c.user = u - - return nil - } -} - // WithVelaClient sets the Vela client in the executor client for Local. func WithVelaClient(cli *vela.Client) Opt { return func(c *client) error { diff --git a/executor/local/opts_test.go b/executor/local/opts_test.go index 64080c4e..746f265f 100644 --- a/executor/local/opts_test.go +++ b/executor/local/opts_test.go @@ -9,6 +9,7 @@ import ( "github.com/gin-gonic/gin" + api "github.com/go-vela/server/api/types" "github.com/go-vela/server/mock/server" "github.com/go-vela/worker/runtime" @@ -144,7 +145,7 @@ func TestLocal_Opt_WithRepo(t *testing.T) { // setup tests tests := []struct { name string - repo *library.Repo + repo *api.Repo }{ { name: "repo", @@ -221,39 +222,6 @@ func TestLocal_Opt_WithRuntime(t *testing.T) { } } -func TestLocal_Opt_WithUser(t *testing.T) { - // setup types - _user := testUser() - - // setup tests - tests := []struct { - name string - user *library.User - }{ - { - name: "user", - user: _user, - }, - } - - // run tests - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - _engine, err := New( - WithUser(test.user), - ) - - if err != nil { - t.Errorf("WithUser returned err: %v", err) - } - - if !reflect.DeepEqual(_engine.user, _user) { - t.Errorf("WithUser is %v, want %v", _engine.user, _user) - } - }) - } -} - func TestLocal_Opt_WithVelaClient(t *testing.T) { // setup types gin.SetMode(gin.TestMode) diff --git a/executor/local/service_test.go b/executor/local/service_test.go index 0c762690..0c857796 100644 --- a/executor/local/service_test.go +++ b/executor/local/service_test.go @@ -17,7 +17,6 @@ func TestLocal_CreateService(t *testing.T) { // setup types _build := testBuild() _repo := testRepo() - _user := testUser() _runtime, err := docker.NewMock() if err != nil { @@ -75,7 +74,6 @@ func TestLocal_CreateService(t *testing.T) { WithPipeline(new(pipeline.Build)), WithRepo(_repo), WithRuntime(_runtime), - WithUser(_user), ) if err != nil { t.Errorf("unable to create executor engine: %v", err) @@ -102,7 +100,6 @@ func TestLocal_PlanService(t *testing.T) { // setup types _build := testBuild() _repo := testRepo() - _user := testUser() _runtime, err := docker.NewMock() if err != nil { @@ -145,7 +142,6 @@ func TestLocal_PlanService(t *testing.T) { WithPipeline(new(pipeline.Build)), WithRepo(_repo), WithRuntime(_runtime), - WithUser(_user), ) if err != nil { t.Errorf("unable to create executor engine: %v", err) @@ -172,7 +168,6 @@ func TestLocal_ExecService(t *testing.T) { // setup types _build := testBuild() _repo := testRepo() - _user := testUser() _runtime, err := docker.NewMock() if err != nil { @@ -233,7 +228,6 @@ func TestLocal_ExecService(t *testing.T) { WithPipeline(new(pipeline.Build)), WithRepo(_repo), WithRuntime(_runtime), - WithUser(_user), withStreamRequests(streamRequests), ) if err != nil { @@ -265,7 +259,6 @@ func TestLocal_StreamService(t *testing.T) { // setup types _build := testBuild() _repo := testRepo() - _user := testUser() _runtime, err := docker.NewMock() if err != nil { @@ -308,7 +301,6 @@ func TestLocal_StreamService(t *testing.T) { WithPipeline(new(pipeline.Build)), WithRepo(_repo), WithRuntime(_runtime), - WithUser(_user), ) if err != nil { t.Errorf("unable to create executor engine: %v", err) @@ -335,7 +327,6 @@ func TestLocal_DestroyService(t *testing.T) { // setup types _build := testBuild() _repo := testRepo() - _user := testUser() _runtime, err := docker.NewMock() if err != nil { @@ -373,7 +364,6 @@ func TestLocal_DestroyService(t *testing.T) { WithPipeline(new(pipeline.Build)), WithRepo(_repo), WithRuntime(_runtime), - WithUser(_user), ) if err != nil { t.Errorf("unable to create executor engine: %v", err) diff --git a/executor/local/stage_test.go b/executor/local/stage_test.go index 9df4a425..05806880 100644 --- a/executor/local/stage_test.go +++ b/executor/local/stage_test.go @@ -24,7 +24,6 @@ func TestLocal_CreateStage(t *testing.T) { _file := "testdata/build/stages/basic.yml" _build := testBuild() _repo := testRepo() - _user := testUser() compiler, _ := native.New(cli.NewContext(nil, flag.NewFlagSet("test", 0), nil)) @@ -33,7 +32,7 @@ func TestLocal_CreateStage(t *testing.T) { WithBuild(_build). WithRepo(_repo). WithLocal(true). - WithUser(_user). + WithUser(_repo.GetOwner()). Compile(_file) if err != nil { t.Errorf("unable to compile pipeline %s: %v", _file, err) @@ -96,7 +95,6 @@ func TestLocal_CreateStage(t *testing.T) { WithPipeline(_pipeline), WithRepo(_repo), WithRuntime(_runtime), - WithUser(_user), ) if err != nil { t.Errorf("unable to create executor engine: %v", err) @@ -129,7 +127,6 @@ func TestLocal_PlanStage(t *testing.T) { // setup types _build := testBuild() _repo := testRepo() - _user := testUser() _runtime, err := docker.NewMock() if err != nil { @@ -226,7 +223,6 @@ func TestLocal_PlanStage(t *testing.T) { WithPipeline(new(pipeline.Build)), WithRepo(_repo), WithRuntime(_runtime), - WithUser(_user), ) if err != nil { t.Errorf("unable to create executor engine: %v", err) @@ -253,7 +249,6 @@ func TestLocal_ExecStage(t *testing.T) { // setup types _build := testBuild() _repo := testRepo() - _user := testUser() _runtime, err := docker.NewMock() if err != nil { @@ -318,7 +313,6 @@ func TestLocal_ExecStage(t *testing.T) { WithPipeline(new(pipeline.Build)), WithRepo(_repo), WithRuntime(_runtime), - WithUser(_user), withStreamRequests(streamRequests), ) if err != nil { @@ -346,7 +340,6 @@ func TestLocal_DestroyStage(t *testing.T) { // setup types _build := testBuild() _repo := testRepo() - _user := testUser() _runtime, err := docker.NewMock() if err != nil { @@ -387,7 +380,6 @@ func TestLocal_DestroyStage(t *testing.T) { WithPipeline(new(pipeline.Build)), WithRepo(_repo), WithRuntime(_runtime), - WithUser(_user), ) if err != nil { t.Errorf("unable to create executor engine: %v", err) diff --git a/executor/local/step_test.go b/executor/local/step_test.go index 339d068d..7db448e0 100644 --- a/executor/local/step_test.go +++ b/executor/local/step_test.go @@ -17,7 +17,6 @@ func TestLocal_CreateStep(t *testing.T) { // setup types _build := testBuild() _repo := testRepo() - _user := testUser() _runtime, err := docker.NewMock() if err != nil { @@ -84,7 +83,6 @@ func TestLocal_CreateStep(t *testing.T) { WithPipeline(new(pipeline.Build)), WithRepo(_repo), WithRuntime(_runtime), - WithUser(_user), ) if err != nil { t.Errorf("unable to create executor engine: %v", err) @@ -111,7 +109,6 @@ func TestLocal_PlanStep(t *testing.T) { // setup types _build := testBuild() _repo := testRepo() - _user := testUser() _runtime, err := docker.NewMock() if err != nil { @@ -152,7 +149,6 @@ func TestLocal_PlanStep(t *testing.T) { WithPipeline(new(pipeline.Build)), WithRepo(_repo), WithRuntime(_runtime), - WithUser(_user), ) if err != nil { t.Errorf("unable to create executor engine: %v", err) @@ -179,7 +175,6 @@ func TestLocal_ExecStep(t *testing.T) { // setup types _build := testBuild() _repo := testRepo() - _user := testUser() _runtime, err := docker.NewMock() if err != nil { @@ -263,7 +258,6 @@ func TestLocal_ExecStep(t *testing.T) { WithPipeline(new(pipeline.Build)), WithRepo(_repo), WithRuntime(_runtime), - WithUser(_user), withStreamRequests(streamRequests), ) if err != nil { @@ -295,7 +289,6 @@ func TestLocal_StreamStep(t *testing.T) { // setup types _build := testBuild() _repo := testRepo() - _user := testUser() _runtime, err := docker.NewMock() if err != nil { @@ -362,7 +355,6 @@ func TestLocal_StreamStep(t *testing.T) { WithPipeline(new(pipeline.Build)), WithRepo(_repo), WithRuntime(_runtime), - WithUser(_user), ) if err != nil { t.Errorf("unable to create executor engine: %v", err) @@ -389,7 +381,6 @@ func TestLocal_DestroyStep(t *testing.T) { // setup types _build := testBuild() _repo := testRepo() - _user := testUser() _runtime, err := docker.NewMock() if err != nil { @@ -438,7 +429,6 @@ func TestLocal_DestroyStep(t *testing.T) { WithPipeline(new(pipeline.Build)), WithRepo(_repo), WithRuntime(_runtime), - WithUser(_user), ) if err != nil { t.Errorf("unable to create executor engine: %v", err) diff --git a/executor/setup.go b/executor/setup.go index 55031039..57751531 100644 --- a/executor/setup.go +++ b/executor/setup.go @@ -14,6 +14,7 @@ import ( "github.com/go-vela/worker/runtime" + api "github.com/go-vela/server/api/types" "github.com/go-vela/types/constants" "github.com/go-vela/types/library" "github.com/go-vela/types/pipeline" @@ -60,9 +61,7 @@ type Setup struct { // resource for storing pipeline information in Vela Pipeline *pipeline.Build // resource for storing repo information in Vela - Repo *library.Repo - // resource for storing user information in Vela - User *library.User + Repo *api.Repo } // Darwin creates and returns a Vela engine capable of @@ -91,7 +90,6 @@ func (s *Setup) Linux() (Engine, error) { linux.WithPipeline(s.Pipeline), linux.WithRepo(s.Repo), linux.WithRuntime(s.Runtime), - linux.WithUser(s.User), linux.WithVelaClient(s.Client), linux.WithVersion(s.Version), linux.WithLogger(s.Logger), @@ -112,7 +110,6 @@ func (s *Setup) Local() (Engine, error) { local.WithPipeline(s.Pipeline), local.WithRepo(s.Repo), local.WithRuntime(s.Runtime), - local.WithUser(s.User), local.WithVelaClient(s.Client), local.WithVersion(s.Version), local.WithMockStdout(s.Mock), @@ -170,7 +167,7 @@ func (s *Setup) Validate() error { } // check if a Vela user was provided - if s.User == nil { + if s.Repo.Owner == nil { return fmt.Errorf("no Vela user provided in setup") } diff --git a/executor/setup_test.go b/executor/setup_test.go index bdde2c58..0fd742c0 100644 --- a/executor/setup_test.go +++ b/executor/setup_test.go @@ -45,7 +45,6 @@ func TestExecutor_Setup_Darwin(t *testing.T) { Pipeline: _pipeline, Repo: _repo, Runtime: _runtime, - User: _user, } got, err := _setup.Darwin() @@ -82,7 +81,6 @@ func TestExecutor_Setup_Linux(t *testing.T) { linux.WithPipeline(_pipeline), linux.WithRepo(_repo), linux.WithRuntime(_runtime), - linux.WithUser(_user), linux.WithVelaClient(_client), linux.WithVersion("v1.0.0"), ) @@ -99,7 +97,6 @@ func TestExecutor_Setup_Linux(t *testing.T) { Pipeline: _pipeline, Repo: _repo, Runtime: _runtime, - User: _user, Version: "v1.0.0", } @@ -138,7 +135,6 @@ func TestExecutor_Setup_Local(t *testing.T) { local.WithPipeline(_pipeline), local.WithRepo(_repo), local.WithRuntime(_runtime), - local.WithUser(_user), local.WithVelaClient(_client), local.WithVersion("v1.0.0"), ) @@ -154,7 +150,6 @@ func TestExecutor_Setup_Local(t *testing.T) { Pipeline: _pipeline, Repo: _repo, Runtime: _runtime, - User: _user, Version: "v1.0.0", } @@ -194,7 +189,6 @@ func TestExecutor_Setup_Windows(t *testing.T) { Pipeline: _pipeline, Repo: _repo, Runtime: _runtime, - User: _user, } got, err := _setup.Windows() @@ -223,6 +217,9 @@ func TestExecutor_Setup_Validate(t *testing.T) { t.Errorf("unable to create runtime engine: %v", err) } + _emptyOwnerRepo := *_repo + _emptyOwnerRepo.Owner = nil + // setup tests tests := []struct { name string @@ -239,7 +236,6 @@ func TestExecutor_Setup_Validate(t *testing.T) { Pipeline: _pipeline, Repo: _repo, Runtime: _runtime, - User: _user, }, failure: false, }, @@ -253,7 +249,6 @@ func TestExecutor_Setup_Validate(t *testing.T) { Pipeline: _pipeline, Repo: _repo, Runtime: _runtime, - User: _user, }, failure: true, }, @@ -267,7 +262,6 @@ func TestExecutor_Setup_Validate(t *testing.T) { Pipeline: _pipeline, Repo: _repo, Runtime: _runtime, - User: _user, }, failure: true, }, @@ -281,7 +275,6 @@ func TestExecutor_Setup_Validate(t *testing.T) { Pipeline: _pipeline, Repo: _repo, Runtime: _runtime, - User: _user, }, failure: true, }, @@ -295,7 +288,6 @@ func TestExecutor_Setup_Validate(t *testing.T) { Pipeline: nil, Repo: _repo, Runtime: _runtime, - User: _user, }, failure: true, }, @@ -309,7 +301,6 @@ func TestExecutor_Setup_Validate(t *testing.T) { Pipeline: _pipeline, Repo: nil, Runtime: _runtime, - User: _user, }, failure: true, }, @@ -323,7 +314,6 @@ func TestExecutor_Setup_Validate(t *testing.T) { Pipeline: _pipeline, Repo: _repo, Runtime: nil, - User: _user, }, failure: true, }, @@ -335,9 +325,8 @@ func TestExecutor_Setup_Validate(t *testing.T) { Driver: constants.DriverLinux, MaxLogSize: 2097152, Pipeline: _pipeline, - Repo: _repo, + Repo: &_emptyOwnerRepo, Runtime: _runtime, - User: nil, }, failure: true, }, diff --git a/go.mod b/go.mod index 52d010a1..5d48dbd3 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,8 @@ module github.com/go-vela/worker -go 1.21 +go 1.21.9 + +toolchain go1.22.2 require ( github.com/Masterminds/semver/v3 v3.2.1 @@ -8,9 +10,9 @@ require ( github.com/docker/docker v24.0.9+incompatible github.com/docker/go-units v0.5.0 github.com/gin-gonic/gin v1.9.1 - github.com/go-vela/sdk-go v0.23.3-0.20240319181130-4a7c245c93ae - github.com/go-vela/server v0.23.4-0.20240319161125-1809638e7e72 - github.com/go-vela/types v0.23.2 + github.com/go-vela/sdk-go v0.23.3-0.20240411165353-c3fdc7210625 + github.com/go-vela/server v0.23.4-0.20240411145541-132447406cf7 + github.com/go-vela/types v0.23.4-0.20240405205548-f24f795ac0b7 github.com/golang-jwt/jwt/v5 v5.2.1 github.com/google/go-cmp v0.6.0 github.com/joho/godotenv v1.5.1 @@ -63,7 +65,7 @@ require ( github.com/gogo/protobuf v1.3.2 // indirect github.com/golang/protobuf v1.5.3 // indirect github.com/google/gnostic-models v0.6.8 // indirect - github.com/google/go-github/v59 v59.0.0 // indirect + github.com/google/go-github/v61 v61.0.0 // indirect github.com/google/go-querystring v1.1.0 // indirect github.com/google/gofuzz v1.2.0 // indirect github.com/google/uuid v1.6.0 // indirect diff --git a/go.sum b/go.sum index 2c44cee8..9f9225fc 100644 --- a/go.sum +++ b/go.sum @@ -93,12 +93,12 @@ github.com/go-playground/validator/v10 v10.14.0 h1:vgvQWe3XCz3gIeFDm/HnTIbj6UGmg github.com/go-playground/validator/v10 v10.14.0/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU= github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI= github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls= -github.com/go-vela/sdk-go v0.23.3-0.20240319181130-4a7c245c93ae h1:E5sgPxZsuiB00hcAgR/TpzRcovy+GVFzTSZfPHMIfPY= -github.com/go-vela/sdk-go v0.23.3-0.20240319181130-4a7c245c93ae/go.mod h1:4iOo5uuh4S3V//7ipZ9ZxvXc1wR2EGxDCeTqpom8rfU= -github.com/go-vela/server v0.23.4-0.20240319161125-1809638e7e72 h1:vREnnFuJCKvnYDzHpo8tnXnjpdWgwJ4u2+XB1aoDZQg= -github.com/go-vela/server v0.23.4-0.20240319161125-1809638e7e72/go.mod h1:uSS5W5UzhNzAsFbKrniwr5OWtq+Q09u/i8H8nr9ls0M= -github.com/go-vela/types v0.23.2 h1:QDt2lta7FPEfN2RK/Bn++DkqyjGIB4H/Q4XkFAj3hXQ= -github.com/go-vela/types v0.23.2/go.mod h1:aTE6dzssqTGOvU6m2/vsI9NoSW/3hH/yLzf3cCSo0Zk= +github.com/go-vela/sdk-go v0.23.3-0.20240411165353-c3fdc7210625 h1:mVdVHlhXeSMNDOCLK8RFTfuw3m+kLsevdIK21/xRfu4= +github.com/go-vela/sdk-go v0.23.3-0.20240411165353-c3fdc7210625/go.mod h1:qByLq0AvL9yFLfn3xhtSiXTXSHkZVZyr7C91NHU8XnQ= +github.com/go-vela/server v0.23.4-0.20240411145541-132447406cf7 h1:G8h44XJ3+gaxiWBV2uAZ82abMXhWRkrNq9sNo2cOaZU= +github.com/go-vela/server v0.23.4-0.20240411145541-132447406cf7/go.mod h1:QV9JFv+LdpAgkRJhHE92dh4vVdh0kNv8OJnyOLt++84= +github.com/go-vela/types v0.23.4-0.20240405205548-f24f795ac0b7 h1:3mN7ej69dMH3Vis3G/tPLzLL0Rfp8nR5qd0gpj5ejRM= +github.com/go-vela/types v0.23.4-0.20240405205548-f24f795ac0b7/go.mod h1:mEF9dLkk00rUXf/t39n2WvXZgJbxnPEEWy+DHqIlRUo= github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= @@ -119,8 +119,8 @@ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= -github.com/google/go-github/v59 v59.0.0 h1:7h6bgpF5as0YQLLkEiVqpgtJqjimMYhBkD4jT5aN3VA= -github.com/google/go-github/v59 v59.0.0/go.mod h1:rJU4R0rQHFVFDOkqGWxfLNo6vEk4dv40oDjhV/gH6wM= +github.com/google/go-github/v61 v61.0.0 h1:VwQCBwhyE9JclCI+22/7mLB1PuU9eowCXKY5pNlu1go= +github.com/google/go-github/v61 v61.0.0/go.mod h1:0WR+KmsWX75G2EbpyGsGmradjo3IiciuI4BmdVCobQY= github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8= github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= diff --git a/internal/build/snapshot.go b/internal/build/snapshot.go index 7f6e200d..8b0f95fb 100644 --- a/internal/build/snapshot.go +++ b/internal/build/snapshot.go @@ -7,6 +7,7 @@ import ( "time" "github.com/go-vela/sdk-go/vela" + api "github.com/go-vela/server/api/types" "github.com/go-vela/types/constants" "github.com/go-vela/types/library" "github.com/sirupsen/logrus" @@ -14,7 +15,7 @@ import ( // Snapshot creates a moment in time record of the build // and attempts to upload it to the server. -func Snapshot(b *library.Build, c *vela.Client, e error, l *logrus.Entry, r *library.Repo) { +func Snapshot(b *library.Build, c *vela.Client, e error, l *logrus.Entry, r *api.Repo) { // check if the build is not in a canceled status if !strings.EqualFold(b.GetStatus(), constants.StatusCanceled) { // check if the error provided is empty diff --git a/internal/build/snapshot_test.go b/internal/build/snapshot_test.go index 04de9d38..76fb1261 100644 --- a/internal/build/snapshot_test.go +++ b/internal/build/snapshot_test.go @@ -9,6 +9,8 @@ import ( "github.com/gin-gonic/gin" "github.com/go-vela/sdk-go/vela" + api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/api/types/actions" "github.com/go-vela/server/mock/server" "github.com/go-vela/types/library" ) @@ -42,23 +44,24 @@ func TestBuild_Snapshot(t *testing.T) { Distribution: vela.String("linux"), } - r := &library.Repo{ - ID: vela.Int64(1), - Org: vela.String("github"), - Name: vela.String("octocat"), - FullName: vela.String("github/octocat"), - Link: vela.String("https://github.com/github/octocat"), - Clone: vela.String("https://github.com/github/octocat.git"), - Branch: vela.String("main"), - Timeout: vela.Int64(60), - Visibility: vela.String("public"), - Private: vela.Bool(false), - Trusted: vela.Bool(false), - Active: vela.Bool(true), - AllowPull: vela.Bool(false), - AllowPush: vela.Bool(true), - AllowDeploy: vela.Bool(false), - AllowTag: vela.Bool(false), + r := &api.Repo{ + ID: vela.Int64(1), + Org: vela.String("github"), + Name: vela.String("octocat"), + FullName: vela.String("github/octocat"), + Link: vela.String("https://github.com/github/octocat"), + Clone: vela.String("https://github.com/github/octocat.git"), + Branch: vela.String("main"), + Timeout: vela.Int64(60), + Visibility: vela.String("public"), + Private: vela.Bool(false), + Trusted: vela.Bool(false), + Active: vela.Bool(true), + AllowEvents: &api.Events{ + Push: &actions.Push{ + Branch: vela.Bool(true), + }, + }, } gin.SetMode(gin.TestMode) @@ -75,7 +78,7 @@ func TestBuild_Snapshot(t *testing.T) { build *library.Build client *vela.Client err error - repo *library.Repo + repo *api.Repo }{ { name: "build with error", @@ -102,7 +105,7 @@ func TestBuild_Snapshot(t *testing.T) { // run test for _, test := range tests { - t.Run(test.name, func(t *testing.T) { + t.Run(test.name, func(_ *testing.T) { Snapshot(test.build, test.client, test.err, nil, test.repo) }) } diff --git a/internal/build/upload.go b/internal/build/upload.go index a4b4ab77..681ba3a1 100644 --- a/internal/build/upload.go +++ b/internal/build/upload.go @@ -7,6 +7,7 @@ import ( "time" "github.com/go-vela/sdk-go/vela" + api "github.com/go-vela/server/api/types" "github.com/go-vela/types/constants" "github.com/go-vela/types/library" "github.com/sirupsen/logrus" @@ -14,7 +15,7 @@ import ( // Upload tracks the final state of the build // and attempts to upload it to the server. -func Upload(b *library.Build, c *vela.Client, e error, l *logrus.Entry, r *library.Repo) { +func Upload(b *library.Build, c *vela.Client, e error, l *logrus.Entry, r *api.Repo) { // handle the build based off the status provided switch b.GetStatus() { // build is in a canceled state diff --git a/internal/build/upload_test.go b/internal/build/upload_test.go index fb43c0a1..7718560a 100644 --- a/internal/build/upload_test.go +++ b/internal/build/upload_test.go @@ -9,6 +9,8 @@ import ( "github.com/gin-gonic/gin" "github.com/go-vela/sdk-go/vela" + api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/api/types/actions" "github.com/go-vela/server/mock/server" "github.com/go-vela/types/library" ) @@ -51,23 +53,24 @@ func TestBuild_Upload(t *testing.T) { _pending := *_build _pending.SetStatus("pending") - _repo := &library.Repo{ - ID: vela.Int64(1), - Org: vela.String("github"), - Name: vela.String("octocat"), - FullName: vela.String("github/octocat"), - Link: vela.String("https://github.com/github/octocat"), - Clone: vela.String("https://github.com/github/octocat.git"), - Branch: vela.String("main"), - Timeout: vela.Int64(60), - Visibility: vela.String("public"), - Private: vela.Bool(false), - Trusted: vela.Bool(false), - Active: vela.Bool(true), - AllowPull: vela.Bool(false), - AllowPush: vela.Bool(true), - AllowDeploy: vela.Bool(false), - AllowTag: vela.Bool(false), + _repo := &api.Repo{ + ID: vela.Int64(1), + Org: vela.String("github"), + Name: vela.String("octocat"), + FullName: vela.String("github/octocat"), + Link: vela.String("https://github.com/github/octocat"), + Clone: vela.String("https://github.com/github/octocat.git"), + Branch: vela.String("main"), + Timeout: vela.Int64(60), + Visibility: vela.String("public"), + Private: vela.Bool(false), + Trusted: vela.Bool(false), + Active: vela.Bool(true), + AllowEvents: &api.Events{ + Push: &actions.Push{ + Branch: vela.Bool(true), + }, + }, } gin.SetMode(gin.TestMode) @@ -84,7 +87,7 @@ func TestBuild_Upload(t *testing.T) { build *library.Build client *vela.Client err error - repo *library.Repo + repo *api.Repo }{ { name: "build with error", @@ -132,7 +135,7 @@ func TestBuild_Upload(t *testing.T) { // run test for _, test := range tests { - t.Run(test.name, func(t *testing.T) { + t.Run(test.name, func(_ *testing.T) { Upload(test.build, test.client, test.err, nil, test.repo) }) } diff --git a/internal/service/environment.go b/internal/service/environment.go index 92c9ee64..189279f9 100644 --- a/internal/service/environment.go +++ b/internal/service/environment.go @@ -5,6 +5,7 @@ package service import ( "fmt" + api "github.com/go-vela/server/api/types" "github.com/go-vela/types/constants" "github.com/go-vela/types/library" "github.com/go-vela/types/pipeline" @@ -12,7 +13,7 @@ import ( // Environment attempts to update the environment variables // for the container based off the library resources. -func Environment(c *pipeline.Container, b *library.Build, r *library.Repo, s *library.Service, version string) error { +func Environment(c *pipeline.Container, b *library.Build, r *api.Repo, s *library.Service, version string) error { // check if container or container environment are empty if c == nil || c.Environment == nil { return fmt.Errorf("empty container provided for environment") diff --git a/internal/service/environment_test.go b/internal/service/environment_test.go index a3820044..bac7bbe7 100644 --- a/internal/service/environment_test.go +++ b/internal/service/environment_test.go @@ -5,6 +5,7 @@ package service import ( "testing" + api "github.com/go-vela/server/api/types" "github.com/go-vela/types/library" "github.com/go-vela/types/pipeline" "github.com/go-vela/types/raw" @@ -54,7 +55,7 @@ func TestService_Environment(t *testing.T) { Pull: "not_present", } - r := new(library.Repo) + r := new(api.Repo) r.SetID(1) r.SetOrg("github") r.SetName("octocat") @@ -67,11 +68,7 @@ func TestService_Environment(t *testing.T) { r.SetPrivate(false) r.SetTrusted(false) r.SetActive(true) - r.SetAllowPull(false) - r.SetAllowPush(true) - r.SetAllowDeploy(false) - r.SetAllowTag(false) - r.SetAllowComment(false) + r.SetAllowEvents(api.NewEventsFromMask(1)) s := new(library.Service) s.SetID(1) @@ -95,7 +92,7 @@ func TestService_Environment(t *testing.T) { failure bool build *library.Build container *pipeline.Container - repo *library.Repo + repo *api.Repo service *library.Service }{ { diff --git a/internal/service/snapshot.go b/internal/service/snapshot.go index 2dccd388..97bf0673 100644 --- a/internal/service/snapshot.go +++ b/internal/service/snapshot.go @@ -7,6 +7,7 @@ import ( "time" "github.com/go-vela/sdk-go/vela" + api "github.com/go-vela/server/api/types" "github.com/go-vela/types/constants" "github.com/go-vela/types/library" "github.com/go-vela/types/pipeline" @@ -15,7 +16,7 @@ import ( // Snapshot creates a moment in time record of the // service and attempts to upload it to the server. -func Snapshot(ctn *pipeline.Container, b *library.Build, c *vela.Client, l *logrus.Entry, r *library.Repo, s *library.Service) { +func Snapshot(ctn *pipeline.Container, b *library.Build, c *vela.Client, l *logrus.Entry, r *api.Repo, s *library.Service) { // check if the build is not in a canceled status if !strings.EqualFold(s.GetStatus(), constants.StatusCanceled) { // check if the container is running in headless mode diff --git a/internal/service/snapshot_test.go b/internal/service/snapshot_test.go index 6b7309ca..253b57f5 100644 --- a/internal/service/snapshot_test.go +++ b/internal/service/snapshot_test.go @@ -8,6 +8,7 @@ import ( "github.com/gin-gonic/gin" "github.com/go-vela/sdk-go/vela" + api "github.com/go-vela/server/api/types" "github.com/go-vela/server/mock/server" "github.com/go-vela/types/library" "github.com/go-vela/types/pipeline" @@ -65,7 +66,7 @@ func TestService_Snapshot(t *testing.T) { Pull: "not_present", } - _repo := &library.Repo{ + _repo := &api.Repo{ ID: vela.Int64(1), Org: vela.String("github"), Name: vela.String("octocat"), @@ -78,10 +79,7 @@ func TestService_Snapshot(t *testing.T) { Private: vela.Bool(false), Trusted: vela.Bool(false), Active: vela.Bool(true), - AllowPull: vela.Bool(false), - AllowPush: vela.Bool(true), - AllowDeploy: vela.Bool(false), - AllowTag: vela.Bool(false), + AllowEvents: api.NewEventsFromMask(1), } _service := &library.Service{ @@ -115,7 +113,7 @@ func TestService_Snapshot(t *testing.T) { build *library.Build client *vela.Client container *pipeline.Container - repo *library.Repo + repo *api.Repo service *library.Service }{ { diff --git a/internal/service/upload.go b/internal/service/upload.go index 6ea3d0e1..865e793c 100644 --- a/internal/service/upload.go +++ b/internal/service/upload.go @@ -6,6 +6,7 @@ import ( "time" "github.com/go-vela/sdk-go/vela" + api "github.com/go-vela/server/api/types" "github.com/go-vela/types/constants" "github.com/go-vela/types/library" "github.com/go-vela/types/pipeline" @@ -14,7 +15,7 @@ import ( // Upload tracks the final state of the service // and attempts to upload it to the server. -func Upload(ctn *pipeline.Container, b *library.Build, c *vela.Client, l *logrus.Entry, r *library.Repo, s *library.Service) { +func Upload(ctn *pipeline.Container, b *library.Build, c *vela.Client, l *logrus.Entry, r *api.Repo, s *library.Service) { // handle the service based off the status provided switch s.GetStatus() { // service is in a canceled state diff --git a/internal/service/upload_test.go b/internal/service/upload_test.go index fb1ae028..90ec085a 100644 --- a/internal/service/upload_test.go +++ b/internal/service/upload_test.go @@ -8,6 +8,7 @@ import ( "github.com/gin-gonic/gin" "github.com/go-vela/sdk-go/vela" + api "github.com/go-vela/server/api/types" "github.com/go-vela/server/mock/server" "github.com/go-vela/types/library" "github.com/go-vela/types/pipeline" @@ -63,7 +64,7 @@ func TestService_Upload(t *testing.T) { Pull: "always", } - _repo := &library.Repo{ + _repo := &api.Repo{ ID: vela.Int64(1), Org: vela.String("github"), Name: vela.String("octocat"), @@ -76,10 +77,7 @@ func TestService_Upload(t *testing.T) { Private: vela.Bool(false), Trusted: vela.Bool(false), Active: vela.Bool(true), - AllowPull: vela.Bool(false), - AllowPush: vela.Bool(true), - AllowDeploy: vela.Bool(false), - AllowTag: vela.Bool(false), + AllowEvents: api.NewEventsFromMask(1), } _service := &library.Service{ @@ -122,7 +120,7 @@ func TestService_Upload(t *testing.T) { build *library.Build client *vela.Client container *pipeline.Container - repo *library.Repo + repo *api.Repo service *library.Service }{ { diff --git a/internal/step/environment.go b/internal/step/environment.go index 48fb1638..72a391b8 100644 --- a/internal/step/environment.go +++ b/internal/step/environment.go @@ -5,6 +5,7 @@ package step import ( "fmt" + api "github.com/go-vela/server/api/types" "github.com/go-vela/types/constants" "github.com/go-vela/types/library" "github.com/go-vela/types/pipeline" @@ -12,7 +13,7 @@ import ( // Environment attempts to update the environment variables // for the container based off the library resources. -func Environment(c *pipeline.Container, b *library.Build, r *library.Repo, s *library.Step, version string) error { +func Environment(c *pipeline.Container, b *library.Build, r *api.Repo, s *library.Step, version string) error { // check if container or container environment are empty if c == nil || c.Environment == nil { return fmt.Errorf("empty container provided for environment") diff --git a/internal/step/environment_test.go b/internal/step/environment_test.go index b344f07e..77c029fe 100644 --- a/internal/step/environment_test.go +++ b/internal/step/environment_test.go @@ -5,6 +5,7 @@ package step import ( "testing" + api "github.com/go-vela/server/api/types" "github.com/go-vela/types/library" "github.com/go-vela/types/pipeline" "github.com/go-vela/types/raw" @@ -53,7 +54,7 @@ func TestStep_Environment(t *testing.T) { Pull: "always", } - r := new(library.Repo) + r := new(api.Repo) r.SetID(1) r.SetOrg("github") r.SetName("octocat") @@ -66,11 +67,7 @@ func TestStep_Environment(t *testing.T) { r.SetPrivate(false) r.SetTrusted(false) r.SetActive(true) - r.SetAllowPull(false) - r.SetAllowPush(true) - r.SetAllowDeploy(false) - r.SetAllowTag(false) - r.SetAllowComment(false) + r.SetAllowEvents(api.NewEventsFromMask(1)) s := new(library.Step) s.SetID(1) @@ -94,7 +91,7 @@ func TestStep_Environment(t *testing.T) { failure bool build *library.Build container *pipeline.Container - repo *library.Repo + repo *api.Repo step *library.Step }{ { diff --git a/internal/step/skip.go b/internal/step/skip.go index 380c8882..71bfd207 100644 --- a/internal/step/skip.go +++ b/internal/step/skip.go @@ -5,6 +5,7 @@ package step import ( "strings" + api "github.com/go-vela/server/api/types" "github.com/go-vela/types/constants" "github.com/go-vela/types/library" "github.com/go-vela/types/pipeline" @@ -13,7 +14,7 @@ import ( // Skip creates the ruledata from the build and repository // information and returns true if the data does not match // the ruleset for the given container. -func Skip(c *pipeline.Container, b *library.Build, r *library.Repo) (bool, error) { +func Skip(c *pipeline.Container, b *library.Build, r *api.Repo) (bool, error) { // check if the container provided is empty if c == nil { return true, nil diff --git a/internal/step/skip_test.go b/internal/step/skip_test.go index 1c6357d9..1b314709 100644 --- a/internal/step/skip_test.go +++ b/internal/step/skip_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/go-vela/sdk-go/vela" + api "github.com/go-vela/server/api/types" "github.com/go-vela/types/library" "github.com/go-vela/types/pipeline" ) @@ -190,7 +191,7 @@ func TestStep_Skip(t *testing.T) { Pull: "always", } - _repo := &library.Repo{ + _repo := &api.Repo{ ID: vela.Int64(1), Org: vela.String("github"), Name: vela.String("octocat"), @@ -203,17 +204,14 @@ func TestStep_Skip(t *testing.T) { Private: vela.Bool(false), Trusted: vela.Bool(false), Active: vela.Bool(true), - AllowPull: vela.Bool(false), - AllowPush: vela.Bool(true), - AllowDeploy: vela.Bool(false), - AllowTag: vela.Bool(false), + AllowEvents: api.NewEventsFromMask(1), } tests := []struct { name string build *library.Build container *pipeline.Container - repo *library.Repo + repo *api.Repo want bool }{ { diff --git a/internal/step/snapshot.go b/internal/step/snapshot.go index 3bcadfa1..01aeeb04 100644 --- a/internal/step/snapshot.go +++ b/internal/step/snapshot.go @@ -7,6 +7,7 @@ import ( "time" "github.com/go-vela/sdk-go/vela" + api "github.com/go-vela/server/api/types" "github.com/go-vela/types/constants" "github.com/go-vela/types/library" "github.com/go-vela/types/pipeline" @@ -15,7 +16,7 @@ import ( // Snapshot creates a moment in time record of the // step and attempts to upload it to the server. -func Snapshot(ctn *pipeline.Container, b *library.Build, c *vela.Client, l *logrus.Entry, r *library.Repo, s *library.Step) { +func Snapshot(ctn *pipeline.Container, b *library.Build, c *vela.Client, l *logrus.Entry, r *api.Repo, s *library.Step) { // check if the build is not in a canceled status or error status logrus.Debugf("Snapshot s: %s %s", s.GetName(), s.GetStatus()) @@ -66,7 +67,7 @@ func Snapshot(ctn *pipeline.Container, b *library.Build, c *vela.Client, l *logr // SnapshotInit creates a moment in time record of the // init step and attempts to upload it to the server. -func SnapshotInit(ctn *pipeline.Container, b *library.Build, c *vela.Client, l *logrus.Entry, r *library.Repo, s *library.Step, lg *library.Log) { +func SnapshotInit(ctn *pipeline.Container, b *library.Build, c *vela.Client, l *logrus.Entry, r *api.Repo, s *library.Step, lg *library.Log) { // check if the build is not in a canceled status if !strings.EqualFold(s.GetStatus(), constants.StatusCanceled) { // check if the container has an unsuccessful exit code diff --git a/internal/step/snapshot_test.go b/internal/step/snapshot_test.go index 4ffa75c1..239bf5a8 100644 --- a/internal/step/snapshot_test.go +++ b/internal/step/snapshot_test.go @@ -8,6 +8,7 @@ import ( "github.com/gin-gonic/gin" "github.com/go-vela/sdk-go/vela" + api "github.com/go-vela/server/api/types" "github.com/go-vela/server/mock/server" "github.com/go-vela/types/library" "github.com/go-vela/types/pipeline" @@ -63,7 +64,7 @@ func TestStep_Snapshot(t *testing.T) { Pull: "always", } - _repo := &library.Repo{ + _repo := &api.Repo{ ID: vela.Int64(1), Org: vela.String("github"), Name: vela.String("octocat"), @@ -76,10 +77,7 @@ func TestStep_Snapshot(t *testing.T) { Private: vela.Bool(false), Trusted: vela.Bool(false), Active: vela.Bool(true), - AllowPull: vela.Bool(false), - AllowPush: vela.Bool(true), - AllowDeploy: vela.Bool(false), - AllowTag: vela.Bool(false), + AllowEvents: api.NewEventsFromMask(1), } _step := &library.Step{ @@ -113,7 +111,7 @@ func TestStep_Snapshot(t *testing.T) { build *library.Build client *vela.Client container *pipeline.Container - repo *library.Repo + repo *api.Repo step *library.Step }{ { @@ -192,7 +190,7 @@ func TestStep_SnapshotInit(t *testing.T) { Pull: "always", } - _repo := &library.Repo{ + _repo := &api.Repo{ ID: vela.Int64(1), Org: vela.String("github"), Name: vela.String("octocat"), @@ -205,10 +203,7 @@ func TestStep_SnapshotInit(t *testing.T) { Private: vela.Bool(false), Trusted: vela.Bool(false), Active: vela.Bool(true), - AllowPull: vela.Bool(false), - AllowPush: vela.Bool(true), - AllowDeploy: vela.Bool(false), - AllowTag: vela.Bool(false), + AllowEvents: api.NewEventsFromMask(1), } _step := &library.Step{ @@ -243,7 +238,7 @@ func TestStep_SnapshotInit(t *testing.T) { client *vela.Client container *pipeline.Container log *library.Log - repo *library.Repo + repo *api.Repo step *library.Step }{ { diff --git a/internal/step/upload.go b/internal/step/upload.go index cd6b4ea4..05a8636c 100644 --- a/internal/step/upload.go +++ b/internal/step/upload.go @@ -6,6 +6,7 @@ import ( "time" "github.com/go-vela/sdk-go/vela" + api "github.com/go-vela/server/api/types" "github.com/go-vela/types/constants" "github.com/go-vela/types/library" "github.com/go-vela/types/pipeline" @@ -14,7 +15,7 @@ import ( // Upload tracks the final state of the step // and attempts to upload it to the server. -func Upload(ctn *pipeline.Container, b *library.Build, c *vela.Client, l *logrus.Entry, r *library.Repo, s *library.Step) { +func Upload(ctn *pipeline.Container, b *library.Build, c *vela.Client, l *logrus.Entry, r *api.Repo, s *library.Step) { // handle the step based off the status provided switch s.GetStatus() { // step is in a canceled state diff --git a/internal/step/upload_test.go b/internal/step/upload_test.go index e689d83a..62a81d4f 100644 --- a/internal/step/upload_test.go +++ b/internal/step/upload_test.go @@ -8,6 +8,7 @@ import ( "github.com/gin-gonic/gin" "github.com/go-vela/sdk-go/vela" + api "github.com/go-vela/server/api/types" "github.com/go-vela/server/mock/server" "github.com/go-vela/types/library" "github.com/go-vela/types/pipeline" @@ -63,7 +64,7 @@ func TestStep_Upload(t *testing.T) { Pull: "always", } - _repo := &library.Repo{ + _repo := &api.Repo{ ID: vela.Int64(1), Org: vela.String("github"), Name: vela.String("octocat"), @@ -76,10 +77,7 @@ func TestStep_Upload(t *testing.T) { Private: vela.Bool(false), Trusted: vela.Bool(false), Active: vela.Bool(true), - AllowPull: vela.Bool(false), - AllowPush: vela.Bool(true), - AllowDeploy: vela.Bool(false), - AllowTag: vela.Bool(false), + AllowEvents: api.NewEventsFromMask(1), } _step := &library.Step{ @@ -122,7 +120,7 @@ func TestStep_Upload(t *testing.T) { build *library.Build client *vela.Client container *pipeline.Container - repo *library.Repo + repo *api.Repo step *library.Step }{ { diff --git a/mock/worker/repo.go b/mock/worker/repo.go index 60156766..c0071de4 100644 --- a/mock/worker/repo.go +++ b/mock/worker/repo.go @@ -9,8 +9,8 @@ import ( "strings" "github.com/gin-gonic/gin" + api "github.com/go-vela/server/api/types" "github.com/go-vela/types" - "github.com/go-vela/types/library" ) const ( @@ -53,7 +53,7 @@ func getRepo(c *gin.Context) { data := []byte(RepoResp) - var body library.Repo + var body api.Repo _ = json.Unmarshal(data, &body) c.JSON(http.StatusOK, body) diff --git a/router/middleware/executor/executor_test.go b/router/middleware/executor/executor_test.go index 6421e07b..06b57dcb 100644 --- a/router/middleware/executor/executor_test.go +++ b/router/middleware/executor/executor_test.go @@ -11,6 +11,7 @@ import ( "github.com/gin-gonic/gin" "github.com/go-vela/sdk-go/vela" + api "github.com/go-vela/server/api/types" "github.com/go-vela/types/constants" "github.com/go-vela/types/library" "github.com/go-vela/types/pipeline" @@ -27,6 +28,9 @@ func TestExecutor_Retrieve(t *testing.T) { t.Errorf("unable to create runtime engine: %v", err) } + _repo := new(api.Repo) + _repo.SetOwner(new(library.User)) + want, err := executor.New(&executor.Setup{ Driver: constants.DriverLinux, MaxLogSize: 2097152, @@ -34,8 +38,7 @@ func TestExecutor_Retrieve(t *testing.T) { Runtime: _runtime, Build: new(library.Build), Pipeline: new(pipeline.Build), - Repo: new(library.Repo), - User: new(library.User), + Repo: _repo, }) if err != nil { t.Errorf("unable to create executor engine: %v", err) @@ -62,6 +65,9 @@ func TestExecutor_Establish(t *testing.T) { t.Errorf("unable to create runtime engine: %v", err) } + _repo := new(api.Repo) + _repo.SetOwner(new(library.User)) + want, err := executor.New(&executor.Setup{ Driver: constants.DriverLinux, MaxLogSize: 2097152, @@ -69,8 +75,7 @@ func TestExecutor_Establish(t *testing.T) { Runtime: _runtime, Build: new(library.Build), Pipeline: new(pipeline.Build), - Repo: new(library.Repo), - User: new(library.User), + Repo: _repo, }) if err != nil { t.Errorf("unable to create executor engine: %v", err)