From 4cd1ecebf17a66b41d132fbc7e521cd9525365c6 Mon Sep 17 00:00:00 2001 From: Johannes Batzill Date: Tue, 30 Aug 2022 09:51:22 -0700 Subject: [PATCH] Remove unnecessary types --- cli/cli.go | 4 - cli/execution/create.go | 82 ------ cli/execution/delete.go | 40 --- cli/execution/execution.go | 17 -- cli/execution/find.go | 68 ----- cli/execution/list.go | 85 ------ cli/execution/update.go | 87 ------ cli/pipeline/create.go | 77 ------ cli/pipeline/delete.go | 35 --- cli/pipeline/find.go | 63 ----- cli/pipeline/list.go | 80 ------ cli/pipeline/pipeline.go | 17 -- cli/pipeline/update.go | 82 ------ cli/server/wire_gen.go | 4 +- client/client.go | 90 ------- client/interface.go | 30 --- internal/api/handler/executions/create.go | 96 ------- .../api/handler/executions/create_test.go | 5 - internal/api/handler/executions/delete.go | 61 ----- .../api/handler/executions/delete_test.go | 5 - internal/api/handler/executions/find.go | 50 ---- internal/api/handler/executions/find_test.go | 5 - internal/api/handler/executions/list.go | 55 ---- internal/api/handler/executions/list_test.go | 5 - internal/api/handler/executions/update.go | 95 ------- .../api/handler/executions/update_test.go | 5 - internal/api/handler/pipelines/create.go | 80 ------ internal/api/handler/pipelines/create_test.go | 5 - internal/api/handler/pipelines/delete.go | 46 ---- internal/api/handler/pipelines/delete_test.go | 5 - internal/api/handler/pipelines/find.go | 51 ---- internal/api/handler/pipelines/find_test.go | 5 - internal/api/handler/pipelines/list.go | 42 --- internal/api/handler/pipelines/list_test.go | 87 ------ internal/api/handler/pipelines/update.go | 79 ------ internal/api/handler/pipelines/update_test.go | 5 - internal/api/handler/projects/find.go | 32 --- internal/api/handler/projects/find_test.go | 5 - internal/api/handler/projects/list.go | 32 --- internal/api/handler/projects/list_test.go | 5 - internal/api/openapi/execution.go | 111 -------- internal/api/openapi/openapi.go | 3 - internal/api/openapi/pipeline.go | 103 ------- internal/api/openapi/projects.go | 63 ----- internal/router/router.go | 34 --- internal/store/database/execution.go | 145 ---------- internal/store/database/execution_sync.go | 67 ----- internal/store/database/execution_test.go | 214 --------------- internal/store/database/pipeline.go | 167 ------------ internal/store/database/pipeline_sync.go | 74 ----- internal/store/database/pipeline_test.go | 254 ------------------ .../store/database/testdata/executions.json | 30 --- .../store/database/testdata/pipelines.json | 22 -- internal/store/database/wire.go | 26 -- internal/store/store.go | 45 ---- mocks/mock.go | 2 +- mocks/mock_client.go | 148 ---------- mocks/mock_store.go | 237 +--------------- types/check/execution.go | 48 ---- types/check/execution_test.go | 5 - types/check/pipeline.go | 48 ---- types/enum/role.go | 48 ---- types/enum/role_test.go | 19 -- types/types.go | 94 ------- 64 files changed, 3 insertions(+), 3726 deletions(-) delete mode 100644 cli/execution/create.go delete mode 100644 cli/execution/delete.go delete mode 100644 cli/execution/execution.go delete mode 100644 cli/execution/find.go delete mode 100644 cli/execution/list.go delete mode 100644 cli/execution/update.go delete mode 100644 cli/pipeline/create.go delete mode 100644 cli/pipeline/delete.go delete mode 100644 cli/pipeline/find.go delete mode 100644 cli/pipeline/list.go delete mode 100644 cli/pipeline/pipeline.go delete mode 100644 cli/pipeline/update.go delete mode 100644 internal/api/handler/executions/create.go delete mode 100644 internal/api/handler/executions/create_test.go delete mode 100644 internal/api/handler/executions/delete.go delete mode 100644 internal/api/handler/executions/delete_test.go delete mode 100644 internal/api/handler/executions/find.go delete mode 100644 internal/api/handler/executions/find_test.go delete mode 100644 internal/api/handler/executions/list.go delete mode 100644 internal/api/handler/executions/list_test.go delete mode 100644 internal/api/handler/executions/update.go delete mode 100644 internal/api/handler/executions/update_test.go delete mode 100644 internal/api/handler/pipelines/create.go delete mode 100644 internal/api/handler/pipelines/create_test.go delete mode 100644 internal/api/handler/pipelines/delete.go delete mode 100644 internal/api/handler/pipelines/delete_test.go delete mode 100644 internal/api/handler/pipelines/find.go delete mode 100644 internal/api/handler/pipelines/find_test.go delete mode 100644 internal/api/handler/pipelines/list.go delete mode 100644 internal/api/handler/pipelines/list_test.go delete mode 100644 internal/api/handler/pipelines/update.go delete mode 100644 internal/api/handler/pipelines/update_test.go delete mode 100644 internal/api/handler/projects/find.go delete mode 100644 internal/api/handler/projects/find_test.go delete mode 100644 internal/api/handler/projects/list.go delete mode 100644 internal/api/handler/projects/list_test.go delete mode 100644 internal/api/openapi/execution.go delete mode 100644 internal/api/openapi/pipeline.go delete mode 100644 internal/api/openapi/projects.go delete mode 100644 internal/store/database/execution.go delete mode 100644 internal/store/database/execution_sync.go delete mode 100644 internal/store/database/execution_test.go delete mode 100644 internal/store/database/pipeline.go delete mode 100644 internal/store/database/pipeline_sync.go delete mode 100644 internal/store/database/pipeline_test.go delete mode 100644 internal/store/database/testdata/executions.json delete mode 100644 internal/store/database/testdata/pipelines.json delete mode 100644 types/check/execution.go delete mode 100644 types/check/execution_test.go delete mode 100644 types/check/pipeline.go delete mode 100644 types/enum/role.go delete mode 100644 types/enum/role_test.go diff --git a/cli/cli.go b/cli/cli.go index 624726f95..f0ca564fc 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -8,8 +8,6 @@ import ( "context" "os" - "github.com/harness/gitness/cli/execution" - "github.com/harness/gitness/cli/pipeline" "github.com/harness/gitness/cli/server" "github.com/harness/gitness/cli/token" "github.com/harness/gitness/cli/user" @@ -34,8 +32,6 @@ func Command() { app := kingpin.New(application, description) server.Register(app) user.Register(app) - pipeline.Register(app) - execution.Register(app) users.Register(app) token.Register(app) registerLogin(app) diff --git a/cli/execution/create.go b/cli/execution/create.go deleted file mode 100644 index fc8927eb4..000000000 --- a/cli/execution/create.go +++ /dev/null @@ -1,82 +0,0 @@ -// Copyright 2021 Harness Inc. All rights reserved. -// Use of this source code is governed by the Polyform Free Trial License -// that can be found in the LICENSE.md file for this repository. - -package execution - -import ( - "encoding/json" - "os" - "text/template" - - "github.com/harness/gitness/cli/util" - "github.com/harness/gitness/types" - - "github.com/drone/funcmap" - "gopkg.in/alecthomas/kingpin.v2" -) - -type createCommand struct { - pipeline string - slug string - name string - desc string - tmpl string - json bool -} - -func (c *createCommand) run(*kingpin.ParseContext) error { - client, err := util.Client() - if err != nil { - return err - } - in := &types.Execution{ - Slug: c.slug, - Name: c.name, - Desc: c.desc, - } - item, err := client.ExecutionCreate(c.pipeline, in) - if err != nil { - return err - } - if c.json { - enc := json.NewEncoder(os.Stdout) - enc.SetIndent("", " ") - return enc.Encode(item) - } - tmpl, err := template.New("_").Funcs(funcmap.Funcs).Parse(c.tmpl) - if err != nil { - return err - } - return tmpl.Execute(os.Stdout, item) -} - -// helper function registers the user create command -func registerCreate(app *kingpin.CmdClause) { - c := new(createCommand) - - cmd := app.Command("create", "create a execution"). - Action(c.run) - - cmd.Arg("pipeline ", "pipeline slug"). - Required(). - StringVar(&c.pipeline) - - cmd.Arg("slug ", "execution slug"). - Required(). - StringVar(&c.slug) - - cmd.Flag("name", "execution name"). - StringVar(&c.name) - - cmd.Flag("desc", "execution description"). - StringVar(&c.desc) - - cmd.Flag("json", "json encode the output"). - BoolVar(&c.json) - - cmd.Flag("format", "format the output using a Go template"). - Default(executionTmpl). - Hidden(). - StringVar(&c.tmpl) -} diff --git a/cli/execution/delete.go b/cli/execution/delete.go deleted file mode 100644 index 4b0a83eb6..000000000 --- a/cli/execution/delete.go +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright 2021 Harness Inc. All rights reserved. -// Use of this source code is governed by the Polyform Free Trial License -// that can be found in the LICENSE.md file for this repository. - -package execution - -import ( - "github.com/harness/gitness/cli/util" - - "gopkg.in/alecthomas/kingpin.v2" -) - -type deleteCommand struct { - pipeline string - slug string -} - -func (c *deleteCommand) run(*kingpin.ParseContext) error { - client, err := util.Client() - if err != nil { - return err - } - return client.ExecutionDelete(c.pipeline, c.slug) -} - -// helper function registers the user delete command -func registerDelete(app *kingpin.CmdClause) { - c := new(deleteCommand) - - cmd := app.Command("delete", "delete a execution"). - Action(c.run) - - cmd.Arg("pipeline ", "pipeline slug"). - Required(). - StringVar(&c.pipeline) - - cmd.Arg("slug ", "execution slug"). - Required(). - StringVar(&c.slug) -} diff --git a/cli/execution/execution.go b/cli/execution/execution.go deleted file mode 100644 index 826c76a98..000000000 --- a/cli/execution/execution.go +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2021 Harness Inc. All rights reserved. -// Use of this source code is governed by the Polyform Free Trial License -// that can be found in the LICENSE.md file for this repository. - -package execution - -import "gopkg.in/alecthomas/kingpin.v2" - -// Register the command. -func Register(app *kingpin.Application) { - cmd := app.Command("execution", "manage executions") - registerFind(cmd) - registerList(cmd) - registerCreate(cmd) - registerUpdate(cmd) - registerDelete(cmd) -} diff --git a/cli/execution/find.go b/cli/execution/find.go deleted file mode 100644 index 2c910fe94..000000000 --- a/cli/execution/find.go +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright 2021 Harness Inc. All rights reserved. -// Use of this source code is governed by the Polyform Free Trial License -// that can be found in the LICENSE.md file for this repository. - -package execution - -import ( - "encoding/json" - "os" - "text/template" - - "github.com/harness/gitness/cli/util" - - "github.com/drone/funcmap" - "gopkg.in/alecthomas/kingpin.v2" -) - -type findCommand struct { - pipeline string - slug string - tmpl string - json bool -} - -func (c *findCommand) run(*kingpin.ParseContext) error { - client, err := util.Client() - if err != nil { - return err - } - item, err := client.Execution(c.pipeline, c.slug) - if err != nil { - return err - } - if c.json { - enc := json.NewEncoder(os.Stdout) - enc.SetIndent("", " ") - return enc.Encode(item) - } - tmpl, err := template.New("_").Funcs(funcmap.Funcs).Parse(c.tmpl + "\n") - if err != nil { - return err - } - return tmpl.Execute(os.Stdout, item) -} - -// helper function registers the user find command -func registerFind(app *kingpin.CmdClause) { - c := new(findCommand) - - cmd := app.Command("find", "display pipeline details"). - Action(c.run) - - cmd.Arg("pipeline ", "pipeline slug"). - Required(). - StringVar(&c.pipeline) - - cmd.Arg("slug ", "execution slug"). - Required(). - StringVar(&c.slug) - - cmd.Flag("json", "json encode the output"). - BoolVar(&c.json) - - cmd.Flag("format", "format the output using a Go template"). - Default(executionTmpl). - Hidden(). - StringVar(&c.tmpl) -} diff --git a/cli/execution/list.go b/cli/execution/list.go deleted file mode 100644 index 6e939b819..000000000 --- a/cli/execution/list.go +++ /dev/null @@ -1,85 +0,0 @@ -// Copyright 2021 Harness Inc. All rights reserved. -// Use of this source code is governed by the Polyform Free Trial License -// that can be found in the LICENSE.md file for this repository. - -package execution - -import ( - "encoding/json" - "os" - "text/template" - - "github.com/drone/funcmap" - "github.com/harness/gitness/cli/util" - "github.com/harness/gitness/types" - - "gopkg.in/alecthomas/kingpin.v2" -) - -const executionTmpl = ` -id: {{ .ID }} -slug: {{ .Slug }} -name: {{ .Name }} -desc: {{ .Desc }} -` - -type listCommand struct { - slug string - tmpl string - json bool - page int - size int -} - -func (c *listCommand) run(*kingpin.ParseContext) error { - client, err := util.Client() - if err != nil { - return err - } - list, err := client.ExecutionList(c.slug, types.Params{ - Size: c.size, - Page: c.page, - }) - if err != nil { - return err - } - if c.json { - enc := json.NewEncoder(os.Stdout) - enc.SetIndent("", " ") - return enc.Encode(list) - } - tmpl, err := template.New("_").Funcs(funcmap.Funcs).Parse(c.tmpl + "\n") - if err != nil { - return err - } - for _, item := range list { - tmpl.Execute(os.Stdout, item) - } - return nil -} - -// helper function registers the list command -func registerList(app *kingpin.CmdClause) { - c := new(listCommand) - - cmd := app.Command("ls", "display a list of executions"). - Action(c.run) - - cmd.Arg("pipeline ", "pipeline slug"). - Required(). - StringVar(&c.slug) - - cmd.Flag("page", "page number"). - IntVar(&c.page) - - cmd.Flag("per-page", "page size"). - IntVar(&c.size) - - cmd.Flag("json", "json encode the output"). - BoolVar(&c.json) - - cmd.Flag("format", "format the output using a Go template"). - Default(executionTmpl). - Hidden(). - StringVar(&c.tmpl) -} diff --git a/cli/execution/update.go b/cli/execution/update.go deleted file mode 100644 index eb777f649..000000000 --- a/cli/execution/update.go +++ /dev/null @@ -1,87 +0,0 @@ -// Copyright 2021 Harness Inc. All rights reserved. -// Use of this source code is governed by the Polyform Free Trial License -// that can be found in the LICENSE.md file for this repository. - -package execution - -import ( - "encoding/json" - "os" - "text/template" - - "github.com/gotidy/ptr" - "github.com/harness/gitness/cli/util" - "github.com/harness/gitness/types" - - "github.com/drone/funcmap" - "gopkg.in/alecthomas/kingpin.v2" -) - -type updateCommand struct { - pipeline string - slug string - name string - desc string - tmpl string - json bool -} - -func (c *updateCommand) run(*kingpin.ParseContext) error { - client, err := util.Client() - if err != nil { - return err - } - - in := new(types.ExecutionInput) - if v := c.name; v != "" { - in.Name = ptr.String(v) - } - if v := c.desc; v != "" { - in.Desc = ptr.String(v) - } - - item, err := client.ExecutionUpdate(c.pipeline, c.slug, in) - if err != nil { - return err - } - if c.json { - enc := json.NewEncoder(os.Stdout) - enc.SetIndent("", " ") - return enc.Encode(item) - } - tmpl, err := template.New("_").Funcs(funcmap.Funcs).Parse(c.tmpl) - if err != nil { - return err - } - return tmpl.Execute(os.Stdout, item) -} - -// helper function registers the update command -func registerUpdate(app *kingpin.CmdClause) { - c := new(updateCommand) - - cmd := app.Command("update", "update a execution"). - Action(c.run) - - cmd.Arg("pipeline ", "pipeline slug"). - Required(). - StringVar(&c.pipeline) - - cmd.Arg("slug ", "execution slug"). - Required(). - StringVar(&c.slug) - - cmd.Flag("name", "update pipeline name"). - StringVar(&c.name) - - cmd.Flag("desc", "update pipeline description"). - StringVar(&c.desc) - - cmd.Flag("json", "json encode the output"). - BoolVar(&c.json) - - cmd.Flag("format", "format the output using a Go template"). - Default(executionTmpl). - Hidden(). - StringVar(&c.tmpl) -} diff --git a/cli/pipeline/create.go b/cli/pipeline/create.go deleted file mode 100644 index 44fc9ae22..000000000 --- a/cli/pipeline/create.go +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright 2021 Harness Inc. All rights reserved. -// Use of this source code is governed by the Polyform Free Trial License -// that can be found in the LICENSE.md file for this repository. - -package pipeline - -import ( - "encoding/json" - "os" - "text/template" - - "github.com/harness/gitness/cli/util" - "github.com/harness/gitness/types" - - "github.com/drone/funcmap" - "gopkg.in/alecthomas/kingpin.v2" -) - -type createCommand struct { - slug string - name string - desc string - tmpl string - json bool -} - -func (c *createCommand) run(*kingpin.ParseContext) error { - client, err := util.Client() - if err != nil { - return err - } - in := &types.Pipeline{ - Slug: c.slug, - Name: c.name, - Desc: c.desc, - } - item, err := client.PipelineCreate(in) - if err != nil { - return err - } - if c.json { - enc := json.NewEncoder(os.Stdout) - enc.SetIndent("", " ") - return enc.Encode(item) - } - tmpl, err := template.New("_").Funcs(funcmap.Funcs).Parse(c.tmpl) - if err != nil { - return err - } - return tmpl.Execute(os.Stdout, item) -} - -// helper function registers the user create command -func registerCreate(app *kingpin.CmdClause) { - c := new(createCommand) - - cmd := app.Command("create", "create a pipeline"). - Action(c.run) - - cmd.Arg("slug", "pipeline slug"). - Required(). - StringVar(&c.slug) - - cmd.Flag("name", "pipeline name"). - StringVar(&c.name) - - cmd.Flag("desc", "pipeline description"). - StringVar(&c.desc) - - cmd.Flag("json", "json encode the output"). - BoolVar(&c.json) - - cmd.Flag("format", "format the output using a Go template"). - Default(pipelineTmpl). - Hidden(). - StringVar(&c.tmpl) -} diff --git a/cli/pipeline/delete.go b/cli/pipeline/delete.go deleted file mode 100644 index 1dc3ed9a1..000000000 --- a/cli/pipeline/delete.go +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright 2021 Harness Inc. All rights reserved. -// Use of this source code is governed by the Polyform Free Trial License -// that can be found in the LICENSE.md file for this repository. - -package pipeline - -import ( - "github.com/harness/gitness/cli/util" - - "gopkg.in/alecthomas/kingpin.v2" -) - -type deleteCommand struct { - slug string -} - -func (c *deleteCommand) run(*kingpin.ParseContext) error { - client, err := util.Client() - if err != nil { - return err - } - return client.PipelineDelete(c.slug) -} - -// helper function registers the user delete command -func registerDelete(app *kingpin.CmdClause) { - c := new(deleteCommand) - - cmd := app.Command("delete", "delete a pipeline"). - Action(c.run) - - cmd.Arg("slug ", "pipeline slug"). - Required(). - StringVar(&c.slug) -} diff --git a/cli/pipeline/find.go b/cli/pipeline/find.go deleted file mode 100644 index 1f20e5421..000000000 --- a/cli/pipeline/find.go +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright 2021 Harness Inc. All rights reserved. -// Use of this source code is governed by the Polyform Free Trial License -// that can be found in the LICENSE.md file for this repository. - -package pipeline - -import ( - "encoding/json" - "os" - "text/template" - - "github.com/harness/gitness/cli/util" - - "github.com/drone/funcmap" - "gopkg.in/alecthomas/kingpin.v2" -) - -type findCommand struct { - slug string - tmpl string - json bool -} - -func (c *findCommand) run(*kingpin.ParseContext) error { - client, err := util.Client() - if err != nil { - return err - } - item, err := client.Pipeline(c.slug) - if err != nil { - return err - } - if c.json { - enc := json.NewEncoder(os.Stdout) - enc.SetIndent("", " ") - return enc.Encode(item) - } - tmpl, err := template.New("_").Funcs(funcmap.Funcs).Parse(c.tmpl + "\n") - if err != nil { - return err - } - return tmpl.Execute(os.Stdout, item) -} - -// helper function registers the user find command -func registerFind(app *kingpin.CmdClause) { - c := new(findCommand) - - cmd := app.Command("find", "display pipeline details"). - Action(c.run) - - cmd.Arg("slug", "pipeline slug"). - Required(). - StringVar(&c.slug) - - cmd.Flag("json", "json encode the output"). - BoolVar(&c.json) - - cmd.Flag("format", "format the output using a Go template"). - Default(pipelineTmpl). - Hidden(). - StringVar(&c.tmpl) -} diff --git a/cli/pipeline/list.go b/cli/pipeline/list.go deleted file mode 100644 index 388fe3a02..000000000 --- a/cli/pipeline/list.go +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright 2021 Harness Inc. All rights reserved. -// Use of this source code is governed by the Polyform Free Trial License -// that can be found in the LICENSE.md file for this repository. - -package pipeline - -import ( - "encoding/json" - "os" - "text/template" - - "github.com/drone/funcmap" - "github.com/harness/gitness/cli/util" - "github.com/harness/gitness/types" - - "gopkg.in/alecthomas/kingpin.v2" -) - -const pipelineTmpl = ` -id: {{ .ID }} -slug: {{ .Slug }} -name: {{ .Name }} -desc: {{ .Desc }} -` - -type listCommand struct { - page int - size int - json bool - tmpl string -} - -func (c *listCommand) run(*kingpin.ParseContext) error { - client, err := util.Client() - if err != nil { - return err - } - list, err := client.PipelineList(types.Params{ - Size: c.size, - Page: c.page, - }) - if err != nil { - return err - } - if c.json { - enc := json.NewEncoder(os.Stdout) - enc.SetIndent("", " ") - return enc.Encode(list) - } - tmpl, err := template.New("_").Funcs(funcmap.Funcs).Parse(c.tmpl + "\n") - if err != nil { - return err - } - for _, item := range list { - tmpl.Execute(os.Stdout, item) - } - return nil -} - -// helper function registers the user list command -func registerList(app *kingpin.CmdClause) { - c := new(listCommand) - - cmd := app.Command("ls", "display a list of pipelines"). - Action(c.run) - - cmd.Flag("page", "page number"). - IntVar(&c.page) - - cmd.Flag("per-page", "page size"). - IntVar(&c.size) - - cmd.Flag("json", "json encode the output"). - BoolVar(&c.json) - - cmd.Flag("format", "format the output using a Go template"). - Default(pipelineTmpl). - Hidden(). - StringVar(&c.tmpl) -} diff --git a/cli/pipeline/pipeline.go b/cli/pipeline/pipeline.go deleted file mode 100644 index 810b1b979..000000000 --- a/cli/pipeline/pipeline.go +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2021 Harness Inc. All rights reserved. -// Use of this source code is governed by the Polyform Free Trial License -// that can be found in the LICENSE.md file for this repository. - -package pipeline - -import "gopkg.in/alecthomas/kingpin.v2" - -// Register the command. -func Register(app *kingpin.Application) { - cmd := app.Command("pipeline", "manage pipelines") - registerFind(cmd) - registerList(cmd) - registerCreate(cmd) - registerUpdate(cmd) - registerDelete(cmd) -} diff --git a/cli/pipeline/update.go b/cli/pipeline/update.go deleted file mode 100644 index ffde25b60..000000000 --- a/cli/pipeline/update.go +++ /dev/null @@ -1,82 +0,0 @@ -// Copyright 2021 Harness Inc. All rights reserved. -// Use of this source code is governed by the Polyform Free Trial License -// that can be found in the LICENSE.md file for this repository. - -package pipeline - -import ( - "encoding/json" - "os" - "text/template" - - "github.com/gotidy/ptr" - "github.com/harness/gitness/cli/util" - "github.com/harness/gitness/types" - - "github.com/drone/funcmap" - "gopkg.in/alecthomas/kingpin.v2" -) - -type updateCommand struct { - slug string - name string - desc string - tmpl string - json bool -} - -func (c *updateCommand) run(*kingpin.ParseContext) error { - client, err := util.Client() - if err != nil { - return err - } - - in := new(types.PipelineInput) - if v := c.name; v != "" { - in.Name = ptr.String(v) - } - if v := c.desc; v != "" { - in.Desc = ptr.String(v) - } - - item, err := client.PipelineUpdate(c.slug, in) - if err != nil { - return err - } - if c.json { - enc := json.NewEncoder(os.Stdout) - enc.SetIndent("", " ") - return enc.Encode(item) - } - tmpl, err := template.New("_").Funcs(funcmap.Funcs).Parse(c.tmpl) - if err != nil { - return err - } - return tmpl.Execute(os.Stdout, item) -} - -// helper function registers the user update command -func registerUpdate(app *kingpin.CmdClause) { - c := new(updateCommand) - - cmd := app.Command("update", "update a pipeline"). - Action(c.run) - - cmd.Arg("slug", "pipeline slug"). - Required(). - StringVar(&c.slug) - - cmd.Flag("name", "update pipeline name"). - StringVar(&c.name) - - cmd.Flag("desc", "update pipeline description"). - StringVar(&c.desc) - - cmd.Flag("json", "json encode the output"). - BoolVar(&c.json) - - cmd.Flag("format", "format the output using a Go template"). - Default(pipelineTmpl). - Hidden(). - StringVar(&c.tmpl) -} diff --git a/cli/server/wire_gen.go b/cli/server/wire_gen.go index 312b4c96f..490f24680 100644 --- a/cli/server/wire_gen.go +++ b/cli/server/wire_gen.go @@ -22,11 +22,9 @@ func initSystem(config *types.Config) (*system, error) { if err != nil { return nil, err } - executionStore := database.ProvideExecutionStore(db) - pipelineStore := database.ProvidePipelineStore(db) userStore := database.ProvideUserStore(db) systemStore := memory.New(config) - handler := router.New(executionStore, pipelineStore, userStore, systemStore) + handler := router.New(userStore, systemStore) serverServer := server.ProvideServer(config, handler) nightly := cron.NewNightly() serverSystem := newSystem(serverServer, nightly) diff --git a/client/client.go b/client/client.go index 7eaf19b68..51f2463e5 100644 --- a/client/client.go +++ b/client/client.go @@ -136,96 +136,6 @@ func (c *HTTPClient) UserDelete(key string) error { return err } -// -// Pipeline endpoints -// - -// -// Pipeline endpoints -// - -// Pipeline returns a pipeline by slug. -func (c *HTTPClient) Pipeline(slug string) (*types.Pipeline, error) { - out := new(types.Pipeline) - uri := fmt.Sprintf("%s/api/v1/pipelines/%s", c.base, slug) - err := c.get(uri, out) - return out, err -} - -// PipelineList returns a list of all pipelines. -func (c *HTTPClient) PipelineList(params types.Params) ([]*types.Pipeline, error) { - out := []*types.Pipeline{} - uri := fmt.Sprintf("%s/api/v1/pipelines?page=%dper_page=%d", c.base, params.Page, params.Size) - err := c.get(uri, &out) - return out, err -} - -// PipelineCreate creates a new pipeline. -func (c *HTTPClient) PipelineCreate(pipeline *types.Pipeline) (*types.Pipeline, error) { - out := new(types.Pipeline) - uri := fmt.Sprintf("%s/api/v1/pipelines", c.base) - err := c.post(uri, pipeline, out) - return out, err -} - -// PipelineUpdate updates a pipeline. -func (c *HTTPClient) PipelineUpdate(key string, user *types.PipelineInput) (*types.Pipeline, error) { - out := new(types.Pipeline) - uri := fmt.Sprintf("%s/api/v1/pipelines/%s", c.base, key) - err := c.patch(uri, user, out) - return out, err -} - -// PipelineDelete deletes a pipeline. -func (c *HTTPClient) PipelineDelete(key string) error { - uri := fmt.Sprintf("%s/api/v1/pipelines/%s", c.base, key) - err := c.delete(uri) - return err -} - -// -// Execution endpoints -// - -// Execution returns a execution by ID. -func (c *HTTPClient) Execution(pipeline, slug string) (*types.Execution, error) { - out := new(types.Execution) - uri := fmt.Sprintf("%s/api/v1/pipelines/%s/executions/%s", c.base, pipeline, slug) - err := c.get(uri, out) - return out, err -} - -// ExecutionList returns a list of all executions by pipeline id. -func (c *HTTPClient) ExecutionList(pipeline string, params types.Params) ([]*types.Execution, error) { - out := []*types.Execution{} - uri := fmt.Sprintf("%s/api/v1/pipelines/%s/executions?page=%dper_page=%d", c.base, pipeline, params.Page, params.Size) - err := c.get(uri, &out) - return out, err -} - -// ExecutionCreate creates a new execution. -func (c *HTTPClient) ExecutionCreate(pipeline string, execution *types.Execution) (*types.Execution, error) { - out := new(types.Execution) - uri := fmt.Sprintf("%s/api/v1/pipelines/%s/executions", c.base, pipeline) - err := c.post(uri, execution, out) - return out, err -} - -// ExecutionUpdate updates a execution. -func (c *HTTPClient) ExecutionUpdate(pipeline, slug string, execution *types.ExecutionInput) (*types.Execution, error) { - out := new(types.Execution) - uri := fmt.Sprintf("%s/api/v1/pipelines/%s/executions/%s", c.base, pipeline, slug) - err := c.patch(uri, execution, out) - return out, err -} - -// ExecutionDelete deletes a execution. -func (c *HTTPClient) ExecutionDelete(pipeline, slug string) error { - uri := fmt.Sprintf("%s/api/v1/pipelines/%s/executions/%s", c.base, pipeline, slug) - err := c.delete(uri) - return err -} - // // http request helper functions // diff --git a/client/interface.go b/client/interface.go index 919c2a798..59b31fa48 100644 --- a/client/interface.go +++ b/client/interface.go @@ -35,36 +35,6 @@ type Client interface { // UserDelete deletes a user account by ID or email. UserDelete(key string) error - - // Pipeline returns a pipeline by slug. - Pipeline(slug string) (*types.Pipeline, error) - - // PipelineList returns a list of all pipelines. - PipelineList(params types.Params) ([]*types.Pipeline, error) - - // PipelineCreate creates a new pipeline. - PipelineCreate(user *types.Pipeline) (*types.Pipeline, error) - - // PipelineUpdate updates a pipeline. - PipelineUpdate(slug string, input *types.PipelineInput) (*types.Pipeline, error) - - // PipelineDelete deletes a pipeline. - PipelineDelete(slug string) error - - // Execution returns a execution by pipeline and slug. - Execution(pipeline, slug string) (*types.Execution, error) - - // ExecutionList returns a list of all executions by pipeline slug. - ExecutionList(pipeline string, params types.Params) ([]*types.Execution, error) - - // ExecutionCreate creates a new execution. - ExecutionCreate(pipeline string, execution *types.Execution) (*types.Execution, error) - - // ExecutionUpdate updates a execution. - ExecutionUpdate(pipeline, slug string, input *types.ExecutionInput) (*types.Execution, error) - - // ExecutionDelete deletes a execution. - ExecutionDelete(pipeline, slug string) error } // remoteError store the error payload returned diff --git a/internal/api/handler/executions/create.go b/internal/api/handler/executions/create.go deleted file mode 100644 index baffb7098..000000000 --- a/internal/api/handler/executions/create.go +++ /dev/null @@ -1,96 +0,0 @@ -// Copyright 2021 Harness Inc. All rights reserved. -// Use of this source code is governed by the Polyform Free Trial License -// that can be found in the LICENSE.md file for this repository. - -package executions - -import ( - "encoding/json" - "net/http" - "time" - - "github.com/go-chi/chi" - "github.com/gosimple/slug" - "github.com/gotidy/ptr" - "github.com/harness/gitness/internal/api/render" - "github.com/harness/gitness/internal/store" - "github.com/harness/gitness/types" - "github.com/harness/gitness/types/check" - "github.com/rs/zerolog/hlog" -) - -// HandleCreate returns an http.HandlerFunc that creates -// the object and persists to the datastore. -func HandleCreate(pipelines store.PipelineStore, executions store.ExecutionStore) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - var ( - ctx = r.Context() - log = hlog.FromRequest(r) - param = chi.URLParam(r, "pipeline") - ) - - pipeline, err := pipelines.FindSlug(ctx, param) - if err != nil { - render.NotFound(w, err) - log.Debug().Err(err). - Str("pipeline_slug", param). - Msg("pipeline not found") - return - } - - sublog := log.With(). - Int64("pipeline_id", pipeline.ID). - Str("pipeline_slug", pipeline.Slug). - Logger() - - in := new(types.ExecutionInput) - err = json.NewDecoder(r.Body).Decode(in) - if err != nil { - render.BadRequest(w, err) - sublog.Debug().Err(err). - Msg("cannot unmarshal json request") - return - } - - execution := &types.Execution{ - Pipeline: pipeline.ID, - Slug: ptr.ToString(in.Slug), - Name: ptr.ToString(in.Name), - Desc: ptr.ToString(in.Desc), - Created: time.Now().UnixMilli(), - Updated: time.Now().UnixMilli(), - } - - // if the slug is empty we can derrive - // the slug from the name. - if execution.Slug == "" { - execution.Slug = slug.Make(execution.Name) - } - - // if the name is empty we can derrive - // the name from the slug. - if execution.Name == "" { - execution.Name = execution.Slug - } - - if ok, err := check.Execution(execution); !ok { - render.BadRequest(w, err) - sublog.Debug().Err(err). - Int64("execution_id", execution.ID). - Str("execution_slug", execution.Slug). - Msg("cannot validate execution") - return - } - - err = executions.Create(ctx, execution) - if err != nil { - render.InternalError(w, err) - sublog.Error().Err(err). - Int64("execution_id", execution.ID). - Str("execution_slug", execution.Slug). - Msg("cannot create execution") - } else { - render.JSON(w, execution, 200) - } - } -} diff --git a/internal/api/handler/executions/create_test.go b/internal/api/handler/executions/create_test.go deleted file mode 100644 index f1d9c00cf..000000000 --- a/internal/api/handler/executions/create_test.go +++ /dev/null @@ -1,5 +0,0 @@ -// Copyright 2021 Harness Inc. All rights reserved. -// Use of this source code is governed by the Polyform Free Trial License -// that can be found in the LICENSE.md file for this repository. - -package executions diff --git a/internal/api/handler/executions/delete.go b/internal/api/handler/executions/delete.go deleted file mode 100644 index 1d2c68e96..000000000 --- a/internal/api/handler/executions/delete.go +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright 2021 Harness Inc. All rights reserved. -// Use of this source code is governed by the Polyform Free Trial License -// that can be found in the LICENSE.md file for this repository. - -package executions - -import ( - "net/http" - - "github.com/harness/gitness/internal/api/render" - "github.com/harness/gitness/internal/store" - - "github.com/go-chi/chi" - "github.com/rs/zerolog/hlog" -) - -// HandleDelete returns an http.HandlerFunc that deletes -// the object from the datastore. -func HandleDelete(pipelines store.PipelineStore, executions store.ExecutionStore) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - var ( - ctx = r.Context() - log = hlog.FromRequest(r) - pipelineParam = chi.URLParam(r, "pipeline") - executionParam = chi.URLParam(r, "execution") - ) - - pipeline, err := pipelines.FindSlug(ctx, pipelineParam) - if err != nil { - render.NotFound(w, err) - log.Debug().Err(err). - Str("pipeline_slug", pipelineParam). - Msg("pipeline not found") - return - } - - execution, err := executions.FindSlug(ctx, pipeline.ID, executionParam) - if err != nil { - render.NotFound(w, err) - log.Debug().Err(err). - Int64("pipeline_id", pipeline.ID). - Str("pipeline_slug", pipeline.Slug). - Str("execution_slug", executionParam). - Msg("execution not found") - return - } - - err = executions.Delete(ctx, execution) - if err != nil { - render.InternalError(w, err) - log.Error().Err(err). - Int64("pipeline_id", pipeline.ID). - Str("pipeline_slug", pipeline.Slug). - Int64("execution_id", execution.ID). - Str("execution_slug", execution.Slug). - Msg("cannot delete execution") - } else { - w.WriteHeader(http.StatusNoContent) - } - } -} diff --git a/internal/api/handler/executions/delete_test.go b/internal/api/handler/executions/delete_test.go deleted file mode 100644 index f1d9c00cf..000000000 --- a/internal/api/handler/executions/delete_test.go +++ /dev/null @@ -1,5 +0,0 @@ -// Copyright 2021 Harness Inc. All rights reserved. -// Use of this source code is governed by the Polyform Free Trial License -// that can be found in the LICENSE.md file for this repository. - -package executions diff --git a/internal/api/handler/executions/find.go b/internal/api/handler/executions/find.go deleted file mode 100644 index ad45de277..000000000 --- a/internal/api/handler/executions/find.go +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright 2021 Harness Inc. All rights reserved. -// Use of this source code is governed by the Polyform Free Trial License -// that can be found in the LICENSE.md file for this repository. - -package executions - -import ( - "net/http" - - "github.com/harness/gitness/internal/api/render" - "github.com/harness/gitness/internal/store" - - "github.com/go-chi/chi" - "github.com/rs/zerolog/hlog" -) - -// HandleFind returns an http.HandlerFunc that writes the -// json-encoded execution details to the response body. -func HandleFind(pipelines store.PipelineStore, executions store.ExecutionStore) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - var ( - ctx = r.Context() - log = hlog.FromRequest(r) - pipelineParam = chi.URLParam(r, "pipeline") - executionParam = chi.URLParam(r, "execution") - ) - - pipeline, err := pipelines.FindSlug(ctx, pipelineParam) - if err != nil { - render.NotFound(w, err) - log.Debug().Err(err). - Str("pipeline_slug", pipelineParam). - Msg("pipeline not found") - return - } - - execution, err := executions.FindSlug(ctx, pipeline.ID, executionParam) - if err != nil { - render.NotFound(w, err) - log.Debug().Err(err). - Int64("pipeline_id", pipeline.ID). - Str("pipeline_slug", pipeline.Slug). - Str("execution_slug", executionParam). - Msg("execution not found") - return - } - - render.JSON(w, execution, 200) - } -} diff --git a/internal/api/handler/executions/find_test.go b/internal/api/handler/executions/find_test.go deleted file mode 100644 index f1d9c00cf..000000000 --- a/internal/api/handler/executions/find_test.go +++ /dev/null @@ -1,5 +0,0 @@ -// Copyright 2021 Harness Inc. All rights reserved. -// Use of this source code is governed by the Polyform Free Trial License -// that can be found in the LICENSE.md file for this repository. - -package executions diff --git a/internal/api/handler/executions/list.go b/internal/api/handler/executions/list.go deleted file mode 100644 index 52abd75a2..000000000 --- a/internal/api/handler/executions/list.go +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright 2021 Harness Inc. All rights reserved. -// Use of this source code is governed by the Polyform Free Trial License -// that can be found in the LICENSE.md file for this repository. - -package executions - -import ( - "net/http" - - "github.com/harness/gitness/internal/api/render" - "github.com/harness/gitness/internal/api/request" - "github.com/harness/gitness/internal/store" - "github.com/harness/gitness/types" - - "github.com/go-chi/chi" - "github.com/rs/zerolog/hlog" -) - -// HandleList returns an http.HandlerFunc that writes a json-encoded -// list of objects to the response body. -func HandleList(pipelines store.PipelineStore, executions store.ExecutionStore) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - var ( - ctx = r.Context() - log = hlog.FromRequest(r) - slug = chi.URLParam(r, "pipeline") - page = request.ParsePage(r) - size = request.ParseSize(r) - ) - - pipeline, err := pipelines.FindSlug(ctx, slug) - if err != nil { - render.NotFound(w, err) - log.Debug().Err(err). - Str("pipeline_slug", slug). - Msg("pipeline not found") - return - } - - executions, err := executions.List(ctx, pipeline.ID, types.Params{ - Size: size, - Page: page, - }) - if err != nil { - render.InternalError(w, err) - log.Error().Err(err). - Int64("pipeline_id", pipeline.ID). - Str("pipeline_slug", pipeline.Slug). - Msg("cannot retrieve list") - } else { - render.Pagination(r, w, page, size, 0) - render.JSON(w, executions, 200) - } - } -} diff --git a/internal/api/handler/executions/list_test.go b/internal/api/handler/executions/list_test.go deleted file mode 100644 index f1d9c00cf..000000000 --- a/internal/api/handler/executions/list_test.go +++ /dev/null @@ -1,5 +0,0 @@ -// Copyright 2021 Harness Inc. All rights reserved. -// Use of this source code is governed by the Polyform Free Trial License -// that can be found in the LICENSE.md file for this repository. - -package executions diff --git a/internal/api/handler/executions/update.go b/internal/api/handler/executions/update.go deleted file mode 100644 index ac583238b..000000000 --- a/internal/api/handler/executions/update.go +++ /dev/null @@ -1,95 +0,0 @@ -// Copyright 2021 Harness Inc. All rights reserved. -// Use of this source code is governed by the Polyform Free Trial License -// that can be found in the LICENSE.md file for this repository. - -package executions - -import ( - "encoding/json" - "net/http" - "time" - - "github.com/harness/gitness/internal/api/render" - "github.com/harness/gitness/internal/store" - "github.com/harness/gitness/types" - "github.com/harness/gitness/types/check" - - "github.com/go-chi/chi" - "github.com/gotidy/ptr" - "github.com/rs/zerolog/hlog" -) - -// HandleUpdate returns an http.HandlerFunc that processes http -// requests to update the object details. -func HandleUpdate(pipelines store.PipelineStore, executions store.ExecutionStore) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - var ( - ctx = r.Context() - log = hlog.FromRequest(r) - pipelineParam = chi.URLParam(r, "pipeline") - executionParam = chi.URLParam(r, "execution") - ) - - pipeline, err := pipelines.FindSlug(ctx, pipelineParam) - if err != nil { - render.NotFound(w, err) - log.Debug().Err(err). - Str("pipeline_slug", pipelineParam). - Msg("pipeline not found") - return - } - - sublog := log.With(). - Int64("pipeline_id", pipeline.ID). - Str("pipeline_slug", pipeline.Slug). - Logger() - - execution, err := executions.FindSlug(ctx, pipeline.ID, executionParam) - if err != nil { - render.NotFound(w, err) - sublog.Debug().Err(err). - Str("execution_slug", executionParam). - Msg("execution not found") - return - } - - sublog = sublog.With(). - Str("execution_slug", execution.Slug). - Int64("execution_id", execution.ID). - Logger() - - in := new(types.ExecutionInput) - err = json.NewDecoder(r.Body).Decode(in) - if err != nil { - render.BadRequest(w, err) - sublog.Debug().Err(err). - Msg("cannot unmarshal json request") - return - } - - if in.Name != nil { - execution.Name = ptr.ToString(in.Name) - } - if in.Desc != nil { - execution.Desc = ptr.ToString(in.Desc) - } - - if ok, err := check.Execution(execution); !ok { - render.BadRequest(w, err) - sublog.Debug().Err(err). - Msg("cannot validate execution") - return - } - - execution.Updated = time.Now().UnixMilli() - - err = executions.Update(ctx, execution) - if err != nil { - render.InternalError(w, err) - sublog.Error().Err(err). - Msg("cannot update execution") - } else { - render.JSON(w, execution, 200) - } - } -} diff --git a/internal/api/handler/executions/update_test.go b/internal/api/handler/executions/update_test.go deleted file mode 100644 index f1d9c00cf..000000000 --- a/internal/api/handler/executions/update_test.go +++ /dev/null @@ -1,5 +0,0 @@ -// Copyright 2021 Harness Inc. All rights reserved. -// Use of this source code is governed by the Polyform Free Trial License -// that can be found in the LICENSE.md file for this repository. - -package executions diff --git a/internal/api/handler/pipelines/create.go b/internal/api/handler/pipelines/create.go deleted file mode 100644 index 3241e1713..000000000 --- a/internal/api/handler/pipelines/create.go +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright 2021 Harness Inc. All rights reserved. -// Use of this source code is governed by the Polyform Free Trial License -// that can be found in the LICENSE.md file for this repository. - -package pipelines - -import ( - "encoding/json" - "net/http" - "time" - - "github.com/harness/gitness/internal/api/render" - "github.com/harness/gitness/internal/store" - "github.com/harness/gitness/types" - "github.com/harness/gitness/types/check" - - "github.com/dchest/uniuri" - "github.com/gosimple/slug" - "github.com/gotidy/ptr" - "github.com/rs/zerolog/hlog" -) - -// HandleCreate returns an http.HandlerFunc that creates -// a new pipeline. -func HandleCreate(pipelines store.PipelineStore) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() - log := hlog.FromRequest(r) - - in := new(types.PipelineInput) - err := json.NewDecoder(r.Body).Decode(in) - if err != nil { - render.BadRequest(w, err) - log.Debug().Err(err). - Msg("cannot unmarshal json request") - return - } - - pipeline := &types.Pipeline{ - Slug: ptr.ToString(in.Slug), - Name: ptr.ToString(in.Name), - Desc: ptr.ToString(in.Desc), - Token: uniuri.NewLen(uniuri.UUIDLen), - Created: time.Now().UnixMilli(), - Updated: time.Now().UnixMilli(), - } - - // if the slug is empty we can derrive - // the slug from the pipeline name. - if pipeline.Slug == "" { - pipeline.Slug = slug.Make(pipeline.Name) - } - - // if the name is empty we can derrive - // the name from the pipeline slug. - if pipeline.Name == "" { - pipeline.Name = pipeline.Slug - } - - if ok, err := check.Pipeline(pipeline); !ok { - render.BadRequest(w, err) - log.Debug().Err(err). - Str("pipeline_slug", pipeline.Slug). - Msg("cannot create pipeline") - return - } - - err = pipelines.Create(ctx, pipeline) - if err != nil { - render.InternalError(w, err) - log.Error().Err(err). - Str("pipeline_name", pipeline.Name). - Str("pipeline_slug", pipeline.Slug). - Msg("cannot create pipeline") - return - } - - render.JSON(w, pipeline, 200) - } -} diff --git a/internal/api/handler/pipelines/create_test.go b/internal/api/handler/pipelines/create_test.go deleted file mode 100644 index 3b9c776b3..000000000 --- a/internal/api/handler/pipelines/create_test.go +++ /dev/null @@ -1,5 +0,0 @@ -// Copyright 2021 Harness Inc. All rights reserved. -// Use of this source code is governed by the Polyform Free Trial License -// that can be found in the LICENSE.md file for this repository. - -package pipelines diff --git a/internal/api/handler/pipelines/delete.go b/internal/api/handler/pipelines/delete.go deleted file mode 100644 index 5fce30252..000000000 --- a/internal/api/handler/pipelines/delete.go +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright 2021 Harness Inc. All rights reserved. -// Use of this source code is governed by the Polyform Free Trial License -// that can be found in the LICENSE.md file for this repository. - -package pipelines - -import ( - "net/http" - - "github.com/harness/gitness/internal/api/render" - "github.com/harness/gitness/internal/store" - - "github.com/go-chi/chi" - "github.com/rs/zerolog/hlog" -) - -// HandleDelete returns an http.HandlerFunc that deletes -// the object from the datastore. -func HandleDelete(pipelines store.PipelineStore) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() - id := chi.URLParam(r, "pipeline") - - pipeline, err := pipelines.FindSlug(ctx, id) - if err != nil { - render.NotFound(w, err) - hlog.FromRequest(r). - Debug().Err(err). - Str("pipeline_slug", id). - Msg("pipeline not found") - return - } - - err = pipelines.Delete(ctx, pipeline) - if err != nil { - render.InternalError(w, err) - hlog.FromRequest(r). - Error().Err(err). - Int64("pipeline_id", pipeline.ID). - Str("pipeline_slug", pipeline.Slug). - Msg("cannot delete pipeline") - } else { - w.WriteHeader(http.StatusNoContent) - } - } -} diff --git a/internal/api/handler/pipelines/delete_test.go b/internal/api/handler/pipelines/delete_test.go deleted file mode 100644 index 3b9c776b3..000000000 --- a/internal/api/handler/pipelines/delete_test.go +++ /dev/null @@ -1,5 +0,0 @@ -// Copyright 2021 Harness Inc. All rights reserved. -// Use of this source code is governed by the Polyform Free Trial License -// that can be found in the LICENSE.md file for this repository. - -package pipelines diff --git a/internal/api/handler/pipelines/find.go b/internal/api/handler/pipelines/find.go deleted file mode 100644 index a909811ef..000000000 --- a/internal/api/handler/pipelines/find.go +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright 2021 Harness Inc. All rights reserved. -// Use of this source code is governed by the Polyform Free Trial License -// that can be found in the LICENSE.md file for this repository. - -package pipelines - -import ( - "net/http" - - "github.com/harness/gitness/internal/api/render" - "github.com/harness/gitness/internal/store" - "github.com/harness/gitness/types" - "github.com/rs/zerolog/hlog" - - "github.com/go-chi/chi" -) - -type pipelineToken struct { - *types.Pipeline - Token string `json:"token"` -} - -// HandleFind returns an http.HandlerFunc that writes the -// json-encoded pipeline details to the response body. -func HandleFind(pipelines store.PipelineStore) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() - id := chi.URLParam(r, "pipeline") - - pipeline, err := pipelines.FindSlug(ctx, id) - if err != nil { - render.NotFound(w, err) - hlog.FromRequest(r). - Debug().Err(err). - Str("pipeline_slug", id). - Msg("pipeline not found") - return - } - - // if the caller requests the pipeline details without - // the token, return the token object as-is. - if r.FormValue("token") != "true" { - render.JSON(w, pipeline, 200) - return - } - - // if the caller requests the pipeline details with - // the token then it can be safely included. - render.JSON(w, &pipelineToken{pipeline, pipeline.Token}, 200) - } -} diff --git a/internal/api/handler/pipelines/find_test.go b/internal/api/handler/pipelines/find_test.go deleted file mode 100644 index 3b9c776b3..000000000 --- a/internal/api/handler/pipelines/find_test.go +++ /dev/null @@ -1,5 +0,0 @@ -// Copyright 2021 Harness Inc. All rights reserved. -// Use of this source code is governed by the Polyform Free Trial License -// that can be found in the LICENSE.md file for this repository. - -package pipelines diff --git a/internal/api/handler/pipelines/list.go b/internal/api/handler/pipelines/list.go deleted file mode 100644 index 938e84752..000000000 --- a/internal/api/handler/pipelines/list.go +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright 2021 Harness Inc. All rights reserved. -// Use of this source code is governed by the Polyform Free Trial License -// that can be found in the LICENSE.md file for this repository. - -package pipelines - -import ( - "net/http" - - "github.com/harness/gitness/internal/api/render" - "github.com/harness/gitness/internal/api/request" - "github.com/harness/gitness/internal/store" - "github.com/harness/gitness/types" - - "github.com/rs/zerolog/log" -) - -// HandleList returns an http.HandlerFunc that writes a json-encoded -// list of pipelines to the response body. -func HandleList(pipelines store.PipelineStore) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - var ( - page = request.ParsePage(r) - size = request.ParseSize(r) - ctx = r.Context() - ) - - viewer, _ := request.UserFrom(ctx) - list, err := pipelines.List(ctx, viewer.ID, types.Params{ - Page: page, - Size: size, - }) - if err != nil { - render.InternalError(w, err) - log.Ctx(ctx).Error(). - Err(err).Msg("cannot list pipelines") - } else { - render.Pagination(r, w, page, size, 0) - render.JSON(w, list, 200) - } - } -} diff --git a/internal/api/handler/pipelines/list_test.go b/internal/api/handler/pipelines/list_test.go deleted file mode 100644 index b564295b4..000000000 --- a/internal/api/handler/pipelines/list_test.go +++ /dev/null @@ -1,87 +0,0 @@ -// Copyright 2021 Harness Inc. All rights reserved. -// Use of this source code is governed by the Polyform Free Trial License -// that can be found in the LICENSE.md file for this repository. - -package pipelines - -import ( - "encoding/json" - "net/http" - "net/http/httptest" - "testing" - - "github.com/harness/gitness/internal/api/render" - "github.com/harness/gitness/internal/api/request" - "github.com/harness/gitness/mocks" - "github.com/harness/gitness/types" - - "github.com/golang/mock/gomock" - "github.com/google/go-cmp/cmp" -) - -func TestHandleList(t *testing.T) { - controller := gomock.NewController(t) - defer controller.Finish() - - mockUser := &types.User{ - ID: 1, - Email: "octocat@github.com", - } - - mockList := []*types.Pipeline{ - { - Name: "test", - Desc: "desc", - }, - } - - projs := mocks.NewMockPipelineStore(controller) - projs.EXPECT().List(gomock.Any(), mockUser.ID, gomock.Any()).Return(mockList, nil) - - w := httptest.NewRecorder() - r := httptest.NewRequest("GET", "/", nil) - r = r.WithContext( - request.WithUser(r.Context(), mockUser), - ) - - HandleList(projs)(w, r) - if got, want := w.Code, http.StatusOK; want != got { - t.Errorf("Want response code %d, got %d", want, got) - } - - got, want := []*types.Pipeline{}, mockList - json.NewDecoder(w.Body).Decode(&got) - if diff := cmp.Diff(got, want); len(diff) > 0 { - t.Errorf(diff) - } -} - -func TestListErr(t *testing.T) { - controller := gomock.NewController(t) - defer controller.Finish() - - mockUser := &types.User{ - ID: 1, - Email: "octocat@github.com", - } - - projs := mocks.NewMockPipelineStore(controller) - projs.EXPECT().List(gomock.Any(), mockUser.ID, gomock.Any()).Return(nil, render.ErrNotFound) - - w := httptest.NewRecorder() - r := httptest.NewRequest("GET", "/", nil) - r = r.WithContext( - request.WithUser(r.Context(), mockUser), - ) - - HandleList(projs)(w, r) - if got, want := w.Code, http.StatusInternalServerError; want != got { - t.Errorf("Want response code %d, got %d", want, got) - } - - got, want := &render.Error{}, render.ErrNotFound - json.NewDecoder(w.Body).Decode(got) - if diff := cmp.Diff(got, want); len(diff) > 0 { - t.Errorf(diff) - } -} diff --git a/internal/api/handler/pipelines/update.go b/internal/api/handler/pipelines/update.go deleted file mode 100644 index 9bc16951f..000000000 --- a/internal/api/handler/pipelines/update.go +++ /dev/null @@ -1,79 +0,0 @@ -// Copyright 2021 Harness Inc. All rights reserved. -// Use of this source code is governed by the Polyform Free Trial License -// that can be found in the LICENSE.md file for this repository. - -package pipelines - -import ( - "encoding/json" - "net/http" - "time" - - "github.com/harness/gitness/internal/api/render" - "github.com/harness/gitness/internal/store" - "github.com/harness/gitness/types" - "github.com/harness/gitness/types/check" - - "github.com/go-chi/chi" - "github.com/gotidy/ptr" - "github.com/rs/zerolog/hlog" -) - -// HandleUpdate returns an http.HandlerFunc that processes http -// requests to update the pipeline details. -func HandleUpdate(pipelines store.PipelineStore) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() - log := hlog.FromRequest(r) - id := chi.URLParam(r, "pipeline") - - pipeline, err := pipelines.FindSlug(ctx, id) - if err != nil { - render.NotFound(w, err) - log.Debug().Err(err). - Str("pipeline_slug", id). - Msg("pipeline not found") - return - } - - in := new(types.PipelineInput) - err = json.NewDecoder(r.Body).Decode(in) - if err != nil { - render.BadRequest(w, err) - log.Debug().Err(err). - Int64("pipeline_id", pipeline.ID). - Str("pipeline_slug", pipeline.Slug). - Msg("cannot unmarshal json request") - return - } - - if in.Name != nil { - pipeline.Name = ptr.ToString(in.Name) - } - if in.Desc != nil { - pipeline.Desc = ptr.ToString(in.Desc) - } - - if ok, err := check.Pipeline(pipeline); !ok { - render.BadRequest(w, err) - log.Debug().Err(err). - Int64("pipeline_id", pipeline.ID). - Str("pipeline_slug", pipeline.Slug). - Msg("cannot update pipeline") - return - } - - pipeline.Updated = time.Now().UnixMilli() - - err = pipelines.Update(ctx, pipeline) - if err != nil { - render.InternalError(w, err) - log.Error().Err(err). - Int64("pipeline_id", pipeline.ID). - Str("pipeline_slug", pipeline.Slug). - Msg("cannot update the pipeline") - } else { - render.JSON(w, pipeline, 200) - } - } -} diff --git a/internal/api/handler/pipelines/update_test.go b/internal/api/handler/pipelines/update_test.go deleted file mode 100644 index 3b9c776b3..000000000 --- a/internal/api/handler/pipelines/update_test.go +++ /dev/null @@ -1,5 +0,0 @@ -// Copyright 2021 Harness Inc. All rights reserved. -// Use of this source code is governed by the Polyform Free Trial License -// that can be found in the LICENSE.md file for this repository. - -package pipelines diff --git a/internal/api/handler/projects/find.go b/internal/api/handler/projects/find.go deleted file mode 100644 index a0910b614..000000000 --- a/internal/api/handler/projects/find.go +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2021 Harness Inc. All rights reserved. -// Use of this source code is governed by the Polyform Free Trial License -// that can be found in the LICENSE.md file for this repository. - -package projects - -import ( - "net/http" - - "github.com/harness/gitness/internal/api/render/platform" - "github.com/harness/gitness/types" -) - -// standalone version of the product uses a single, -// hard-coded project as its default. -var defaultProject = &types.Project{ - Identifier: "default", - Color: "#0063f7", - Desc: "Default Project", - Name: "Default Project", - Modules: []string{}, - Org: "default", - Tags: map[string]string{}, -} - -// HandleFind returns an http.HandlerFunc that writes json-encoded -// project to the http response body. -func HandleFind() http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - platform.RenderResource(w, defaultProject, 200) - } -} diff --git a/internal/api/handler/projects/find_test.go b/internal/api/handler/projects/find_test.go deleted file mode 100644 index e2baed957..000000000 --- a/internal/api/handler/projects/find_test.go +++ /dev/null @@ -1,5 +0,0 @@ -// Copyright 2021 Harness Inc. All rights reserved. -// Use of this source code is governed by the Polyform Free Trial License -// that can be found in the LICENSE.md file for this repository. - -package projects diff --git a/internal/api/handler/projects/list.go b/internal/api/handler/projects/list.go deleted file mode 100644 index 603b1be65..000000000 --- a/internal/api/handler/projects/list.go +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2021 Harness Inc. All rights reserved. -// Use of this source code is governed by the Polyform Free Trial License -// that can be found in the LICENSE.md file for this repository. - -package projects - -import ( - "net/http" - - "github.com/harness/gitness/internal/api/render/platform" - "github.com/harness/gitness/types" -) - -// standalone version of the product uses a single, -// hard-coded project as its default. -var defaultProjectList = &types.ProjectList{ - Data: []*types.Project{defaultProject}, - Empty: false, - PageIndex: 1, - PageItemCount: 1, - PageSize: 1, - TotalItems: 1, - TotalPages: 1, -} - -// HandleList returns an http.HandlerFunc that writes json-encoded -// project list to the http response body. -func HandleList() http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - platform.RenderResource(w, defaultProjectList, 200) - } -} diff --git a/internal/api/handler/projects/list_test.go b/internal/api/handler/projects/list_test.go deleted file mode 100644 index e2baed957..000000000 --- a/internal/api/handler/projects/list_test.go +++ /dev/null @@ -1,5 +0,0 @@ -// Copyright 2021 Harness Inc. All rights reserved. -// Use of this source code is governed by the Polyform Free Trial License -// that can be found in the LICENSE.md file for this repository. - -package projects diff --git a/internal/api/openapi/execution.go b/internal/api/openapi/execution.go deleted file mode 100644 index 5a13c1e55..000000000 --- a/internal/api/openapi/execution.go +++ /dev/null @@ -1,111 +0,0 @@ -// Copyright 2021 Harness Inc. All rights reserved. -// Use of this source code is governed by the Polyform Free Trial License -// that can be found in the LICENSE.md file for this repository. - -package openapi - -import ( - "net/http" - - "github.com/harness/gitness/internal/api/render" - "github.com/harness/gitness/types" - - "github.com/swaggest/openapi-go/openapi3" -) - -type ( - // request to find or delete a execution. - executionRequest struct { - Pipeline string `path:"pipeline"` - Execution string `path:"execution"` - - // include account parameters - baseRequest - } - - // request to list all executions - executionListRequest struct { - Pipeline string `path:"pipeline"` - - // include pagination - paginationRequest - - // include account parameters - baseRequest - } - - // request to create a execution. - executionCreateRequest struct { - Pipeline string `path:"pipeline"` - - // include request body input. - types.ExecutionInput - - // include account parameters - baseRequest - } - - // request to update a execution. - executionUpdateRequest struct { - Pipeline string `path:"pipeline"` - Execution string `path:"execution"` - - // include request body input. - types.ExecutionInput - - // include account parameters - baseRequest - } -) - -// helper function that constructs the openapi specification -// for execution resources. -func buildExecution(reflector *openapi3.Reflector) { - - opFind := openapi3.Operation{} - opFind.WithTags("execution") - opFind.WithMapOfAnything(map[string]interface{}{"operationId": "getExecution"}) - reflector.SetRequest(&opFind, new(executionRequest), http.MethodGet) - reflector.SetJSONResponse(&opFind, new(types.Execution), http.StatusOK) - reflector.SetJSONResponse(&opFind, new(render.Error), http.StatusInternalServerError) - reflector.SetJSONResponse(&opFind, new(render.Error), http.StatusNotFound) - reflector.Spec.AddOperation(http.MethodGet, "/pipelines/{pipeline}/executions/{execution}", opFind) - - opList := openapi3.Operation{} - opList.WithTags("execution") - opList.WithMapOfAnything(map[string]interface{}{"operationId": "listExecutions"}) - reflector.SetRequest(&opList, new(executionListRequest), http.MethodGet) - reflector.SetJSONResponse(&opList, new([]*types.Execution), http.StatusOK) - reflector.SetJSONResponse(&opList, new(render.Error), http.StatusInternalServerError) - reflector.SetJSONResponse(&opList, new(render.Error), http.StatusNotFound) - reflector.Spec.AddOperation(http.MethodGet, "/pipelines/{pipeline}/executions", opList) - - opCreate := openapi3.Operation{} - opCreate.WithTags("execution") - opCreate.WithMapOfAnything(map[string]interface{}{"operationId": "createExecution"}) - reflector.SetRequest(&opCreate, new(executionCreateRequest), http.MethodPost) - reflector.SetJSONResponse(&opCreate, new(types.Execution), http.StatusOK) - reflector.SetJSONResponse(&opCreate, new(render.Error), http.StatusBadRequest) - reflector.SetJSONResponse(&opCreate, new(render.Error), http.StatusInternalServerError) - reflector.SetJSONResponse(&opCreate, new(render.Error), http.StatusNotFound) - reflector.Spec.AddOperation(http.MethodPost, "/pipelines/{pipeline}/executions", opCreate) - - opUpdate := openapi3.Operation{} - opUpdate.WithTags("execution") - opUpdate.WithMapOfAnything(map[string]interface{}{"operationId": "updateExecution"}) - reflector.SetRequest(&opUpdate, new(executionUpdateRequest), http.MethodPatch) - reflector.SetJSONResponse(&opUpdate, new(types.Execution), http.StatusOK) - reflector.SetJSONResponse(&opUpdate, new(render.Error), http.StatusBadRequest) - reflector.SetJSONResponse(&opUpdate, new(render.Error), http.StatusInternalServerError) - reflector.SetJSONResponse(&opUpdate, new(render.Error), http.StatusNotFound) - reflector.Spec.AddOperation(http.MethodPatch, "/pipelines/{pipeline}/executions/{execution}", opUpdate) - - opDelete := openapi3.Operation{} - opDelete.WithTags("execution") - opDelete.WithMapOfAnything(map[string]interface{}{"operationId": "deleteExecution"}) - reflector.SetRequest(&opDelete, new(executionRequest), http.MethodDelete) - reflector.SetJSONResponse(&opDelete, nil, http.StatusNoContent) - reflector.SetJSONResponse(&opDelete, new(render.Error), http.StatusInternalServerError) - reflector.SetJSONResponse(&opDelete, new(render.Error), http.StatusNotFound) - reflector.Spec.AddOperation(http.MethodDelete, "/pipelines/{pipeline}/executions/{execution}", opDelete) -} diff --git a/internal/api/openapi/openapi.go b/internal/api/openapi/openapi.go index 67a097a69..4bc86f543 100644 --- a/internal/api/openapi/openapi.go +++ b/internal/api/openapi/openapi.go @@ -76,11 +76,8 @@ func Generate() *openapi3.Spec { // buildAccount(&reflector) - buildPipeline(&reflector) - buildExecution(&reflector) buildUser(&reflector) buildUsers(&reflector) - buildProjects(&reflector) // // define security scheme diff --git a/internal/api/openapi/pipeline.go b/internal/api/openapi/pipeline.go deleted file mode 100644 index 0075300bb..000000000 --- a/internal/api/openapi/pipeline.go +++ /dev/null @@ -1,103 +0,0 @@ -// Copyright 2021 Harness Inc. All rights reserved. -// Use of this source code is governed by the Polyform Free Trial License -// that can be found in the LICENSE.md file for this repository. - -package openapi - -import ( - "net/http" - - "github.com/harness/gitness/internal/api/render" - "github.com/harness/gitness/types" - - "github.com/swaggest/openapi-go/openapi3" -) - -type ( - // request to find or delete a pipeline. - pipelineRequest struct { - Param string `path:"pipeline"` - - // include account parameters - baseRequest - } - - pipelineListRequest struct { - // include account parameters - baseRequest - - // include pagination parameters - paginationRequest - } - - // request to update a pipeline. - pipelineUpdateRequest struct { - Param string `path:"pipeline"` - - // include request body input. - types.PipelineInput - - // include account parameters - baseRequest - } - - // request to create a pipeline. - pipelineCreateRequest struct { - // include account parameters - baseRequest - - // include request body input. - types.PipelineInput - } -) - -// helper function that constructs the openapi specification -// for pipeline resources. -func buildPipeline(reflector *openapi3.Reflector) { - - opFind := openapi3.Operation{} - opFind.WithTags("pipeline") - opFind.WithMapOfAnything(map[string]interface{}{"operationId": "getPipeline"}) - reflector.SetRequest(&opFind, new(pipelineRequest), http.MethodGet) - reflector.SetJSONResponse(&opFind, new(types.Pipeline), http.StatusOK) - reflector.SetJSONResponse(&opFind, new(render.Error), http.StatusInternalServerError) - reflector.SetJSONResponse(&opFind, new(render.Error), http.StatusNotFound) - reflector.Spec.AddOperation(http.MethodGet, "/pipelines/{pipeline}", opFind) - - onList := openapi3.Operation{} - onList.WithTags("pipeline") - onList.WithMapOfAnything(map[string]interface{}{"operationId": "listPipelines"}) - reflector.SetRequest(&onList, new(pipelineListRequest), http.MethodGet) - reflector.SetJSONResponse(&onList, new([]*types.Pipeline), http.StatusOK) - reflector.SetJSONResponse(&onList, new(render.Error), http.StatusInternalServerError) - reflector.Spec.AddOperation(http.MethodGet, "/pipelines", onList) - - opCreate := openapi3.Operation{} - opCreate.WithTags("pipeline") - opCreate.WithMapOfAnything(map[string]interface{}{"operationId": "createPipeline"}) - reflector.SetRequest(&opCreate, new(pipelineCreateRequest), http.MethodPost) - reflector.SetJSONResponse(&opCreate, new(types.Pipeline), http.StatusOK) - reflector.SetJSONResponse(&opCreate, new(render.Error), http.StatusBadRequest) - reflector.SetJSONResponse(&opCreate, new(render.Error), http.StatusInternalServerError) - reflector.SetJSONResponse(&opCreate, new(render.Error), http.StatusNotFound) - reflector.Spec.AddOperation(http.MethodPost, "/pipelines", opCreate) - - opUpdate := openapi3.Operation{} - opUpdate.WithTags("pipeline") - opUpdate.WithMapOfAnything(map[string]interface{}{"operationId": "updatePipeline"}) - reflector.SetRequest(&opUpdate, new(pipelineUpdateRequest), http.MethodPatch) - reflector.SetJSONResponse(&opUpdate, new(types.Pipeline), http.StatusOK) - reflector.SetJSONResponse(&opUpdate, new(render.Error), http.StatusBadRequest) - reflector.SetJSONResponse(&opUpdate, new(render.Error), http.StatusInternalServerError) - reflector.SetJSONResponse(&opUpdate, new(render.Error), http.StatusNotFound) - reflector.Spec.AddOperation(http.MethodPatch, "/pipelines/{pipeline}", opUpdate) - - opDelete := openapi3.Operation{} - opDelete.WithTags("pipeline") - opDelete.WithMapOfAnything(map[string]interface{}{"operationId": "deletePipeline"}) - reflector.SetRequest(&opDelete, new(pipelineRequest), http.MethodDelete) - reflector.SetJSONResponse(&opDelete, nil, http.StatusNoContent) - reflector.SetJSONResponse(&opDelete, new(render.Error), http.StatusInternalServerError) - reflector.SetJSONResponse(&opDelete, new(render.Error), http.StatusNotFound) - reflector.Spec.AddOperation(http.MethodDelete, "/pipelines/{pipeline}", opDelete) -} diff --git a/internal/api/openapi/projects.go b/internal/api/openapi/projects.go deleted file mode 100644 index b2f3db8b3..000000000 --- a/internal/api/openapi/projects.go +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright 2021 Harness Inc. All rights reserved. -// Use of this source code is governed by the Polyform Free Trial License -// that can be found in the LICENSE.md file for this repository. - -package openapi - -import ( - "net/http" - - "github.com/harness/gitness/internal/api/render" - "github.com/harness/gitness/types" - - "github.com/swaggest/openapi-go/openapi3" -) - -type ( - projectRequest struct { - Project string `path:"project"` - - // include base request - baseRequest - } - - projectListRequest struct { - // include pagination request - paginationRequest - - // include base request - baseRequest - } - - projectResponse struct { - Data types.Project `json:"data"` - Status string `json:"status" enum:"SUCCESS,FAILURE,ERROR"` - } - - projectListResponse struct { - Data types.ProjectList `json:"data"` - Status string `json:"status" enum:"SUCCESS,FAILURE,ERROR"` - } -) - -// helper function that constructs the openapi specification -// for project resources. -func buildProjects(reflector *openapi3.Reflector) { - - opFind := openapi3.Operation{} - opFind.WithTags("projects") - opFind.WithMapOfAnything(map[string]interface{}{"operationId": "getProject"}) - reflector.SetRequest(&opFind, new(projectRequest), http.MethodGet) - reflector.SetJSONResponse(&opFind, new(projectResponse), http.StatusOK) - reflector.SetJSONResponse(&opFind, new(render.Error), http.StatusInternalServerError) - reflector.Spec.AddOperation(http.MethodGet, "/api/projects/{project}", opFind) - - opList := openapi3.Operation{} - opList.WithTags("projects", "user") - opList.WithMapOfAnything(map[string]interface{}{"operationId": "listProjects"}) - reflector.SetRequest(&opList, new(projectListRequest), http.MethodGet) - reflector.SetJSONResponse(&opList, new(projectListResponse), http.StatusOK) - reflector.SetJSONResponse(&opList, new(render.Error), http.StatusInternalServerError) - reflector.Spec.AddOperation(http.MethodGet, "/api/user/projects", opList) - -} diff --git a/internal/router/router.go b/internal/router/router.go index 8f469e1af..6f4ce3796 100644 --- a/internal/router/router.go +++ b/internal/router/router.go @@ -11,9 +11,6 @@ import ( "net/http" "github.com/harness/gitness/internal/api/handler/account" - "github.com/harness/gitness/internal/api/handler/executions" - "github.com/harness/gitness/internal/api/handler/pipelines" - "github.com/harness/gitness/internal/api/handler/projects" "github.com/harness/gitness/internal/api/handler/system" "github.com/harness/gitness/internal/api/handler/user" "github.com/harness/gitness/internal/api/handler/users" @@ -39,8 +36,6 @@ var nocontext = context.Background() // New returns a new http.Handler that routes traffic // to the appropriate http.Handlers. func New( - executionStore store.ExecutionStore, - pipelineStore store.PipelineStore, userStore store.UserStore, systemStore store.SystemStore, ) http.Handler { @@ -89,28 +84,6 @@ func New( r.Use(cors.Handler) r.Route("/v1", func(r chi.Router) { - // pipeline endpoints - r.Route("/pipelines", func(r chi.Router) { - r.Use(auth) - r.Get("/", pipelines.HandleList(pipelineStore)) - r.Post("/", pipelines.HandleCreate(pipelineStore)) - - // pipeline endpoints - r.Route("/{pipeline}", func(r chi.Router) { - r.Get("/", pipelines.HandleFind(pipelineStore)) - r.Patch("/", pipelines.HandleUpdate(pipelineStore)) - r.Delete("/", pipelines.HandleDelete(pipelineStore)) - - // execution endpoints - r.Route("/executions", func(r chi.Router) { - r.Get("/", executions.HandleList(pipelineStore, executionStore)) - r.Post("/", executions.HandleCreate(pipelineStore, executionStore)) - r.Get("/{execution}", executions.HandleFind(pipelineStore, executionStore)) - r.Patch("/{execution}", executions.HandleUpdate(pipelineStore, executionStore)) - r.Delete("/{execution}", executions.HandleDelete(pipelineStore, executionStore)) - }) - }) - }) // authenticated user endpoints r.Route("/user", func(r chi.Router) { @@ -152,17 +125,10 @@ func New( }) - // harness platform project endpoints - r.Route("/projects", func(r chi.Router) { - r.Use(auth) - r.Get("/{project}", projects.HandleFind()) - }) - // harness platform project endpoints r.Route("/user", func(r chi.Router) { r.Use(auth) r.Get("/currentUser", user.HandleCurrent()) - r.Get("/projects", projects.HandleList()) }) }) diff --git a/internal/store/database/execution.go b/internal/store/database/execution.go deleted file mode 100644 index f49ed8b36..000000000 --- a/internal/store/database/execution.go +++ /dev/null @@ -1,145 +0,0 @@ -// Copyright 2021 Harness Inc. All rights reserved. -// Use of this source code is governed by the Polyform Free Trial License -// that can be found in the LICENSE.md file for this repository. - -package database - -import ( - "context" - - "github.com/harness/gitness/internal/store" - "github.com/harness/gitness/types" - - "github.com/jmoiron/sqlx" -) - -var _ store.ExecutionStore = (*ExecutionStore)(nil) - -// NewExecutionStore returns a new ExecutionStore. -func NewExecutionStore(db *sqlx.DB) *ExecutionStore { - return &ExecutionStore{db} -} - -// ExecutionStore implements a ExecutionStore backed by a relational -// database. -type ExecutionStore struct { - db *sqlx.DB -} - -// Find finds the execution by id. -func (s *ExecutionStore) Find(ctx context.Context, id int64) (*types.Execution, error) { - dst := new(types.Execution) - err := s.db.Get(dst, executionSelectID, id) - return dst, err -} - -// FindSlug finds the execution by pipeline id and slug. -func (s *ExecutionStore) FindSlug(ctx context.Context, id int64, slug string) (*types.Execution, error) { - dst := new(types.Execution) - err := s.db.Get(dst, executionSelectSlug, id, slug) - return dst, err -} - -// List returns a list of executions. -func (s *ExecutionStore) List(ctx context.Context, id int64, opts types.Params) ([]*types.Execution, error) { - dst := []*types.Execution{} - err := s.db.Select(&dst, executionSelect, id, limit(opts.Size), offset(opts.Page, opts.Size)) - return dst, err -} - -// Create saves the execution details. -func (s *ExecutionStore) Create(ctx context.Context, execution *types.Execution) error { - query, arg, err := s.db.BindNamed(executionInsert, execution) - if err != nil { - return err - } - return s.db.QueryRow(query, arg...).Scan(&execution.ID) -} - -// Update updates the execution details. -func (s *ExecutionStore) Update(ctx context.Context, execution *types.Execution) error { - query, arg, err := s.db.BindNamed(executionUpdate, execution) - if err != nil { - return err - } - _, err = s.db.Exec(query, arg...) - return err -} - -// Delete deletes the execution. -func (s *ExecutionStore) Delete(ctx context.Context, execution *types.Execution) error { - tx, err := s.db.BeginTx(ctx, nil) - if err != nil { - return err - } - defer tx.Rollback() - // delete the execution - if _, err := tx.Exec(executionDelete, execution.ID); err != nil { - return err - } - return tx.Commit() -} - -const executionBase = ` -SELECT - execution_id -,execution_pipeline_id -,execution_slug -,execution_name -,execution_desc -,execution_created -,execution_updated -FROM executions -` - -const executionSelect = executionBase + ` -WHERE execution_pipeline_id = $1 -ORDER BY execution_name ASC -LIMIT $2 OFFSET $3 -` - -const executionSelectID = executionBase + ` -WHERE execution_id = $1 -` - -const executionSelectSlug = executionBase + ` -WHERE execution_pipeline_id = $1 - AND execution_slug = $2 -` - -const executionInsert = ` -INSERT INTO executions ( - execution_pipeline_id -,execution_slug -,execution_name -,execution_desc -,execution_created -,execution_updated -) values ( - :execution_pipeline_id -,:execution_slug -,:execution_name -,:execution_desc -,:execution_created -,:execution_updated -) RETURNING execution_id -` - -const executionUpdate = ` -UPDATE executions -SET - execution_name = :execution_name -,execution_desc = :execution_desc -,execution_updated = :execution_updated -WHERE execution_id = :execution_id -` - -const executionDelete = ` -DELETE FROM executions -WHERE execution_id = $1 -` - -const executionDeletePipeline = ` -DELETE FROM executions -WHERE execution_pipeline_id = $1 -` diff --git a/internal/store/database/execution_sync.go b/internal/store/database/execution_sync.go deleted file mode 100644 index e270bc818..000000000 --- a/internal/store/database/execution_sync.go +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright 2021 Harness Inc. All rights reserved. -// Use of this source code is governed by the Polyform Free Trial License -// that can be found in the LICENSE.md file for this repository. - -package database - -import ( - "context" - - "github.com/harness/gitness/internal/store" - "github.com/harness/gitness/internal/store/database/mutex" - "github.com/harness/gitness/types" -) - -var _ store.ExecutionStore = (*ExecutionStoreSync)(nil) - -// NewExecutionStoreSync returns a new ExecutionStoreSync. -func NewExecutionStoreSync(store *ExecutionStore) *ExecutionStoreSync { - return &ExecutionStoreSync{base: store} -} - -// ExecutionStoreSync synronizes read and write access to the -// execution store. This prevents race conditions when the database -// type is sqlite3. -type ExecutionStoreSync struct{ base *ExecutionStore } - -// Find finds the execution by id. -func (s *ExecutionStoreSync) Find(ctx context.Context, id int64) (*types.Execution, error) { - mutex.RLock() - defer mutex.RUnlock() - return s.base.Find(ctx, id) -} - -// FindSlug finds the execution by pipeline id and slug. -func (s *ExecutionStoreSync) FindSlug(ctx context.Context, id int64, slug string) (*types.Execution, error) { - mutex.RLock() - defer mutex.RUnlock() - return s.base.FindSlug(ctx, id, slug) -} - -// List returns a list of executions. -func (s *ExecutionStoreSync) List(ctx context.Context, id int64, opts types.Params) ([]*types.Execution, error) { - mutex.RLock() - defer mutex.RUnlock() - return s.base.List(ctx, id, opts) -} - -// Create saves the execution details. -func (s *ExecutionStoreSync) Create(ctx context.Context, execution *types.Execution) error { - mutex.Lock() - defer mutex.Unlock() - return s.base.Create(ctx, execution) -} - -// Update updates the execution details. -func (s *ExecutionStoreSync) Update(ctx context.Context, execution *types.Execution) error { - mutex.Lock() - defer mutex.Unlock() - return s.base.Update(ctx, execution) -} - -// Delete deletes the execution. -func (s *ExecutionStoreSync) Delete(ctx context.Context, execution *types.Execution) error { - mutex.Lock() - defer mutex.Unlock() - return s.base.Delete(ctx, execution) -} diff --git a/internal/store/database/execution_test.go b/internal/store/database/execution_test.go deleted file mode 100644 index 5f0ba2235..000000000 --- a/internal/store/database/execution_test.go +++ /dev/null @@ -1,214 +0,0 @@ -// Copyright 2021 Harness Inc. All rights reserved. -// Use of this source code is governed by the Polyform Free Trial License -// that can be found in the LICENSE.md file for this repository. - -package database - -import ( - "database/sql" - "testing" - - "github.com/google/go-cmp/cmp" - "github.com/google/go-cmp/cmp/cmpopts" - "github.com/harness/gitness/internal/store" - "github.com/harness/gitness/types" - "github.com/jmoiron/sqlx" -) - -// execution fields to ignore in test comparisons -var executionIgnore = cmpopts.IgnoreFields(types.Execution{}, - "ID", "Created", "Updated") - -func TestExecution(t *testing.T) { - db, err := connect() - if err != nil { - t.Error(err) - return - } - defer db.Close() - if err := seed(db); err != nil { - t.Error(err) - return - } - - if _, err := newPipelineStoreSeeded(db); err != nil { - t.Error(err) - return - } - - store := NewExecutionStoreSync(NewExecutionStore(db)) - t.Run("create", testExecutionCreate(store)) - t.Run("find", testExecutionFind(store)) - t.Run("list", testExecutionList(store)) - t.Run("update", testExecutionUpdate(store)) - t.Run("delete", testExecutionDelete(store)) -} - -// this test creates entries in the database and confirms -// the primary keys were auto-incremented. -func testExecutionCreate(store store.ExecutionStore) func(t *testing.T) { - return func(t *testing.T) { - vv := []*types.Execution{} - if err := unmarshal("testdata/executions.json", &vv); err != nil { - t.Error(err) - return - } - - // create row 1 - v := vv[0] - if err := store.Create(noContext, v); err != nil { - t.Error(err) - return - } - if v.ID == 0 { - t.Errorf("Want autoincremented primary key") - } - // create row 2 - v = vv[1] - if err := store.Create(noContext, v); err != nil { - t.Error(err) - return - } - // create row 3 - v = vv[2] - if err := store.Create(noContext, v); err != nil { - t.Error(err) - return - } - - t.Run("duplicate slug", func(t *testing.T) { - // reset the ID so that a new row is created - // using the same slug - v.ID = 0 - if err := store.Create(noContext, v); err == nil { - t.Errorf("Expect duplicate row error") - return - } - }) - } -} - -// this test fetches executions from the database by id and key -// and compares to the expected results (sourced from a json file) -// to ensure all columns are correctly mapped. -func testExecutionFind(store store.ExecutionStore) func(t *testing.T) { - return func(t *testing.T) { - vv := []*types.Execution{} - if err := unmarshal("testdata/executions.json", &vv); err != nil { - t.Error(err) - return - } - want := vv[0] - - t.Run("id", func(t *testing.T) { - got, err := store.Find(noContext, 1) - if err != nil { - t.Error(err) - return - } - if diff := cmp.Diff(got, want, executionIgnore); len(diff) != 0 { - t.Errorf(diff) - return - } - }) - - t.Run("slug", func(t *testing.T) { - got, err := store.FindSlug(noContext, want.Pipeline, want.Slug) - if err != nil { - t.Error(err) - return - } - if diff := cmp.Diff(got, want, executionIgnore); len(diff) != 0 { - t.Errorf(diff) - return - } - }) - } -} - -// this test fetches a list of executions from the database -// and compares to the expected results (sourced from a json file) -// to ensure all columns are correctly mapped. -func testExecutionList(store store.ExecutionStore) func(t *testing.T) { - return func(t *testing.T) { - want := []*types.Execution{} - if err := unmarshal("testdata/executions.json", &want); err != nil { - t.Error(err) - return - } - got, err := store.List(noContext, 2, types.Params{Size: 25, Page: 0}) - if err != nil { - t.Error(err) - return - } - - if diff := cmp.Diff(got, want[1:], executionIgnore); len(diff) != 0 { - t.Errorf(diff) - debug(t, got) - return - } - } -} - -// this test updates a execution in the database and then fetches -// the execution and confirms the column was updated as expected. -func testExecutionUpdate(store store.ExecutionStore) func(t *testing.T) { - return func(t *testing.T) { - before, err := store.Find(noContext, 1) - if err != nil { - t.Error(err) - return - } - before.Desc = "updated description" - if err := store.Update(noContext, before); err != nil { - t.Error(err) - return - } - after, err := store.Find(noContext, 1) - if err != nil { - t.Error(err) - return - } - - if diff := cmp.Diff(before, after, executionIgnore); len(diff) != 0 { - t.Errorf(diff) - return - } - } -} - -// this test deletes a execution from the database and then confirms -// subsequent attempts to fetch the deleted execution result in -// a sql.ErrNoRows error. -func testExecutionDelete(store store.ExecutionStore) func(t *testing.T) { - return func(t *testing.T) { - v, err := store.Find(noContext, 1) - if err != nil { - t.Error(err) - return - } - if err := store.Delete(noContext, v); err != nil { - t.Error(err) - return - } - if _, err := store.Find(noContext, 1); err != sql.ErrNoRows { - t.Errorf("Expected sql.ErrNoRows got %s", err) - } - } -} - -// helper function that returns an execution store that is seeded -// with execution data loaded from a json file. -func newExecutionStoreSeeded(db *sqlx.DB) (store.ExecutionStore, error) { - store := NewExecutionStoreSync(NewExecutionStore(db)) - vv := []*types.Execution{} - if err := unmarshal("testdata/executions.json", &vv); err != nil { - return nil, err - } - for _, v := range vv { - if err := store.Create(noContext, v); err != nil { - return nil, err - } - } - return store, nil -} diff --git a/internal/store/database/pipeline.go b/internal/store/database/pipeline.go deleted file mode 100644 index 4c82445d1..000000000 --- a/internal/store/database/pipeline.go +++ /dev/null @@ -1,167 +0,0 @@ -// Copyright 2021 Harness Inc. All rights reserved. -// Use of this source code is governed by the Polyform Free Trial License -// that can be found in the LICENSE.md file for this repository. - -package database - -import ( - "context" - - "github.com/harness/gitness/internal/store" - "github.com/harness/gitness/types" - - "github.com/jmoiron/sqlx" -) - -var _ store.PipelineStore = (*PipelineStore)(nil) - -// NewPipelineStore returns a new PipelinetStore. -func NewPipelineStore(db *sqlx.DB) *PipelineStore { - return &PipelineStore{db} -} - -// PipelineStore implements a PipelineStore backed by a -// relational database. -type PipelineStore struct { - db *sqlx.DB -} - -// Find finds the pipeline by id. -func (s *PipelineStore) Find(ctx context.Context, id int64) (*types.Pipeline, error) { - dst := new(types.Pipeline) - err := s.db.Get(dst, pipelineSelectID, id) - return dst, err -} - -// FindToken finds the pipeline by token. -func (s *PipelineStore) FindToken(ctx context.Context, token string) (*types.Pipeline, error) { - dst := new(types.Pipeline) - err := s.db.Get(dst, pipelineSelectToken, token) - return dst, err -} - -// FindSlug finds the pipeline by slug. -func (s *PipelineStore) FindSlug(ctx context.Context, slug string) (*types.Pipeline, error) { - dst := new(types.Pipeline) - err := s.db.Get(dst, pipelineSelectSlug, slug) - return dst, err -} - -// List returns a list of pipelines by user. -func (s *PipelineStore) List(ctx context.Context, user int64, opts types.Params) ([]*types.Pipeline, error) { - dst := []*types.Pipeline{} - err := s.db.Select(&dst, pipelineSelect, limit(opts.Size), offset(opts.Page, opts.Size)) - return dst, err -} - -// Create saves the pipeline details. -func (s *PipelineStore) Create(ctx context.Context, pipeline *types.Pipeline) error { - query, arg, err := s.db.BindNamed(pipelineInsert, pipeline) - if err != nil { - return err - } - return s.db.QueryRow(query, arg...).Scan(&pipeline.ID) -} - -// Update updates the pipeline details. -func (s *PipelineStore) Update(ctx context.Context, pipeline *types.Pipeline) error { - query, arg, err := s.db.BindNamed(pipelineUpdate, pipeline) - if err != nil { - return err - } - _, err = s.db.Exec(query, arg...) - return err -} - -// Delete deletes the pipeline. -func (s *PipelineStore) Delete(ctx context.Context, pipeline *types.Pipeline) error { - tx, err := s.db.BeginTx(ctx, nil) - if err != nil { - return err - } - defer tx.Rollback() - - // pleae note that we are aware of foreign keys and - // cascading deletes, however, we chose to implement - // this logic in the application code in the event we - // want to leverage citus postgres. - // - // to future developers: feel free to remove and - // replace with foreign keys and cascading deletes - // at your discretion. - - // delete the executions associated with the pipeline - if _, err := tx.Exec(executionDeletePipeline, pipeline.ID); err != nil { - return err - } - // delete the pipeline - if _, err := tx.Exec(pipelineDelete, pipeline.ID); err != nil { - return err - } - return tx.Commit() -} - -const pipelineBase = ` -SELECT - pipeline_id -,pipeline_name -,pipeline_slug -,pipeline_desc -,pipeline_token -,pipeline_active -,pipeline_created -,pipeline_updated -FROM pipelines -` - -const pipelineSelect = pipelineBase + ` -ORDER BY pipeline_slug -LIMIT $1 OFFSET $2 -` - -const pipelineSelectID = pipelineBase + ` -WHERE pipeline_id = $1 -` - -const pipelineSelectToken = pipelineBase + ` -WHERE pipeline_token = $1 -` - -const pipelineSelectSlug = pipelineBase + ` -WHERE pipeline_slug = $1 -` - -const pipelineDelete = ` -DELETE FROM pipelines -WHERE pipeline_id = $1 -` - -const pipelineInsert = ` -INSERT INTO pipelines ( - pipeline_name -,pipeline_slug -,pipeline_desc -,pipeline_token -,pipeline_active -,pipeline_created -,pipeline_updated -) values ( - :pipeline_name -,:pipeline_slug -,:pipeline_desc -,:pipeline_token -,:pipeline_active -,:pipeline_created -,:pipeline_updated -) RETURNING pipeline_id -` - -const pipelineUpdate = ` -UPDATE pipelines -SET - pipeline_name = :pipeline_name -,pipeline_desc = :pipeline_desc -,pipeline_active = :pipeline_active -,pipeline_updated = :pipeline_updated -WHERE pipeline_id = :pipeline_id -` diff --git a/internal/store/database/pipeline_sync.go b/internal/store/database/pipeline_sync.go deleted file mode 100644 index d98fa3992..000000000 --- a/internal/store/database/pipeline_sync.go +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright 2021 Harness Inc. All rights reserved. -// Use of this source code is governed by the Polyform Free Trial License -// that can be found in the LICENSE.md file for this repository. - -package database - -import ( - "context" - - "github.com/harness/gitness/internal/store" - "github.com/harness/gitness/internal/store/database/mutex" - "github.com/harness/gitness/types" -) - -var _ store.PipelineStore = (*PipelineStoreSync)(nil) - -// NewPipelineStoreSync returns a new PipelineStoreSync. -func NewPipelineStoreSync(store *PipelineStore) *PipelineStoreSync { - return &PipelineStoreSync{base: store} -} - -// PipelineStoreSync synronizes read and write access to the -// pipeline store. This prevents race conditions when the database -// type is sqlite3. -type PipelineStoreSync struct{ base *PipelineStore } - -// Find finds the pipeline by id. -func (s *PipelineStoreSync) Find(ctx context.Context, id int64) (*types.Pipeline, error) { - mutex.RLock() - defer mutex.RUnlock() - return s.base.Find(ctx, id) -} - -// FindToken finds the pipeline by token. -func (s *PipelineStoreSync) FindToken(ctx context.Context, token string) (*types.Pipeline, error) { - mutex.RLock() - defer mutex.RUnlock() - return s.base.FindToken(ctx, token) -} - -// FindSlug finds the pipeline by slug. -func (s *PipelineStoreSync) FindSlug(ctx context.Context, slug string) (*types.Pipeline, error) { - mutex.RLock() - defer mutex.RUnlock() - return s.base.FindSlug(ctx, slug) -} - -// List returns a list of pipelines by user. -func (s *PipelineStoreSync) List(ctx context.Context, id int64, opts types.Params) ([]*types.Pipeline, error) { - mutex.RLock() - defer mutex.RUnlock() - return s.base.List(ctx, id, opts) -} - -// Create saves the pipeline details. -func (s *PipelineStoreSync) Create(ctx context.Context, pipeline *types.Pipeline) error { - mutex.Lock() - defer mutex.Unlock() - return s.base.Create(ctx, pipeline) -} - -// Update updates the pipeline details. -func (s *PipelineStoreSync) Update(ctx context.Context, pipeline *types.Pipeline) error { - mutex.Lock() - defer mutex.Unlock() - return s.base.Update(ctx, pipeline) -} - -// Delete deletes the pipeline. -func (s *PipelineStoreSync) Delete(ctx context.Context, pipeline *types.Pipeline) error { - mutex.Lock() - defer mutex.Unlock() - return s.base.Delete(ctx, pipeline) -} diff --git a/internal/store/database/pipeline_test.go b/internal/store/database/pipeline_test.go deleted file mode 100644 index 63afa4916..000000000 --- a/internal/store/database/pipeline_test.go +++ /dev/null @@ -1,254 +0,0 @@ -// Copyright 2021 Harness Inc. All rights reserved. -// Use of this source code is governed by the Polyform Free Trial License -// that can be found in the LICENSE.md file for this repository. - -package database - -import ( - "database/sql" - "fmt" - "testing" - "time" - - "github.com/harness/gitness/internal/store" - "github.com/harness/gitness/types" - - "github.com/google/go-cmp/cmp" - "github.com/google/go-cmp/cmp/cmpopts" - "github.com/jmoiron/sqlx" -) - -// pipeline fields to ignore in test comparisons -var pipelineIgnore = cmpopts.IgnoreFields(types.Pipeline{}, - "ID", "Token", "Created", "Updated") - -func TestPipeline(t *testing.T) { - db, err := connect() - if err != nil { - t.Error(err) - return - } - defer db.Close() - if err := seed(db); err != nil { - t.Error(err) - return - } - - if _, err := newUserStoreSeeded(db); err != nil { - t.Error(err) - return - } - - store := NewPipelineStoreSync(NewPipelineStore(db)) - t.Run("create", testPipelineCreate(store)) - t.Run("find", testPipelineFind(store)) - t.Run("list", testPipelineList(store)) - t.Run("update", testPipelineUpdate(store)) - t.Run("delete", testPipelineDelete(store)) -} - -// this test creates entries in the database and confirms -// the primary keys were auto-incremented. -func testPipelineCreate(store store.PipelineStore) func(t *testing.T) { - return func(t *testing.T) { - vv := []*types.Pipeline{} - if err := unmarshal("testdata/pipelines.json", &vv); err != nil { - t.Error(err) - return - } - // create row 1 - v := vv[0] - // generate a deterministic token for each - // entry based on the hash of the email. - v.Token = fmt.Sprintf("%x", v.Slug) - if err := store.Create(noContext, v); err != nil { - t.Error(err) - return - } - if v.ID == 0 { - t.Errorf("Want autoincremented primary key") - } - // create row 2 - v = vv[1] - v.Token = fmt.Sprintf("%x", v.Slug) - if err := store.Create(noContext, v); err != nil { - t.Error(err) - return - } - if v.ID == 0 { - t.Errorf("Want autoincremented primary key") - } - - t.Run("duplicate slug", func(t *testing.T) { - v.ID = 0 - v.Token = "9afeab83324a53" - v.Slug = "cassini" - if err := store.Create(noContext, v); err == nil { - t.Errorf("Expect duplicate row error") - return - } - }) - - t.Run("duplicate token", func(t *testing.T) { - v.ID = 0 - v.Slug = "voyager" - v.Token = "63617373696e69" - if err := store.Create(noContext, v); err == nil { - t.Errorf("Expect duplicate row error") - return - } - }) - } -} - -// this test fetches pipelines from the database by id and key -// and compares to the expected results (sourced from a json file) -// to ensure all columns are correctly mapped. -func testPipelineFind(store store.PipelineStore) func(t *testing.T) { - return func(t *testing.T) { - vv := []*types.Pipeline{} - if err := unmarshal("testdata/pipelines.json", &vv); err != nil { - t.Error(err) - return - } - want := vv[0] - want.Token = "63617373696e69" - - // Find row by ID - got, err := store.Find(noContext, 1) - if err != nil { - t.Error(err) - return - } - if diff := cmp.Diff(got, want, pipelineIgnore); len(diff) != 0 { - t.Errorf(diff) - return - } - - t.Run("token", func(t *testing.T) { - got, err := store.FindToken(noContext, want.Token) - if err != nil { - t.Error(err) - return - } - if diff := cmp.Diff(got, want, pipelineIgnore); len(diff) != 0 { - t.Errorf(diff) - return - } - }) - - t.Run("slug", func(t *testing.T) { - got, err := store.FindSlug(noContext, want.Slug) - if err != nil { - t.Error(err) - return - } - if diff := cmp.Diff(got, want, pipelineIgnore); len(diff) != 0 { - t.Errorf(diff) - return - } - }) - - t.Run("slug", func(t *testing.T) { - got, err := store.FindSlug(noContext, want.Slug) - if err != nil { - t.Error(err) - return - } - if diff := cmp.Diff(got, want, pipelineIgnore); len(diff) != 0 { - t.Errorf(diff) - return - } - }) - } -} - -// this test fetches a list of pipelines from the database -// and compares to the expected results (sourced from a json file) -// to ensure all columns are correctly mapped. -func testPipelineList(store store.PipelineStore) func(t *testing.T) { - return func(t *testing.T) { - want := []*types.Pipeline{} - if err := unmarshal("testdata/pipelines.json", &want); err != nil { - t.Error(err) - return - } - got, err := store.List(noContext, 2, types.Params{Page: 0, Size: 100}) - if err != nil { - t.Error(err) - return - } - if len(got) != 2 { - t.Errorf("Expect 2 pipelines") - } - if diff := cmp.Diff(got, want, pipelineIgnore); len(diff) != 0 { - t.Errorf(diff) - return - } - } -} - -// this test updates an pipeline in the database and then fetches -// the pipeline and confirms the column was updated as expected. -func testPipelineUpdate(store store.PipelineStore) func(t *testing.T) { - return func(t *testing.T) { - before, err := store.Find(noContext, 1) - if err != nil { - t.Error(err) - return - } - before.Updated = time.Now().Unix() - before.Active = false - if err := store.Update(noContext, before); err != nil { - t.Error(err) - return - } - after, err := store.Find(noContext, 1) - if err != nil { - t.Error(err) - return - } - - if diff := cmp.Diff(before, after, pipelineIgnore); len(diff) != 0 { - t.Errorf(diff) - return - } - } -} - -// this test deletes an pipeline from the database and then confirms -// subsequent attempts to fetch the deleted pipeline result in -// a sql.ErrNoRows error. -func testPipelineDelete(store store.PipelineStore) func(t *testing.T) { - return func(t *testing.T) { - v, err := store.Find(noContext, 1) - if err != nil { - t.Error(err) - return - } - if err := store.Delete(noContext, v); err != nil { - t.Error(err) - return - } - if _, err := store.Find(noContext, 1); err != sql.ErrNoRows { - t.Errorf("Expected sql.ErrNoRows got %s", err) - } - } -} - -// helper function that returns an pipeline store that is seeded -// with pipeline data loaded from a json file. -func newPipelineStoreSeeded(db *sqlx.DB) (store.PipelineStore, error) { - store := NewPipelineStoreSync(NewPipelineStore(db)) - vv := []*types.Pipeline{} - if err := unmarshal("testdata/pipelines.json", &vv); err != nil { - return nil, err - } - for _, v := range vv { - v.Token = fmt.Sprintf("%x", v.Slug) - if err := store.Create(noContext, v); err != nil { - return nil, err - } - } - return store, nil -} diff --git a/internal/store/database/testdata/executions.json b/internal/store/database/testdata/executions.json deleted file mode 100644 index affbb729a..000000000 --- a/internal/store/database/testdata/executions.json +++ /dev/null @@ -1,30 +0,0 @@ -[ - { - "id": 0, - "pipeline": 1, - "slug": "foo", - "name": "Foo", - "desc": "this is a foo", - "token": "63617373696e69", - "created": 1637192718, - "updated": 1637192725 - }, - { - "id": 0, - "pipeline": 2, - "slug": "bar", - "name": "Bar", - "desc": "this is a bar", - "created": 1637192718, - "updated": 1637192725 - }, - { - "id": 0, - "pipeline": 2, - "slug": "baz", - "name": "Baz", - "desc": "this is a baz", - "created": 1637192718, - "updated": 1637192725 - } -] \ No newline at end of file diff --git a/internal/store/database/testdata/pipelines.json b/internal/store/database/testdata/pipelines.json deleted file mode 100644 index f34dddeb4..000000000 --- a/internal/store/database/testdata/pipelines.json +++ /dev/null @@ -1,22 +0,0 @@ -[ - { - "id": 0, - "slug": "cassini", - "name": "Cassini", - "desc": "orbit saturn and its moons", - "token": "63617373696e69", - "archived": true, - "created": 0, - "updated": 0 - }, - { - "id": 0, - "slug": "galileo", - "name": "Galileo", - "desc": "orbit jupiter and its moons", - "token": "67616c696c656f", - "archived": true, - "created": 0, - "updated": 0 - } -] \ No newline at end of file diff --git a/internal/store/database/wire.go b/internal/store/database/wire.go index da2f5bfba..a0f92bc8c 100644 --- a/internal/store/database/wire.go +++ b/internal/store/database/wire.go @@ -16,8 +16,6 @@ import ( var WireSet = wire.NewSet( ProvideDatabase, ProvideUserStore, - ProvidePipelineStore, - ProvideExecutionStore, ) // ProvideDatabase provides a database connection. @@ -39,27 +37,3 @@ func ProvideUserStore(db *sqlx.DB) store.UserStore { ) } } - -// ProvidePipelineStore provides a pipeline store. -func ProvidePipelineStore(db *sqlx.DB) store.PipelineStore { - switch db.DriverName() { - case "postgres": - return NewPipelineStore(db) - default: - return NewPipelineStoreSync( - NewPipelineStore(db), - ) - } -} - -// ProvideExecutionStore provides a execution store. -func ProvideExecutionStore(db *sqlx.DB) store.ExecutionStore { - switch db.DriverName() { - case "postgres": - return NewExecutionStore(db) - default: - return NewExecutionStoreSync( - NewExecutionStore(db), - ) - } -} diff --git a/internal/store/store.go b/internal/store/store.go index 8467e83a1..b1f78d73b 100644 --- a/internal/store/store.go +++ b/internal/store/store.go @@ -12,51 +12,6 @@ import ( ) type ( - // ExecutionStore defines execution data storage. - ExecutionStore interface { - // Find finds the execution by id. - Find(ctx context.Context, id int64) (*types.Execution, error) - - // FindSlug finds the execution by pipeline id and slug. - FindSlug(ctx context.Context, id int64, slug string) (*types.Execution, error) - - // List returns a list of executions by pipeline id. - List(ctx context.Context, id int64, params types.Params) ([]*types.Execution, error) - - // Create saves the execution details. - Create(ctx context.Context, execution *types.Execution) error - - // Update updates the execution details. - Update(ctx context.Context, execution *types.Execution) error - - // Delete deletes the execution. - Delete(ctx context.Context, execution *types.Execution) error - } - - // PipelineStore defines pipeline data storage. - PipelineStore interface { - // Find finds the pipeline by id. - Find(ctx context.Context, id int64) (*types.Pipeline, error) - - // FindToken finds the pipeline by token. - FindToken(ctx context.Context, token string) (*types.Pipeline, error) - - // FindSlug finds the user unique name. - FindSlug(ctx context.Context, key string) (*types.Pipeline, error) - - // List returns a list of pipelines by user. - List(ctx context.Context, user int64, params types.Params) ([]*types.Pipeline, error) - - // Create saves the pipeline details. - Create(ctx context.Context, pipeline *types.Pipeline) error - - // Update updates the pipeline details. - Update(ctx context.Context, pipeline *types.Pipeline) error - - // Delete deletes the pipeline. - Delete(ctx context.Context, pipeline *types.Pipeline) error - } - // UserStore defines user data storage. UserStore interface { // Find finds the user by id. diff --git a/mocks/mock.go b/mocks/mock.go index 0b7cba901..ac30ad271 100644 --- a/mocks/mock.go +++ b/mocks/mock.go @@ -5,5 +5,5 @@ // Package mocks provides mock interfaces. package mocks -//go:generate mockgen -package=mocks -destination=mock_store.go github.com/harness/gitness/internal/store ExecutionStore,PipelineStore,SystemStore,UserStore +//go:generate mockgen -package=mocks -destination=mock_store.go github.com/harness/gitness/internal/store SystemStore,UserStore //go:generate mockgen -package=mocks -destination=mock_client.go github.com/harness/gitness/client Client diff --git a/mocks/mock_client.go b/mocks/mock_client.go index 70414124c..86a7bb5ab 100644 --- a/mocks/mock_client.go +++ b/mocks/mock_client.go @@ -34,80 +34,6 @@ func (m *MockClient) EXPECT() *MockClientMockRecorder { return m.recorder } -// Execution mocks base method. -func (m *MockClient) Execution(arg0, arg1 string) (*types.Execution, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Execution", arg0, arg1) - ret0, _ := ret[0].(*types.Execution) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// Execution indicates an expected call of Execution. -func (mr *MockClientMockRecorder) Execution(arg0, arg1 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Execution", reflect.TypeOf((*MockClient)(nil).Execution), arg0, arg1) -} - -// ExecutionCreate mocks base method. -func (m *MockClient) ExecutionCreate(arg0 string, arg1 *types.Execution) (*types.Execution, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ExecutionCreate", arg0, arg1) - ret0, _ := ret[0].(*types.Execution) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// ExecutionCreate indicates an expected call of ExecutionCreate. -func (mr *MockClientMockRecorder) ExecutionCreate(arg0, arg1 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ExecutionCreate", reflect.TypeOf((*MockClient)(nil).ExecutionCreate), arg0, arg1) -} - -// ExecutionDelete mocks base method. -func (m *MockClient) ExecutionDelete(arg0, arg1 string) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ExecutionDelete", arg0, arg1) - ret0, _ := ret[0].(error) - return ret0 -} - -// ExecutionDelete indicates an expected call of ExecutionDelete. -func (mr *MockClientMockRecorder) ExecutionDelete(arg0, arg1 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ExecutionDelete", reflect.TypeOf((*MockClient)(nil).ExecutionDelete), arg0, arg1) -} - -// ExecutionList mocks base method. -func (m *MockClient) ExecutionList(arg0 string, arg1 types.Params) ([]*types.Execution, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ExecutionList", arg0, arg1) - ret0, _ := ret[0].([]*types.Execution) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// ExecutionList indicates an expected call of ExecutionList. -func (mr *MockClientMockRecorder) ExecutionList(arg0, arg1 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ExecutionList", reflect.TypeOf((*MockClient)(nil).ExecutionList), arg0, arg1) -} - -// ExecutionUpdate mocks base method. -func (m *MockClient) ExecutionUpdate(arg0, arg1 string, arg2 *types.ExecutionInput) (*types.Execution, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ExecutionUpdate", arg0, arg1, arg2) - ret0, _ := ret[0].(*types.Execution) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// ExecutionUpdate indicates an expected call of ExecutionUpdate. -func (mr *MockClientMockRecorder) ExecutionUpdate(arg0, arg1, arg2 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ExecutionUpdate", reflect.TypeOf((*MockClient)(nil).ExecutionUpdate), arg0, arg1, arg2) -} - // Login mocks base method. func (m *MockClient) Login(arg0, arg1 string) (*types.Token, error) { m.ctrl.T.Helper() @@ -123,80 +49,6 @@ func (mr *MockClientMockRecorder) Login(arg0, arg1 interface{}) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Login", reflect.TypeOf((*MockClient)(nil).Login), arg0, arg1) } -// Pipeline mocks base method. -func (m *MockClient) Pipeline(arg0 string) (*types.Pipeline, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Pipeline", arg0) - ret0, _ := ret[0].(*types.Pipeline) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// Pipeline indicates an expected call of Pipeline. -func (mr *MockClientMockRecorder) Pipeline(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Pipeline", reflect.TypeOf((*MockClient)(nil).Pipeline), arg0) -} - -// PipelineCreate mocks base method. -func (m *MockClient) PipelineCreate(arg0 *types.Pipeline) (*types.Pipeline, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "PipelineCreate", arg0) - ret0, _ := ret[0].(*types.Pipeline) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// PipelineCreate indicates an expected call of PipelineCreate. -func (mr *MockClientMockRecorder) PipelineCreate(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PipelineCreate", reflect.TypeOf((*MockClient)(nil).PipelineCreate), arg0) -} - -// PipelineDelete mocks base method. -func (m *MockClient) PipelineDelete(arg0 string) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "PipelineDelete", arg0) - ret0, _ := ret[0].(error) - return ret0 -} - -// PipelineDelete indicates an expected call of PipelineDelete. -func (mr *MockClientMockRecorder) PipelineDelete(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PipelineDelete", reflect.TypeOf((*MockClient)(nil).PipelineDelete), arg0) -} - -// PipelineList mocks base method. -func (m *MockClient) PipelineList(arg0 types.Params) ([]*types.Pipeline, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "PipelineList", arg0) - ret0, _ := ret[0].([]*types.Pipeline) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// PipelineList indicates an expected call of PipelineList. -func (mr *MockClientMockRecorder) PipelineList(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PipelineList", reflect.TypeOf((*MockClient)(nil).PipelineList), arg0) -} - -// PipelineUpdate mocks base method. -func (m *MockClient) PipelineUpdate(arg0 string, arg1 *types.PipelineInput) (*types.Pipeline, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "PipelineUpdate", arg0, arg1) - ret0, _ := ret[0].(*types.Pipeline) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// PipelineUpdate indicates an expected call of PipelineUpdate. -func (mr *MockClientMockRecorder) PipelineUpdate(arg0, arg1 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PipelineUpdate", reflect.TypeOf((*MockClient)(nil).PipelineUpdate), arg0, arg1) -} - // Register mocks base method. func (m *MockClient) Register(arg0, arg1 string) (*types.Token, error) { m.ctrl.T.Helper() diff --git a/mocks/mock_store.go b/mocks/mock_store.go index 1faa65d41..f6f624fe4 100644 --- a/mocks/mock_store.go +++ b/mocks/mock_store.go @@ -1,5 +1,5 @@ // Code generated by MockGen. DO NOT EDIT. -// Source: github.com/harness/gitness/internal/store (interfaces: ExecutionStore,PipelineStore,SystemStore,UserStore) +// Source: github.com/harness/gitness/internal/store (interfaces: SystemStore,UserStore) // Package mocks is a generated GoMock package. package mocks @@ -12,241 +12,6 @@ import ( types "github.com/harness/gitness/types" ) -// MockExecutionStore is a mock of ExecutionStore interface. -type MockExecutionStore struct { - ctrl *gomock.Controller - recorder *MockExecutionStoreMockRecorder -} - -// MockExecutionStoreMockRecorder is the mock recorder for MockExecutionStore. -type MockExecutionStoreMockRecorder struct { - mock *MockExecutionStore -} - -// NewMockExecutionStore creates a new mock instance. -func NewMockExecutionStore(ctrl *gomock.Controller) *MockExecutionStore { - mock := &MockExecutionStore{ctrl: ctrl} - mock.recorder = &MockExecutionStoreMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockExecutionStore) EXPECT() *MockExecutionStoreMockRecorder { - return m.recorder -} - -// Create mocks base method. -func (m *MockExecutionStore) Create(arg0 context.Context, arg1 *types.Execution) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Create", arg0, arg1) - ret0, _ := ret[0].(error) - return ret0 -} - -// Create indicates an expected call of Create. -func (mr *MockExecutionStoreMockRecorder) Create(arg0, arg1 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Create", reflect.TypeOf((*MockExecutionStore)(nil).Create), arg0, arg1) -} - -// Delete mocks base method. -func (m *MockExecutionStore) Delete(arg0 context.Context, arg1 *types.Execution) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Delete", arg0, arg1) - ret0, _ := ret[0].(error) - return ret0 -} - -// Delete indicates an expected call of Delete. -func (mr *MockExecutionStoreMockRecorder) Delete(arg0, arg1 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Delete", reflect.TypeOf((*MockExecutionStore)(nil).Delete), arg0, arg1) -} - -// Find mocks base method. -func (m *MockExecutionStore) Find(arg0 context.Context, arg1 int64) (*types.Execution, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Find", arg0, arg1) - ret0, _ := ret[0].(*types.Execution) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// Find indicates an expected call of Find. -func (mr *MockExecutionStoreMockRecorder) Find(arg0, arg1 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Find", reflect.TypeOf((*MockExecutionStore)(nil).Find), arg0, arg1) -} - -// FindSlug mocks base method. -func (m *MockExecutionStore) FindSlug(arg0 context.Context, arg1 int64, arg2 string) (*types.Execution, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "FindSlug", arg0, arg1, arg2) - ret0, _ := ret[0].(*types.Execution) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// FindSlug indicates an expected call of FindSlug. -func (mr *MockExecutionStoreMockRecorder) FindSlug(arg0, arg1, arg2 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FindSlug", reflect.TypeOf((*MockExecutionStore)(nil).FindSlug), arg0, arg1, arg2) -} - -// List mocks base method. -func (m *MockExecutionStore) List(arg0 context.Context, arg1 int64, arg2 types.Params) ([]*types.Execution, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "List", arg0, arg1, arg2) - ret0, _ := ret[0].([]*types.Execution) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// List indicates an expected call of List. -func (mr *MockExecutionStoreMockRecorder) List(arg0, arg1, arg2 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "List", reflect.TypeOf((*MockExecutionStore)(nil).List), arg0, arg1, arg2) -} - -// Update mocks base method. -func (m *MockExecutionStore) Update(arg0 context.Context, arg1 *types.Execution) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Update", arg0, arg1) - ret0, _ := ret[0].(error) - return ret0 -} - -// Update indicates an expected call of Update. -func (mr *MockExecutionStoreMockRecorder) Update(arg0, arg1 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Update", reflect.TypeOf((*MockExecutionStore)(nil).Update), arg0, arg1) -} - -// MockPipelineStore is a mock of PipelineStore interface. -type MockPipelineStore struct { - ctrl *gomock.Controller - recorder *MockPipelineStoreMockRecorder -} - -// MockPipelineStoreMockRecorder is the mock recorder for MockPipelineStore. -type MockPipelineStoreMockRecorder struct { - mock *MockPipelineStore -} - -// NewMockPipelineStore creates a new mock instance. -func NewMockPipelineStore(ctrl *gomock.Controller) *MockPipelineStore { - mock := &MockPipelineStore{ctrl: ctrl} - mock.recorder = &MockPipelineStoreMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockPipelineStore) EXPECT() *MockPipelineStoreMockRecorder { - return m.recorder -} - -// Create mocks base method. -func (m *MockPipelineStore) Create(arg0 context.Context, arg1 *types.Pipeline) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Create", arg0, arg1) - ret0, _ := ret[0].(error) - return ret0 -} - -// Create indicates an expected call of Create. -func (mr *MockPipelineStoreMockRecorder) Create(arg0, arg1 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Create", reflect.TypeOf((*MockPipelineStore)(nil).Create), arg0, arg1) -} - -// Delete mocks base method. -func (m *MockPipelineStore) Delete(arg0 context.Context, arg1 *types.Pipeline) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Delete", arg0, arg1) - ret0, _ := ret[0].(error) - return ret0 -} - -// Delete indicates an expected call of Delete. -func (mr *MockPipelineStoreMockRecorder) Delete(arg0, arg1 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Delete", reflect.TypeOf((*MockPipelineStore)(nil).Delete), arg0, arg1) -} - -// Find mocks base method. -func (m *MockPipelineStore) Find(arg0 context.Context, arg1 int64) (*types.Pipeline, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Find", arg0, arg1) - ret0, _ := ret[0].(*types.Pipeline) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// Find indicates an expected call of Find. -func (mr *MockPipelineStoreMockRecorder) Find(arg0, arg1 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Find", reflect.TypeOf((*MockPipelineStore)(nil).Find), arg0, arg1) -} - -// FindSlug mocks base method. -func (m *MockPipelineStore) FindSlug(arg0 context.Context, arg1 string) (*types.Pipeline, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "FindSlug", arg0, arg1) - ret0, _ := ret[0].(*types.Pipeline) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// FindSlug indicates an expected call of FindSlug. -func (mr *MockPipelineStoreMockRecorder) FindSlug(arg0, arg1 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FindSlug", reflect.TypeOf((*MockPipelineStore)(nil).FindSlug), arg0, arg1) -} - -// FindToken mocks base method. -func (m *MockPipelineStore) FindToken(arg0 context.Context, arg1 string) (*types.Pipeline, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "FindToken", arg0, arg1) - ret0, _ := ret[0].(*types.Pipeline) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// FindToken indicates an expected call of FindToken. -func (mr *MockPipelineStoreMockRecorder) FindToken(arg0, arg1 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FindToken", reflect.TypeOf((*MockPipelineStore)(nil).FindToken), arg0, arg1) -} - -// List mocks base method. -func (m *MockPipelineStore) List(arg0 context.Context, arg1 int64, arg2 types.Params) ([]*types.Pipeline, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "List", arg0, arg1, arg2) - ret0, _ := ret[0].([]*types.Pipeline) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// List indicates an expected call of List. -func (mr *MockPipelineStoreMockRecorder) List(arg0, arg1, arg2 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "List", reflect.TypeOf((*MockPipelineStore)(nil).List), arg0, arg1, arg2) -} - -// Update mocks base method. -func (m *MockPipelineStore) Update(arg0 context.Context, arg1 *types.Pipeline) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Update", arg0, arg1) - ret0, _ := ret[0].(error) - return ret0 -} - -// Update indicates an expected call of Update. -func (mr *MockPipelineStoreMockRecorder) Update(arg0, arg1 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Update", reflect.TypeOf((*MockPipelineStore)(nil).Update), arg0, arg1) -} - // MockSystemStore is a mock of SystemStore interface. type MockSystemStore struct { ctrl *gomock.Controller diff --git a/types/check/execution.go b/types/check/execution.go deleted file mode 100644 index 2b1bf2a26..000000000 --- a/types/check/execution.go +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright 2021 Harness Inc. All rights reserved. -// Use of this source code is governed by the Polyform Free Trial License -// that can be found in the LICENSE.md file for this repository. - -package check - -import ( - "errors" - - "github.com/harness/gitness/types" - - "github.com/gosimple/slug" -) - -var ( - // ErrExecutionIdentifier is returned when the execution - // slug is an invalid format. - ErrExecutionIdentifier = errors.New("Invalid execution identifier") - - // ErrExecutionIdentifierLen is returned when the execution - // name exceeds the maximum number of characters. - ErrExecutionIdentifierLen = errors.New("Execution identifier cannot exceed 250 characters") - - // ErrExecutionNameLen is returned when the execution name - // exceeds the maximum number of characters. - ErrExecutionNameLen = errors.New("Execution name cannot exceed 250 characters") - - // ErrExecutionDescLen is returned when the execution desc - // exceeds the maximum number of characters. - ErrExecutionDescLen = errors.New("Execution description cannot exceed 250 characters") -) - -// Execution returns true if the Execution if valid. -func Execution(execution *types.Execution) (bool, error) { - if !slug.IsSlug(execution.Slug) { - return false, ErrExecutionIdentifier - } - if len(execution.Slug) > 250 { - return false, ErrExecutionIdentifierLen - } - if len(execution.Name) > 250 { - return false, ErrExecutionNameLen - } - if len(execution.Desc) > 500 { - return false, ErrExecutionDescLen - } - return true, nil -} diff --git a/types/check/execution_test.go b/types/check/execution_test.go deleted file mode 100644 index 9012b6c40..000000000 --- a/types/check/execution_test.go +++ /dev/null @@ -1,5 +0,0 @@ -// Copyright 2021 Harness Inc. All rights reserved. -// Use of this source code is governed by the Polyform Free Trial License -// that can be found in the LICENSE.md file for this repository. - -package check diff --git a/types/check/pipeline.go b/types/check/pipeline.go deleted file mode 100644 index 742d3ca84..000000000 --- a/types/check/pipeline.go +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright 2021 Harness Inc. All rights reserved. -// Use of this source code is governed by the Polyform Free Trial License -// that can be found in the LICENSE.md file for this repository. - -package check - -import ( - "errors" - - "github.com/harness/gitness/types" - - "github.com/gosimple/slug" -) - -var ( - // ErrPipelineIdentifier is returned when the pipeline - // slug is an invalid format. - ErrPipelineIdentifier = errors.New("Invalid pipeline identifier") - - // ErrPipelineIdentifierLen is returned when the pipeline - // name exceeds the maximum number of characters. - ErrPipelineIdentifierLen = errors.New("Pipeline identifier cannot exceed 250 characters") - - // ErrPipelineNameLen is returned when the pipeline name - // exceeds the maximum number of characters. - ErrPipelineNameLen = errors.New("Pipeline name cannot exceed 250 characters") - - // ErrPipelineDescLen is returned when the pipeline desc - // exceeds the maximum number of characters. - ErrPipelineDescLen = errors.New("Pipeline description cannot exceed 250 characters") -) - -// Pipeline returns true if the Pipeline if valid. -func Pipeline(pipeline *types.Pipeline) (bool, error) { - if !slug.IsSlug(pipeline.Slug) { - return false, ErrPipelineIdentifier - } - if len(pipeline.Slug) > 250 { - return false, ErrPipelineIdentifierLen - } - if len(pipeline.Name) > 250 { - return false, ErrPipelineNameLen - } - if len(pipeline.Desc) > 500 { - return false, ErrPipelineDescLen - } - return true, nil -} diff --git a/types/enum/role.go b/types/enum/role.go deleted file mode 100644 index 62a87a3c4..000000000 --- a/types/enum/role.go +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright 2021 Harness Inc. All rights reserved. -// Use of this source code is governed by the Polyform Free Trial License -// that can be found in the LICENSE.md file for this repository. - -package enum - -import "encoding/json" - -// Role defines the member role. -type Role int - -// Role enumeration. -const ( - RoleDeveloper Role = iota - RoleAdmin -) - -// String returns the Role as a string. -func (e Role) String() string { - switch e { - case RoleDeveloper: - return "developer" - case RoleAdmin: - return "admin" - default: - return "developer" - } -} - -// MarshalJSON marshals the Type as a JSON string. -func (e Role) MarshalJSON() ([]byte, error) { - return json.Marshal(e.String()) -} - -// UnmarshalJSON unmashals a quoted json string to the enum value. -func (e *Role) UnmarshalJSON(b []byte) error { - var v string - json.Unmarshal(b, &v) - switch v { - case "admin": - *e = RoleAdmin - case "developer": - *e = RoleDeveloper - default: - *e = RoleDeveloper - } - return nil -} diff --git a/types/enum/role_test.go b/types/enum/role_test.go deleted file mode 100644 index 62d8241a8..000000000 --- a/types/enum/role_test.go +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright 2021 Harness Inc. All rights reserved. -// Use of this source code is governed by the Polyform Free Trial License -// that can be found in the LICENSE.md file for this repository. - -package enum - -import "testing" - -func TestRoleUnmarshal(t *testing.T) { - t.Skip() -} - -func TestRoleMarshal(t *testing.T) { - t.Skip() -} - -func TestRoleString(t *testing.T) { - t.Skip() -} diff --git a/types/types.go b/types/types.go index f5c8f81e2..134f8e9ec 100644 --- a/types/types.go +++ b/types/types.go @@ -28,76 +28,6 @@ type ( Order enum.Order `json:"direction"` } - // Execution stores execution details. - Execution struct { - ID int64 `db:"execution_id" json:"id"` - Pipeline int64 `db:"execution_pipeline_id" json:"pipeline,omitempty"` - Slug string `db:"execution_slug" json:"slug"` - Name string `db:"execution_name" json:"name"` - Desc string `db:"execution_desc" json:"desc"` - Created int64 `db:"execution_created" json:"created"` - Updated int64 `db:"execution_updated" json:"updated"` - } - - // ExecutionParams stores execution parameters. - ExecutionParams struct { - Pipeline int64 - Slug string - - Scope Scope - } - - // ExecutionListParams stores execution list - // parameters. - ExecutionListParams struct { - Pipeline int64 - - Query Params - Scope Scope - } - - // ExecutionInput store details used to create or - // update a execution. - ExecutionInput struct { - Slug *string `json:"slug"` - Name *string `json:"name"` - Desc *string `json:"desc"` - } - - // Pipeline stores pipeline details. - Pipeline struct { - ID int64 `db:"pipeline_id" json:"id"` - Name string `db:"pipeline_name" json:"name"` - Slug string `db:"pipeline_slug" json:"slug"` - Desc string `db:"pipeline_desc" json:"desc"` - Token string `db:"pipeline_token" json:"-"` - Active bool `db:"pipeline_active" json:"active"` - Created int64 `db:"pipeline_created" json:"created"` - Updated int64 `db:"pipeline_updated" json:"updated"` - } - - // PipelineParams stores pipeline parameters. - PipelineParams struct { - Slug string - - Scope Scope - } - - // PipelineListParams stores pipeline list - // parameters. - PipelineListParams struct { - Query Params - Scope Scope - } - - // PipelineInput store user pipeline details used to - // create or update a pipeline. - PipelineInput struct { - Slug *string `json:"slug"` - Name *string `json:"name"` - Desc *string `json:"desc"` - } - // User stores user account details. User struct { ID int64 `db:"user_id" json:"id"` @@ -143,28 +73,4 @@ type ( User *User `json:"user"` Token *Token `json:"token"` } - - // Project stores project details. - Project struct { - Identifier string `json:"identifier"` - Color string `json:"color"` - Desc string `json:"description"` - Name string `json:"name"` - Modules []string `json:"modules"` - Org string `json:"orgIdentifier"` - Tags map[string]string `json:"tags"` - } - - // ProjectList stores the project list and project - // result set metdata. - ProjectList struct { - Data []*Project `json:"data"` - - Empty bool `json:"empty"` - PageIndex int `json:"pageIndex,omitempty"` - PageItemCount int `json:"pageItemCount,omitempty"` - PageSize int `json:"pageSize,omitempty"` - TotalItems int `json:"totalItems,omitempty"` - TotalPages int `json:"totalPages,omitempty"` - } )