From 8cce6da6977efb40ecc3805693f2d6b996c02338 Mon Sep 17 00:00:00 2001 From: ecrupper Date: Thu, 17 Oct 2024 20:06:56 -0500 Subject: [PATCH 1/2] refactor(steps/services): use server API types for steps and services --- api/admin/clean.go | 2 +- api/admin/service.go | 4 +- api/admin/step.go | 4 +- api/admin/worker.go | 2 +- api/auth/logout.go | 2 +- api/auth/post_token.go | 2 +- api/badge.go | 2 +- api/build/approve.go | 2 +- api/build/auto_cancel.go | 2 +- api/build/auto_cancel_test.go | 2 +- api/build/cancel.go | 2 +- api/build/clean.go | 5 +- api/build/compile_publish.go | 2 +- api/build/graph.go | 24 +- api/build/list_org.go | 2 +- api/build/list_repo.go | 2 +- api/build/restart.go | 2 +- api/build/token.go | 2 +- api/build/update.go | 7 +- api/metrics.go | 2 +- api/repo/create.go | 2 +- api/repo/list_org.go | 2 +- api/repo/update.go | 2 +- api/secret/create.go | 2 +- api/secret/delete.go | 2 +- api/secret/get.go | 2 +- api/secret/list.go | 2 +- api/secret/update.go | 2 +- api/service/create.go | 6 +- api/service/plan.go | 8 +- api/service/update.go | 4 +- api/step/create.go | 6 +- api/step/plan.go | 10 +- api/step/update.go | 6 +- api/types/actions/comment.go | 2 +- api/types/actions/comment_test.go | 2 +- api/types/actions/deploy.go | 2 +- api/types/actions/deploy_test.go | 2 +- api/types/actions/pull.go | 2 +- api/types/actions/pull_test.go | 2 +- api/types/actions/push.go | 2 +- api/types/actions/push_test.go | 2 +- api/types/actions/schedule.go | 2 +- api/types/actions/schedule_test.go | 2 +- api/types/build.go | 2 +- api/types/events.go | 2 +- api/types/events_test.go | 2 +- api/types/repo_test.go | 2 +- api/types/secret.go | 2 +- api/types/secret_test.go | 2 +- api/types/service.go | 645 ++++++++++++++++ api/types/service_test.go | 449 +++++++++++ api/types/step.go | 727 ++++++++++++++++++ api/types/step_test.go | 482 ++++++++++++ api/webhook/post.go | 2 +- api/worker/create.go | 2 +- api/worker/refresh.go | 2 +- cmd/vela-server/main.go | 2 +- cmd/vela-server/schedule.go | 2 +- cmd/vela-server/secret.go | 2 +- cmd/vela-server/validate.go | 2 +- compiler/native/clone.go | 2 +- compiler/native/compile.go | 2 +- compiler/native/compile_test.go | 2 +- compiler/native/environment.go | 2 +- compiler/native/expand.go | 2 +- compiler/native/initialize.go | 2 +- compiler/native/parse.go | 2 +- compiler/native/parse_test.go | 2 +- compiler/native/validate.go | 2 +- compiler/types/pipeline/build.go | 2 +- compiler/types/pipeline/build_test.go | 2 +- compiler/types/pipeline/container.go | 2 +- compiler/types/pipeline/container_test.go | 2 +- compiler/types/pipeline/ruleset.go | 2 +- compiler/types/pipeline/ruleset_test.go | 2 +- compiler/types/pipeline/secret.go | 2 +- compiler/types/pipeline/stage.go | 2 +- compiler/types/pipeline/stage_test.go | 2 +- compiler/types/yaml/ruleset.go | 2 +- compiler/types/yaml/secret.go | 2 +- compiler/types/yaml/service.go | 2 +- compiler/types/yaml/step.go | 2 +- constants/action.go | 42 + constants/allow_events.go | 27 + constants/badge.go | 98 +++ constants/compression.go | 52 ++ constants/doc.go | 8 + constants/event.go | 38 + constants/limit.go | 1 + constants/matcher.go | 12 + constants/operator.go | 12 + constants/pipeline.go | 15 + constants/pull.go | 22 + constants/queue.go | 9 + constants/table.go | 1 + constants/worker_status.go | 21 + constants/workspace.go | 12 + database/build/build.go | 2 +- database/build/clean.go | 2 +- database/build/count.go | 2 +- database/build/count_deployment.go | 2 +- database/build/count_org.go | 2 +- database/build/count_org_test.go | 2 +- database/build/count_repo.go | 2 +- database/build/count_status.go | 2 +- database/build/create.go | 2 +- database/build/delete.go | 2 +- database/build/get.go | 2 +- database/build/get_repo.go | 2 +- database/build/get_repo_test.go | 2 +- database/build/get_test.go | 2 +- database/build/last_repo.go | 2 +- database/build/last_repo_test.go | 2 +- database/build/list.go | 2 +- database/build/list_dashboard.go | 2 +- database/build/list_org.go | 2 +- database/build/list_org_test.go | 2 +- database/build/list_pending_running.go | 2 +- database/build/list_pending_running_repo.go | 2 +- database/build/list_pending_running_test.go | 2 +- database/build/list_repo.go | 2 +- database/build/list_repo_test.go | 2 +- database/build/list_test.go | 2 +- database/build/table.go | 2 +- database/build/update.go | 2 +- database/dashboard/table.go | 2 +- database/database.go | 2 +- database/deployment/count.go | 2 +- database/deployment/count_repo.go | 2 +- database/deployment/create.go | 2 +- database/deployment/delete.go | 2 +- database/deployment/deployment.go | 2 +- database/deployment/get.go | 2 +- database/deployment/get_repo.go | 2 +- database/deployment/list.go | 2 +- database/deployment/list_repo.go | 2 +- database/deployment/table.go | 2 +- database/deployment/update.go | 2 +- database/executable/clean.go | 2 +- database/executable/clean_test.go | 2 +- database/executable/create.go | 2 +- database/executable/executable.go | 2 +- database/executable/executable_test.go | 2 +- database/executable/pop.go | 2 +- database/executable/table.go | 2 +- database/flags.go | 2 +- database/hook/last_repo.go | 2 +- database/integration_test.go | 26 +- database/jwk/table.go | 2 +- database/log/count.go | 2 +- database/log/count_build.go | 2 +- database/log/create.go | 2 +- database/log/delete.go | 2 +- database/log/get.go | 2 +- database/log/get_service.go | 5 +- database/log/get_step.go | 5 +- database/log/interface.go | 4 +- database/log/list.go | 2 +- database/log/list_build.go | 2 +- database/log/log.go | 2 +- database/log/table.go | 2 +- database/log/update.go | 2 +- database/pipeline/count.go | 2 +- database/pipeline/count_repo.go | 2 +- database/pipeline/create.go | 2 +- database/pipeline/delete.go | 2 +- database/pipeline/get.go | 2 +- database/pipeline/get_repo.go | 2 +- database/pipeline/list.go | 2 +- database/pipeline/list_repo.go | 2 +- database/pipeline/pipeline.go | 2 +- database/pipeline/table.go | 2 +- database/pipeline/update.go | 2 +- database/repo/count.go | 2 +- database/repo/count_org.go | 2 +- database/repo/count_user.go | 2 +- database/repo/create.go | 2 +- database/repo/delete.go | 2 +- database/repo/get.go | 2 +- database/repo/get_org.go | 2 +- database/repo/get_org_test.go | 2 +- database/repo/get_test.go | 2 +- database/repo/list.go | 2 +- database/repo/list_org.go | 2 +- database/repo/list_org_test.go | 2 +- database/repo/list_test.go | 2 +- database/repo/list_user.go | 2 +- database/repo/list_user_test.go | 2 +- database/repo/repo.go | 2 +- database/repo/table.go | 2 +- database/repo/update.go | 2 +- database/repo/update_test.go | 2 +- database/schedule/count.go | 2 +- database/schedule/count_active.go | 2 +- database/schedule/count_active_test.go | 2 +- database/schedule/count_repo.go | 2 +- database/schedule/count_repo_test.go | 2 +- database/schedule/count_test.go | 2 +- database/schedule/create.go | 2 +- database/schedule/create_test.go | 2 +- database/schedule/delete.go | 2 +- database/schedule/delete_test.go | 2 +- database/schedule/get.go | 2 +- database/schedule/get_repo.go | 2 +- database/schedule/get_repo_test.go | 2 +- database/schedule/get_test.go | 2 +- database/schedule/list.go | 2 +- database/schedule/list_active.go | 2 +- database/schedule/list_active_test.go | 2 +- database/schedule/list_repo.go | 2 +- database/schedule/list_repo_test.go | 2 +- database/schedule/list_test.go | 2 +- database/schedule/schedule.go | 2 +- database/schedule/table.go | 2 +- database/schedule/update.go | 2 +- database/schedule/update_test.go | 2 +- database/secret/count.go | 2 +- database/secret/count_org.go | 2 +- database/secret/count_org_test.go | 2 +- database/secret/count_repo.go | 2 +- database/secret/count_repo_test.go | 2 +- database/secret/count_team.go | 2 +- database/secret/count_team_test.go | 2 +- database/secret/create.go | 2 +- database/secret/delete.go | 2 +- database/secret/get.go | 2 +- database/secret/get_org.go | 2 +- database/secret/get_org_test.go | 2 +- database/secret/get_repo.go | 2 +- database/secret/get_repo_test.go | 2 +- database/secret/get_team.go | 2 +- database/secret/get_team_test.go | 2 +- database/secret/list.go | 2 +- database/secret/list_org.go | 2 +- database/secret/list_org_test.go | 2 +- database/secret/list_repo.go | 2 +- database/secret/list_repo_test.go | 2 +- database/secret/list_team.go | 2 +- database/secret/list_team_test.go | 2 +- database/secret/secret.go | 2 +- database/secret/table.go | 2 +- database/secret/update.go | 2 +- database/service/clean.go | 10 +- database/service/count.go | 2 +- database/service/count_build.go | 2 +- database/service/create.go | 18 +- database/service/delete.go | 13 +- database/service/get.go | 15 +- database/service/get_build.go | 14 +- database/service/get_build_test.go | 4 +- database/service/get_test.go | 4 +- database/service/interface.go | 15 +- database/service/list.go | 17 +- database/service/list_build.go | 16 +- database/service/list_build_test.go | 8 +- database/service/list_image.go | 2 +- database/service/list_status.go | 2 +- database/service/list_test.go | 8 +- database/service/service.go | 2 +- database/service/table.go | 2 +- database/service/update.go | 18 +- database/settings/table.go | 2 +- database/step/clean.go | 10 +- database/step/count.go | 2 +- database/step/count_build.go | 2 +- database/step/create.go | 18 +- database/step/delete.go | 10 +- database/step/get.go | 15 +- database/step/get_build.go | 14 +- database/step/get_build_test.go | 4 +- database/step/get_test.go | 4 +- database/step/interface.go | 15 +- database/step/list.go | 17 +- database/step/list_build.go | 16 +- database/step/list_build_test.go | 8 +- database/step/list_image.go | 2 +- database/step/list_status.go | 2 +- database/step/list_test.go | 8 +- database/step/step.go | 2 +- database/step/table.go | 2 +- database/step/update.go | 18 +- database/testutils/api_resources.go | 8 +- database/types/deployment.go | 2 +- database/types/pipeline_test.go | 2 +- database/types/repo.go | 2 +- database/types/repo_test.go | 2 +- database/types/schedule_test.go | 2 +- database/types/secret.go | 2 +- database/types/service.go | 231 ++++++ database/types/service_test.go | 221 ++++++ database/types/step.go | 249 ++++++ database/types/step_test.go | 230 ++++++ database/types/worker.go | 2 +- database/user/count.go | 2 +- database/user/create.go | 2 +- database/user/delete.go | 2 +- database/user/get.go | 2 +- database/user/get_name.go | 2 +- database/user/list.go | 2 +- database/user/list_lite.go | 2 +- database/user/table.go | 2 +- database/user/update.go | 2 +- database/user/user.go | 2 +- database/validate.go | 2 +- database/worker/count.go | 2 +- database/worker/create.go | 2 +- database/worker/delete.go | 2 +- database/worker/get.go | 2 +- database/worker/get_hostname.go | 2 +- database/worker/list.go | 2 +- database/worker/table.go | 2 +- database/worker/update.go | 2 +- database/worker/worker.go | 2 +- internal/token/compose.go | 2 +- internal/token/compose_test.go | 2 +- internal/token/parse_test.go | 2 +- internal/token/refresh.go | 2 +- internal/token/refresh_test.go | 2 +- internal/webhook.go | 2 +- internal/webhook_test.go | 2 +- mock/server/authentication.go | 2 +- mock/server/service.go | 10 +- mock/server/service_test.go | 4 +- mock/server/step.go | 10 +- mock/server/step_test.go | 4 +- queue/flags.go | 2 +- queue/queue.go | 2 +- queue/redis/driver.go | 2 +- queue/redis/driver_test.go | 2 +- queue/redis/route.go | 2 +- queue/redis/route_test.go | 2 +- queue/setup.go | 2 +- router/middleware/auth/auth.go | 2 +- router/middleware/auth/auth_test.go | 2 +- router/middleware/claims/claims.go | 2 +- router/middleware/claims/claims_test.go | 2 +- router/middleware/claims/context_test.go | 2 +- .../middleware/default_repo_settings_test.go | 2 +- router/middleware/executors/executors.go | 2 +- router/middleware/logger.go | 2 +- router/middleware/logger_test.go | 5 +- router/middleware/pipeline/pipeline_test.go | 2 +- router/middleware/service/context.go | 8 +- router/middleware/service/context_test.go | 6 +- router/middleware/service/service.go | 4 +- router/middleware/service/service_test.go | 7 +- router/middleware/step/context.go | 8 +- router/middleware/step/context_test.go | 6 +- router/middleware/step/step.go | 4 +- router/middleware/step/step_test.go | 7 +- router/middleware/user/user.go | 2 +- router/middleware/user/user_test.go | 2 +- scm/flags.go | 2 +- scm/github/driver.go | 2 +- scm/github/driver_test.go | 2 +- scm/github/repo.go | 5 +- scm/github/repo_test.go | 15 +- scm/github/webhook.go | 2 +- scm/github/webhook_test.go | 2 +- scm/scm.go | 2 +- scm/service.go | 3 +- scm/setup.go | 2 +- secret/native/count.go | 2 +- secret/native/create.go | 2 +- secret/native/delete.go | 2 +- secret/native/driver.go | 2 +- secret/native/driver_test.go | 2 +- secret/native/get.go | 2 +- secret/native/list.go | 2 +- secret/native/update.go | 2 +- secret/secret.go | 2 +- secret/setup.go | 2 +- secret/vault/count.go | 2 +- secret/vault/create.go | 2 +- secret/vault/delete.go | 2 +- secret/vault/driver.go | 2 +- secret/vault/driver_test.go | 2 +- secret/vault/get.go | 2 +- secret/vault/list.go | 2 +- secret/vault/update.go | 2 +- secret/vault/vault.go | 2 +- util/compression_test.go | 2 +- 383 files changed, 4152 insertions(+), 611 deletions(-) create mode 100644 api/types/service.go create mode 100644 api/types/service_test.go create mode 100644 api/types/step.go create mode 100644 api/types/step_test.go create mode 100644 constants/action.go create mode 100644 constants/allow_events.go create mode 100644 constants/badge.go create mode 100644 constants/compression.go create mode 100644 constants/doc.go create mode 100644 constants/event.go create mode 100644 constants/matcher.go create mode 100644 constants/operator.go create mode 100644 constants/pipeline.go create mode 100644 constants/pull.go create mode 100644 constants/queue.go create mode 100644 constants/worker_status.go create mode 100644 constants/workspace.go create mode 100644 database/types/service.go create mode 100644 database/types/service_test.go create mode 100644 database/types/step.go create mode 100644 database/types/step_test.go diff --git a/api/admin/clean.go b/api/admin/clean.go index da3949568..86b1fc7cc 100644 --- a/api/admin/clean.go +++ b/api/admin/clean.go @@ -11,10 +11,10 @@ import ( "github.com/gin-gonic/gin" "github.com/sirupsen/logrus" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database" "github.com/go-vela/server/util" "github.com/go-vela/types" - "github.com/go-vela/types/constants" ) // swagger:operation PUT /api/v1/admin/clean admin AdminCleanResources diff --git a/api/admin/service.go b/api/admin/service.go index 13d33d199..5e5e5dcba 100644 --- a/api/admin/service.go +++ b/api/admin/service.go @@ -10,9 +10,9 @@ import ( "github.com/gin-gonic/gin" "github.com/sirupsen/logrus" + "github.com/go-vela/server/api/types" "github.com/go-vela/server/database" "github.com/go-vela/server/util" - "github.com/go-vela/types/library" ) // swagger:operation PUT /api/v1/admin/service admin AdminUpdateService @@ -59,7 +59,7 @@ func UpdateService(c *gin.Context) { l.Debug("platform admin: updating service") // capture body from API request - input := new(library.Service) + input := new(types.Service) err := c.Bind(input) if err != nil { diff --git a/api/admin/step.go b/api/admin/step.go index b29fc57e0..6e7ad4cdb 100644 --- a/api/admin/step.go +++ b/api/admin/step.go @@ -10,9 +10,9 @@ import ( "github.com/gin-gonic/gin" "github.com/sirupsen/logrus" + "github.com/go-vela/server/api/types" "github.com/go-vela/server/database" "github.com/go-vela/server/util" - "github.com/go-vela/types/library" ) // swagger:operation PUT /api/v1/admin/step admin AdminUpdateStep @@ -58,7 +58,7 @@ func UpdateStep(c *gin.Context) { l.Debug("platform admin: updating step") // capture body from API request - input := new(library.Step) + input := new(types.Step) err := c.Bind(input) if err != nil { diff --git a/api/admin/worker.go b/api/admin/worker.go index 59ed71a5e..9ff7f5e60 100644 --- a/api/admin/worker.go +++ b/api/admin/worker.go @@ -9,9 +9,9 @@ import ( "github.com/gin-gonic/gin" "github.com/sirupsen/logrus" + "github.com/go-vela/server/constants" "github.com/go-vela/server/internal/token" "github.com/go-vela/server/util" - "github.com/go-vela/types/constants" "github.com/go-vela/types/library" ) diff --git a/api/auth/logout.go b/api/auth/logout.go index 9acb575cd..77ac9c97f 100644 --- a/api/auth/logout.go +++ b/api/auth/logout.go @@ -10,11 +10,11 @@ import ( "github.com/gin-gonic/gin" "github.com/sirupsen/logrus" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database" "github.com/go-vela/server/internal" "github.com/go-vela/server/router/middleware/user" "github.com/go-vela/server/util" - "github.com/go-vela/types/constants" ) // swagger:operation GET /logout authenticate GetLogout diff --git a/api/auth/post_token.go b/api/auth/post_token.go index d5fc345c9..d23183f2b 100644 --- a/api/auth/post_token.go +++ b/api/auth/post_token.go @@ -9,11 +9,11 @@ import ( "github.com/gin-gonic/gin" "github.com/sirupsen/logrus" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database" "github.com/go-vela/server/internal/token" "github.com/go-vela/server/scm" "github.com/go-vela/server/util" - "github.com/go-vela/types/constants" "github.com/go-vela/types/library" ) diff --git a/api/badge.go b/api/badge.go index 37ffeb694..ce0ce0d76 100644 --- a/api/badge.go +++ b/api/badge.go @@ -8,10 +8,10 @@ import ( "github.com/gin-gonic/gin" "github.com/sirupsen/logrus" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database" "github.com/go-vela/server/router/middleware/repo" "github.com/go-vela/server/util" - "github.com/go-vela/types/constants" ) // swagger:operation GET /badge/{org}/{repo}/status.svg base GetBadge diff --git a/api/build/approve.go b/api/build/approve.go index 61b1b6a4e..bab499ae6 100644 --- a/api/build/approve.go +++ b/api/build/approve.go @@ -12,6 +12,7 @@ import ( "github.com/gin-gonic/gin" "github.com/sirupsen/logrus" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database" "github.com/go-vela/server/queue" "github.com/go-vela/server/queue/models" @@ -19,7 +20,6 @@ import ( "github.com/go-vela/server/router/middleware/repo" "github.com/go-vela/server/router/middleware/user" "github.com/go-vela/server/util" - "github.com/go-vela/types/constants" ) // swagger:operation POST /api/v1/repos/{org}/{repo}/builds/{build}/approve builds ApproveBuild diff --git a/api/build/auto_cancel.go b/api/build/auto_cancel.go index 7f8a77f81..c34d24917 100644 --- a/api/build/auto_cancel.go +++ b/api/build/auto_cancel.go @@ -16,9 +16,9 @@ import ( "github.com/go-vela/server/api/types" "github.com/go-vela/server/compiler/types/pipeline" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database" "github.com/go-vela/server/internal/token" - "github.com/go-vela/types/constants" ) // AutoCancel is a helper function that checks to see if any pending or running diff --git a/api/build/auto_cancel_test.go b/api/build/auto_cancel_test.go index d3ad75ae7..bcd52ae6d 100644 --- a/api/build/auto_cancel_test.go +++ b/api/build/auto_cancel_test.go @@ -7,7 +7,7 @@ import ( "github.com/go-vela/server/api/types" "github.com/go-vela/server/compiler/types/pipeline" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) func Test_isCancelable(t *testing.T) { diff --git a/api/build/cancel.go b/api/build/cancel.go index 79d186799..3804f5deb 100644 --- a/api/build/cancel.go +++ b/api/build/cancel.go @@ -13,6 +13,7 @@ import ( "github.com/gin-gonic/gin" "github.com/sirupsen/logrus" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database" "github.com/go-vela/server/internal/token" "github.com/go-vela/server/router/middleware/build" @@ -20,7 +21,6 @@ import ( "github.com/go-vela/server/router/middleware/repo" "github.com/go-vela/server/router/middleware/user" "github.com/go-vela/server/util" - "github.com/go-vela/types/constants" ) // swagger:operation DELETE /api/v1/repos/{org}/{repo}/builds/{build}/cancel builds CancelBuild diff --git a/api/build/clean.go b/api/build/clean.go index 5c70b5164..ead0f164b 100644 --- a/api/build/clean.go +++ b/api/build/clean.go @@ -10,15 +10,14 @@ import ( "github.com/sirupsen/logrus" "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database" - "github.com/go-vela/types/constants" - "github.com/go-vela/types/library" ) // cleanBuild is a helper function to kill the build // without execution. This will kill all resources, // like steps and services, for the build. -func CleanBuild(ctx context.Context, database database.Interface, b *types.Build, services []*library.Service, steps []*library.Step, e error) { +func CleanBuild(ctx context.Context, database database.Interface, b *types.Build, services []*types.Service, steps []*types.Step, e error) { l := logrus.WithFields(logrus.Fields{ "build": b.GetNumber(), "build_id": b.GetID(), diff --git a/api/build/compile_publish.go b/api/build/compile_publish.go index 05111de4a..cc99e8579 100644 --- a/api/build/compile_publish.go +++ b/api/build/compile_publish.go @@ -16,12 +16,12 @@ import ( "github.com/go-vela/server/api/types" "github.com/go-vela/server/compiler" "github.com/go-vela/server/compiler/types/pipeline" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database" "github.com/go-vela/server/internal" "github.com/go-vela/server/queue" "github.com/go-vela/server/queue/models" "github.com/go-vela/server/scm" - "github.com/go-vela/types/constants" ) // CompileAndPublishConfig is a struct that contains information for the CompileAndPublish function. diff --git a/api/build/graph.go b/api/build/graph.go index 086c9261d..5db83eaa4 100644 --- a/api/build/graph.go +++ b/api/build/graph.go @@ -11,8 +11,10 @@ import ( "github.com/gin-gonic/gin" "github.com/sirupsen/logrus" + "github.com/go-vela/server/api/types" "github.com/go-vela/server/compiler" "github.com/go-vela/server/compiler/types/pipeline" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database" "github.com/go-vela/server/internal" "github.com/go-vela/server/router/middleware/build" @@ -20,8 +22,6 @@ import ( "github.com/go-vela/server/router/middleware/user" "github.com/go-vela/server/scm" "github.com/go-vela/server/util" - "github.com/go-vela/types/constants" - "github.com/go-vela/types/library" ) // Graph contains nodes, and relationships between nodes, or edges. @@ -46,10 +46,10 @@ type node struct { Name string `json:"name"` // vela metadata - Status string `json:"status"` - StartedAt int `json:"started_at"` - FinishedAt int `json:"finished_at"` - Steps []*library.Step `json:"steps"` + Status string `json:"status"` + StartedAt int `json:"started_at"` + FinishedAt int `json:"finished_at"` + Steps []*types.Step `json:"steps"` // unexported data used for building edges Stage *pipeline.Stage `json:"-"` @@ -67,7 +67,7 @@ type edge struct { // stg represents a stage's steps and some metadata for producing node/edge information. type stg struct { - steps []*library.Step + steps []*types.Step // used for tracking stage status success int running int @@ -241,7 +241,7 @@ func GetBuildGraph(c *gin.Context) { } // retrieve the steps for the build from the step table - steps := []*library.Step{} + steps := []*types.Step{} page := 1 perPage := 100 @@ -279,7 +279,7 @@ func GetBuildGraph(c *gin.Context) { } // retrieve the services for the build from the service table - services := []*library.Service{} + services := []*types.Service{} page = 1 perPage = 100 @@ -359,7 +359,7 @@ func GetBuildGraph(c *gin.Context) { // initialize a stage tracker if _, ok := stageMap[name]; !ok { stageMap[name] = &stg{ - steps: []*library.Step{}, + steps: []*types.Step{}, } } @@ -615,13 +615,13 @@ func nodeFromStage(nodeID, cluster int, stage *pipeline.Stage, s *stg) *node { } // nodeFromService returns a new node from a service. -func nodeFromService(nodeID int, service *library.Service) *node { +func nodeFromService(nodeID int, service *types.Service) *node { return &node{ ID: nodeID, Cluster: ServiceCluster, Name: service.GetName(), Stage: nil, - Steps: []*library.Step{}, + Steps: []*types.Step{}, Status: service.GetStatus(), StartedAt: int(service.GetStarted()), FinishedAt: int(service.GetFinished()), diff --git a/api/build/list_org.go b/api/build/list_org.go index 6dca24e1b..fd00559ef 100644 --- a/api/build/list_org.go +++ b/api/build/list_org.go @@ -12,12 +12,12 @@ import ( "github.com/go-vela/server/api" "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database" "github.com/go-vela/server/router/middleware/org" "github.com/go-vela/server/router/middleware/user" "github.com/go-vela/server/scm" "github.com/go-vela/server/util" - "github.com/go-vela/types/constants" ) // swagger:operation GET /api/v1/repos/{org}/builds builds ListBuildsForOrg diff --git a/api/build/list_repo.go b/api/build/list_repo.go index 44ffee206..1d7fae833 100644 --- a/api/build/list_repo.go +++ b/api/build/list_repo.go @@ -13,10 +13,10 @@ import ( "github.com/go-vela/server/api" "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database" "github.com/go-vela/server/router/middleware/repo" "github.com/go-vela/server/util" - "github.com/go-vela/types/constants" ) // swagger:operation GET /api/v1/repos/{org}/{repo}/builds builds ListBuildsForRepo diff --git a/api/build/restart.go b/api/build/restart.go index 24b30409d..56cffae38 100644 --- a/api/build/restart.go +++ b/api/build/restart.go @@ -12,6 +12,7 @@ import ( "github.com/sirupsen/logrus" "github.com/go-vela/server/compiler" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database" "github.com/go-vela/server/internal" "github.com/go-vela/server/queue" @@ -21,7 +22,6 @@ import ( "github.com/go-vela/server/router/middleware/user" "github.com/go-vela/server/scm" "github.com/go-vela/server/util" - "github.com/go-vela/types/constants" ) // swagger:operation POST /api/v1/repos/{org}/{repo}/builds/{build} builds RestartBuild diff --git a/api/build/token.go b/api/build/token.go index b2126bb84..e626b9379 100644 --- a/api/build/token.go +++ b/api/build/token.go @@ -11,12 +11,12 @@ import ( "github.com/gin-gonic/gin" "github.com/sirupsen/logrus" + "github.com/go-vela/server/constants" "github.com/go-vela/server/internal/token" "github.com/go-vela/server/router/middleware/build" "github.com/go-vela/server/router/middleware/claims" "github.com/go-vela/server/router/middleware/repo" "github.com/go-vela/server/util" - "github.com/go-vela/types/constants" "github.com/go-vela/types/library" ) diff --git a/api/build/update.go b/api/build/update.go index eabe94981..83fc3f9b3 100644 --- a/api/build/update.go +++ b/api/build/update.go @@ -10,13 +10,12 @@ import ( "github.com/sirupsen/logrus" "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database" "github.com/go-vela/server/router/middleware/build" "github.com/go-vela/server/router/middleware/repo" "github.com/go-vela/server/scm" "github.com/go-vela/server/util" - "github.com/go-vela/types/constants" - "github.com/go-vela/types/library" ) // swagger:operation PUT /api/v1/repos/{org}/{repo}/builds/{build} builds UpdateBuild @@ -191,7 +190,7 @@ func UpdateComponentStatuses(c *gin.Context, b *types.Build, status string) erro l.Debug("updating component statuses") // retrieve the steps for the build from the step table - steps := []*library.Step{} + steps := []*types.Step{} page := 1 perPage := 100 @@ -230,7 +229,7 @@ func UpdateComponentStatuses(c *gin.Context, b *types.Build, status string) erro } // retrieve the services for the build from the service table - services := []*library.Service{} + services := []*types.Service{} page = 1 for page > 0 { diff --git a/api/metrics.go b/api/metrics.go index e23fa1d62..77609c497 100644 --- a/api/metrics.go +++ b/api/metrics.go @@ -12,9 +12,9 @@ import ( "github.com/prometheus/client_golang/prometheus/promhttp" "github.com/sirupsen/logrus" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database" "github.com/go-vela/server/queue" - "github.com/go-vela/types/constants" ) // MetricsQueryParameters holds query parameter information pertaining to requested metrics. diff --git a/api/repo/create.go b/api/repo/create.go index cdd6848a3..3e35be3f0 100644 --- a/api/repo/create.go +++ b/api/repo/create.go @@ -14,12 +14,12 @@ import ( "github.com/go-vela/server/api/types" "github.com/go-vela/server/api/types/actions" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database" "github.com/go-vela/server/router/middleware/settings" "github.com/go-vela/server/router/middleware/user" "github.com/go-vela/server/scm" "github.com/go-vela/server/util" - "github.com/go-vela/types/constants" ) // swagger:operation POST /api/v1/repos repos CreateRepo diff --git a/api/repo/list_org.go b/api/repo/list_org.go index ba306e942..75f6a2aa1 100644 --- a/api/repo/list_org.go +++ b/api/repo/list_org.go @@ -11,12 +11,12 @@ import ( "github.com/sirupsen/logrus" "github.com/go-vela/server/api" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database" "github.com/go-vela/server/router/middleware/org" "github.com/go-vela/server/router/middleware/user" "github.com/go-vela/server/scm" "github.com/go-vela/server/util" - "github.com/go-vela/types/constants" ) // swagger:operation GET /api/v1/repos/{org} repos ListReposForOrg diff --git a/api/repo/update.go b/api/repo/update.go index 683df18bc..001a67626 100644 --- a/api/repo/update.go +++ b/api/repo/update.go @@ -13,12 +13,12 @@ import ( "github.com/sirupsen/logrus" "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database" "github.com/go-vela/server/router/middleware/repo" "github.com/go-vela/server/router/middleware/user" "github.com/go-vela/server/scm" "github.com/go-vela/server/util" - "github.com/go-vela/types/constants" ) // swagger:operation PUT /api/v1/repos/{org}/{repo} repos UpdateRepo diff --git a/api/secret/create.go b/api/secret/create.go index 2a2ee8af8..fd89341b9 100644 --- a/api/secret/create.go +++ b/api/secret/create.go @@ -13,11 +13,11 @@ import ( "github.com/go-vela/server/api/types" "github.com/go-vela/server/api/types/actions" + "github.com/go-vela/server/constants" "github.com/go-vela/server/router/middleware/user" "github.com/go-vela/server/scm" "github.com/go-vela/server/secret" "github.com/go-vela/server/util" - "github.com/go-vela/types/constants" ) // swagger:operation POST /api/v1/secrets/{engine}/{type}/{org}/{name} secrets CreateSecret diff --git a/api/secret/delete.go b/api/secret/delete.go index c038c1a08..f50e1e619 100644 --- a/api/secret/delete.go +++ b/api/secret/delete.go @@ -10,9 +10,9 @@ import ( "github.com/gin-gonic/gin" "github.com/sirupsen/logrus" + "github.com/go-vela/server/constants" "github.com/go-vela/server/secret" "github.com/go-vela/server/util" - "github.com/go-vela/types/constants" ) // swagger:operation DELETE /api/v1/secrets/{engine}/{type}/{org}/{name}/{secret} secrets DeleteSecret diff --git a/api/secret/get.go b/api/secret/get.go index 72a84fc18..71f0f3d60 100644 --- a/api/secret/get.go +++ b/api/secret/get.go @@ -10,10 +10,10 @@ import ( "github.com/gin-gonic/gin" "github.com/sirupsen/logrus" + "github.com/go-vela/server/constants" "github.com/go-vela/server/router/middleware/claims" "github.com/go-vela/server/secret" "github.com/go-vela/server/util" - "github.com/go-vela/types/constants" ) // swagger:operation GET /api/v1/secrets/{engine}/{type}/{org}/{name}/{secret} secrets GetSecret diff --git a/api/secret/list.go b/api/secret/list.go index 7f1ac50b5..f7e21e706 100644 --- a/api/secret/list.go +++ b/api/secret/list.go @@ -13,11 +13,11 @@ import ( "github.com/go-vela/server/api" "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/router/middleware/user" "github.com/go-vela/server/scm" "github.com/go-vela/server/secret" "github.com/go-vela/server/util" - "github.com/go-vela/types/constants" ) // swagger:operation GET /api/v1/secrets/{engine}/{type}/{org}/{name} secrets ListSecrets diff --git a/api/secret/update.go b/api/secret/update.go index a5226c3bc..dbd5eb971 100644 --- a/api/secret/update.go +++ b/api/secret/update.go @@ -12,10 +12,10 @@ import ( "github.com/sirupsen/logrus" "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/router/middleware/user" "github.com/go-vela/server/secret" "github.com/go-vela/server/util" - "github.com/go-vela/types/constants" ) // diff --git a/api/service/create.go b/api/service/create.go index 4e3ee47c7..fd8909f20 100644 --- a/api/service/create.go +++ b/api/service/create.go @@ -10,12 +10,12 @@ import ( "github.com/gin-gonic/gin" "github.com/sirupsen/logrus" + "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database" "github.com/go-vela/server/router/middleware/build" "github.com/go-vela/server/router/middleware/repo" "github.com/go-vela/server/util" - "github.com/go-vela/types/constants" - "github.com/go-vela/types/library" ) // swagger:operation POST /api/v1/repos/{org}/{repo}/builds/{build}/services services CreateService @@ -85,7 +85,7 @@ func CreateService(c *gin.Context) { l.Debugf("creating new service for build %s", entry) // capture body from API request - input := new(library.Service) + input := new(types.Service) err := c.Bind(input) if err != nil { diff --git a/api/service/plan.go b/api/service/plan.go index 6efa6b2a5..afe7c0c32 100644 --- a/api/service/plan.go +++ b/api/service/plan.go @@ -11,22 +11,22 @@ import ( "github.com/go-vela/server/api/types" "github.com/go-vela/server/compiler/types/pipeline" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database" - "github.com/go-vela/types/constants" "github.com/go-vela/types/library" ) // PlanServices is a helper function to plan all services // in the build for execution. This creates the services // for the build. -func PlanServices(ctx context.Context, database database.Interface, p *pipeline.Build, b *types.Build) ([]*library.Service, error) { +func PlanServices(ctx context.Context, database database.Interface, p *pipeline.Build, b *types.Build) ([]*types.Service, error) { // variable to store planned services - services := []*library.Service{} + services := []*types.Service{} // iterate through all pipeline services for _, service := range p.Services { // create the service object - s := new(library.Service) + s := new(types.Service) s.SetBuildID(b.GetID()) s.SetRepoID(b.GetRepo().GetID()) s.SetName(service.Name) diff --git a/api/service/update.go b/api/service/update.go index a7e047a60..5815f1abb 100644 --- a/api/service/update.go +++ b/api/service/update.go @@ -9,12 +9,12 @@ import ( "github.com/gin-gonic/gin" "github.com/sirupsen/logrus" + "github.com/go-vela/server/api/types" "github.com/go-vela/server/database" "github.com/go-vela/server/router/middleware/build" "github.com/go-vela/server/router/middleware/repo" "github.com/go-vela/server/router/middleware/service" "github.com/go-vela/server/util" - "github.com/go-vela/types/library" ) // @@ -91,7 +91,7 @@ func UpdateService(c *gin.Context) { l.Debugf("updating service %s", entry) // capture body from API request - input := new(library.Service) + input := new(types.Service) err := c.Bind(input) if err != nil { diff --git a/api/step/create.go b/api/step/create.go index b9a113de4..6bbbe7746 100644 --- a/api/step/create.go +++ b/api/step/create.go @@ -10,12 +10,12 @@ import ( "github.com/gin-gonic/gin" "github.com/sirupsen/logrus" + "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database" "github.com/go-vela/server/router/middleware/build" "github.com/go-vela/server/router/middleware/repo" "github.com/go-vela/server/util" - "github.com/go-vela/types/constants" - "github.com/go-vela/types/library" ) // swagger:operation POST /api/v1/repos/{org}/{repo}/builds/{build}/steps steps CreateStep @@ -85,7 +85,7 @@ func CreateStep(c *gin.Context) { l.Debugf("creating new step for build %s", entry) // capture body from API request - input := new(library.Step) + input := new(types.Step) err := c.Bind(input) if err != nil { diff --git a/api/step/plan.go b/api/step/plan.go index 5bbc1ac84..9b6356fec 100644 --- a/api/step/plan.go +++ b/api/step/plan.go @@ -11,18 +11,18 @@ import ( "github.com/go-vela/server/api/types" "github.com/go-vela/server/compiler/types/pipeline" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database" "github.com/go-vela/server/scm" - "github.com/go-vela/types/constants" "github.com/go-vela/types/library" ) // PlanSteps is a helper function to plan all steps // in the build for execution. This creates the steps // for the build. -func PlanSteps(ctx context.Context, database database.Interface, scm scm.Service, p *pipeline.Build, b *types.Build) ([]*library.Step, error) { +func PlanSteps(ctx context.Context, database database.Interface, scm scm.Service, p *pipeline.Build, b *types.Build) ([]*types.Step, error) { // variable to store planned steps - steps := []*library.Step{} + steps := []*types.Step{} // iterate through all pipeline stages for _, stage := range p.Stages { @@ -51,9 +51,9 @@ func PlanSteps(ctx context.Context, database database.Interface, scm scm.Service return steps, nil } -func planStep(ctx context.Context, database database.Interface, scm scm.Service, b *types.Build, c *pipeline.Container, stage string) (*library.Step, error) { +func planStep(ctx context.Context, database database.Interface, scm scm.Service, b *types.Build, c *pipeline.Container, stage string) (*types.Step, error) { // create the step object - s := new(library.Step) + s := new(types.Step) s.SetBuildID(b.GetID()) s.SetRepoID(b.GetRepo().GetID()) s.SetNumber(c.Number) diff --git a/api/step/update.go b/api/step/update.go index c543de2c8..d456956d6 100644 --- a/api/step/update.go +++ b/api/step/update.go @@ -9,14 +9,14 @@ import ( "github.com/gin-gonic/gin" "github.com/sirupsen/logrus" + "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database" "github.com/go-vela/server/router/middleware/build" "github.com/go-vela/server/router/middleware/repo" "github.com/go-vela/server/router/middleware/step" "github.com/go-vela/server/scm" "github.com/go-vela/server/util" - "github.com/go-vela/types/constants" - "github.com/go-vela/types/library" ) // swagger:operation PUT /api/v1/repos/{org}/{repo}/builds/{build}/steps/{step} steps UpdateStep @@ -92,7 +92,7 @@ func UpdateStep(c *gin.Context) { l.Debugf("updating step %s", entry) // capture body from API request - input := new(library.Step) + input := new(types.Step) err := c.Bind(input) if err != nil { diff --git a/api/types/actions/comment.go b/api/types/actions/comment.go index 552aa3800..716d87a3c 100644 --- a/api/types/actions/comment.go +++ b/api/types/actions/comment.go @@ -2,7 +2,7 @@ package actions -import "github.com/go-vela/types/constants" +import "github.com/go-vela/server/constants" // Comment is the API representation of the various actions associated // with the comment event webhook from the SCM. diff --git a/api/types/actions/comment_test.go b/api/types/actions/comment_test.go index 1ffc465b8..2344f1d3b 100644 --- a/api/types/actions/comment_test.go +++ b/api/types/actions/comment_test.go @@ -6,7 +6,7 @@ import ( "reflect" "testing" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) func TestTypes_Comment_Getters(t *testing.T) { diff --git a/api/types/actions/deploy.go b/api/types/actions/deploy.go index 5dd7a4242..1664c39d3 100644 --- a/api/types/actions/deploy.go +++ b/api/types/actions/deploy.go @@ -3,7 +3,7 @@ //nolint:dupl // similar code to schedule.go package actions -import "github.com/go-vela/types/constants" +import "github.com/go-vela/server/constants" // Deploy is the API representation of the various actions associated // with the deploy event webhook from the SCM. diff --git a/api/types/actions/deploy_test.go b/api/types/actions/deploy_test.go index 373407c7f..05809764c 100644 --- a/api/types/actions/deploy_test.go +++ b/api/types/actions/deploy_test.go @@ -6,7 +6,7 @@ import ( "reflect" "testing" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) func TestTypes_Deploy_Getters(t *testing.T) { diff --git a/api/types/actions/pull.go b/api/types/actions/pull.go index fd35fe7eb..1635709d5 100644 --- a/api/types/actions/pull.go +++ b/api/types/actions/pull.go @@ -2,7 +2,7 @@ package actions -import "github.com/go-vela/types/constants" +import "github.com/go-vela/server/constants" // Pull is the API representation of the various actions associated // with the pull_request event webhook from the SCM. diff --git a/api/types/actions/pull_test.go b/api/types/actions/pull_test.go index 0ff17d6ad..4be4b0b60 100644 --- a/api/types/actions/pull_test.go +++ b/api/types/actions/pull_test.go @@ -6,7 +6,7 @@ import ( "reflect" "testing" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) func TestActions_Pull_Getters(t *testing.T) { diff --git a/api/types/actions/push.go b/api/types/actions/push.go index 6d5b24a6f..e48eb0f3d 100644 --- a/api/types/actions/push.go +++ b/api/types/actions/push.go @@ -2,7 +2,7 @@ package actions -import "github.com/go-vela/types/constants" +import "github.com/go-vela/server/constants" // Push is the API representation of the various actions associated // with the push event webhook from the SCM. diff --git a/api/types/actions/push_test.go b/api/types/actions/push_test.go index 259f7db2b..1d1be093a 100644 --- a/api/types/actions/push_test.go +++ b/api/types/actions/push_test.go @@ -6,7 +6,7 @@ import ( "reflect" "testing" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) func TestTypes_Push_Getters(t *testing.T) { diff --git a/api/types/actions/schedule.go b/api/types/actions/schedule.go index bc4588d2f..296f0ba16 100644 --- a/api/types/actions/schedule.go +++ b/api/types/actions/schedule.go @@ -3,7 +3,7 @@ //nolint:dupl // similar code to deploy.go package actions -import "github.com/go-vela/types/constants" +import "github.com/go-vela/server/constants" // Schedule is the API representation of the various actions associated // with the schedule event. diff --git a/api/types/actions/schedule_test.go b/api/types/actions/schedule_test.go index 8a06b0d75..5d3c9fa03 100644 --- a/api/types/actions/schedule_test.go +++ b/api/types/actions/schedule_test.go @@ -6,7 +6,7 @@ import ( "reflect" "testing" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) func TestTypes_Schedule_Getters(t *testing.T) { diff --git a/api/types/build.go b/api/types/build.go index f9ba8ea49..f5af28911 100644 --- a/api/types/build.go +++ b/api/types/build.go @@ -8,7 +8,7 @@ import ( "time" "github.com/go-vela/server/compiler/types/raw" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) // Build is the API types representation of a build for a pipeline. diff --git a/api/types/events.go b/api/types/events.go index 8bf27db8c..0bc0b10ee 100644 --- a/api/types/events.go +++ b/api/types/events.go @@ -6,7 +6,7 @@ import ( "fmt" "github.com/go-vela/server/api/types/actions" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) // Events is the API representation of the various events that generate a diff --git a/api/types/events_test.go b/api/types/events_test.go index 68f6f5709..882364f97 100644 --- a/api/types/events_test.go +++ b/api/types/events_test.go @@ -9,7 +9,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/go-vela/server/api/types/actions" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) func TestTypes_Events_Getters(t *testing.T) { diff --git a/api/types/repo_test.go b/api/types/repo_test.go index 2cbe84639..c7e20407d 100644 --- a/api/types/repo_test.go +++ b/api/types/repo_test.go @@ -9,7 +9,7 @@ import ( "github.com/google/go-cmp/cmp" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) func TestTypes_Repo_Environment(t *testing.T) { diff --git a/api/types/secret.go b/api/types/secret.go index ef82e9e9f..53f3b8163 100644 --- a/api/types/secret.go +++ b/api/types/secret.go @@ -6,7 +6,7 @@ import ( "fmt" "strings" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" "github.com/go-vela/types/pipeline" ) diff --git a/api/types/secret_test.go b/api/types/secret_test.go index ffa4aa107..e84f4f6d5 100644 --- a/api/types/secret_test.go +++ b/api/types/secret_test.go @@ -11,7 +11,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/go-vela/server/api/types/actions" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" "github.com/go-vela/types/pipeline" ) diff --git a/api/types/service.go b/api/types/service.go new file mode 100644 index 000000000..075beb44f --- /dev/null +++ b/api/types/service.go @@ -0,0 +1,645 @@ +// SPDX-License-Identifier: Apache-2.0 + +package types + +import ( + "fmt" + "strconv" + "time" + + "github.com/go-vela/server/compiler/types/pipeline" + "github.com/go-vela/server/constants" +) + +// Service is the API representation of a service in a build. +// +// swagger:model Service +type Service struct { + ID *int64 `json:"id,omitempty"` + BuildID *int64 `json:"build_id,omitempty"` + RepoID *int64 `json:"repo_id,omitempty"` + Number *int `json:"number,omitempty"` + Name *string `json:"name,omitempty"` + Image *string `json:"image,omitempty"` + Status *string `json:"status,omitempty"` + Error *string `json:"error,omitempty"` + ExitCode *int `json:"exit_code,omitempty"` + Created *int64 `json:"created,omitempty"` + Started *int64 `json:"started,omitempty"` + Finished *int64 `json:"finished,omitempty"` + Host *string `json:"host,omitempty"` + Runtime *string `json:"runtime,omitempty"` + Distribution *string `json:"distribution,omitempty"` +} + +// Duration calculates and returns the total amount of +// time the service ran for in a human-readable format. +func (s *Service) Duration() string { + // check if the service doesn't have a started timestamp + if s.GetStarted() == 0 { + return "..." + } + + // capture started unix timestamp from the service + started := time.Unix(s.GetStarted(), 0) + + // check if the service doesn't have a finished timestamp + if s.GetFinished() == 0 { + // return the duration in a human-readable form by + // subtracting the service started time from the + // current time rounded to the nearest second + return time.Since(started).Round(time.Second).String() + } + + // capture finished unix timestamp from the service + finished := time.Unix(s.GetFinished(), 0) + + // calculate the duration by subtracting the service + // started time from the service finished time + duration := finished.Sub(started) + + // return the duration in a human-readable form + return duration.String() +} + +// Environment returns a list of environment variables +// provided from the fields of the Service type. +func (s *Service) Environment() map[string]string { + return map[string]string{ + "VELA_SERVICE_CREATED": ToString(s.GetCreated()), + "VELA_SERVICE_DISTRIBUTION": ToString(s.GetDistribution()), + "VELA_SERVICE_EXIT_CODE": ToString(s.GetExitCode()), + "VELA_SERVICE_HOST": ToString(s.GetHost()), + "VELA_SERVICE_IMAGE": ToString(s.GetImage()), + "VELA_SERVICE_NAME": ToString(s.GetName()), + "VELA_SERVICE_NUMBER": ToString(s.GetNumber()), + "VELA_SERVICE_RUNTIME": ToString(s.GetRuntime()), + "VELA_SERVICE_STARTED": ToString(s.GetStarted()), + "VELA_SERVICE_STATUS": ToString(s.GetStatus()), + } +} + +// GetID returns the ID field. +// +// When the provided Service type is nil, or the field within +// the type is nil, it returns the zero value for the field. +func (s *Service) GetID() int64 { + // return zero value if Service type or ID field is nil + if s == nil || s.ID == nil { + return 0 + } + + return *s.ID +} + +// GetBuildID returns the BuildID field. +// +// When the provided Service type is nil, or the field within +// the type is nil, it returns the zero value for the field. +func (s *Service) GetBuildID() int64 { + // return zero value if Service type or BuildID field is nil + if s == nil || s.BuildID == nil { + return 0 + } + + return *s.BuildID +} + +// GetRepoID returns the RepoID field. +// +// When the provided Service type is nil, or the field within +// the type is nil, it returns the zero value for the field. +func (s *Service) GetRepoID() int64 { + // return zero value if Service type or RepoID field is nil + if s == nil || s.RepoID == nil { + return 0 + } + + return *s.RepoID +} + +// GetNumber returns the Number field. +// +// When the provided Service type is nil, or the field within +// the type is nil, it returns the zero value for the field. +func (s *Service) GetNumber() int { + // return zero value if Service type or Number field is nil + if s == nil || s.Number == nil { + return 0 + } + + return *s.Number +} + +// GetName returns the Name field. +// +// When the provided Service type is nil, or the field within +// the type is nil, it returns the zero value for the field. +func (s *Service) GetName() string { + // return zero value if Service type or Name field is nil + if s == nil || s.Name == nil { + return "" + } + + return *s.Name +} + +// GetImage returns the Image field. +// +// When the provided Service type is nil, or the field within +// the type is nil, it returns the zero value for the field. +func (s *Service) GetImage() string { + // return zero value if Service type or Image field is nil + if s == nil || s.Image == nil { + return "" + } + + return *s.Image +} + +// GetStatus returns the Status field. +// +// When the provided Service type is nil, or the field within +// the type is nil, it returns the zero value for the field. +func (s *Service) GetStatus() string { + // return zero value if Service type or Status field is nil + if s == nil || s.Status == nil { + return "" + } + + return *s.Status +} + +// GetError returns the Error field. +// +// When the provided Service type is nil, or the field within +// the type is nil, it returns the zero value for the field. +func (s *Service) GetError() string { + // return zero value if Service type or Error field is nil + if s == nil || s.Error == nil { + return "" + } + + return *s.Error +} + +// GetExitCode returns the ExitCode field. +// +// When the provided Service type is nil, or the field within +// the type is nil, it returns the zero value for the field. +func (s *Service) GetExitCode() int { + // return zero value if Service type or ExitCode field is nil + if s == nil || s.ExitCode == nil { + return 0 + } + + return *s.ExitCode +} + +// GetCreated returns the Created field. +// +// When the provided Service type is nil, or the field within +// the type is nil, it returns the zero value for the field. +func (s *Service) GetCreated() int64 { + // return zero value if Service type or Created field is nil + if s == nil || s.Created == nil { + return 0 + } + + return *s.Created +} + +// GetStarted returns the Started field. +// +// When the provided Service type is nil, or the field within +// the type is nil, it returns the zero value for the field. +func (s *Service) GetStarted() int64 { + // return zero value if Service type or Started field is nil + if s == nil || s.Started == nil { + return 0 + } + + return *s.Started +} + +// GetFinished returns the Finished field. +// +// When the provided Service type is nil, or the field within +// the type is nil, it returns the zero value for the field. +func (s *Service) GetFinished() int64 { + // return zero value if Service type or Finished field is nil + if s == nil || s.Finished == nil { + return 0 + } + + return *s.Finished +} + +// GetHost returns the Host field. +// +// When the provided Service type is nil, or the field within +// the type is nil, it returns the zero value for the field. +func (s *Service) GetHost() string { + // return zero value if Service type or Host field is nil + if s == nil || s.Host == nil { + return "" + } + + return *s.Host +} + +// GetRuntime returns the Runtime field. +// +// When the provided Service type is nil, or the field within +// the type is nil, it returns the zero value for the field. +func (s *Service) GetRuntime() string { + // return zero value if Service type or Runtime field is nil + if s == nil || s.Runtime == nil { + return "" + } + + return *s.Runtime +} + +// GetDistribution returns the Runtime field. +// +// When the provided Service type is nil, or the field within +// the type is nil, it returns the zero value for the field. +func (s *Service) GetDistribution() string { + // return zero value if Service type or Distribution field is nil + if s == nil || s.Distribution == nil { + return "" + } + + return *s.Distribution +} + +// SetID sets the ID field. +// +// When the provided Service type is nil, it +// will set nothing and immediately return. +func (s *Service) SetID(v int64) { + // return if Service type is nil + if s == nil { + return + } + + s.ID = &v +} + +// SetBuildID sets the BuildID field. +// +// When the provided Service type is nil, it +// will set nothing and immediately return. +func (s *Service) SetBuildID(v int64) { + // return if Service type is nil + if s == nil { + return + } + + s.BuildID = &v +} + +// SetRepoID sets the RepoID field. +// +// When the provided Service type is nil, it +// will set nothing and immediately return. +func (s *Service) SetRepoID(v int64) { + // return if Service type is nil + if s == nil { + return + } + + s.RepoID = &v +} + +// SetNumber sets the Number field. +// +// When the provided Service type is nil, it +// will set nothing and immediately return. +func (s *Service) SetNumber(v int) { + // return if Service type is nil + if s == nil { + return + } + + s.Number = &v +} + +// SetName sets the Name field. +// +// When the provided Service type is nil, it +// will set nothing and immediately return. +func (s *Service) SetName(v string) { + // return if Service type is nil + if s == nil { + return + } + + s.Name = &v +} + +// SetImage sets the Image field. +// +// When the provided Service type is nil, it +// will set nothing and immediately return. +func (s *Service) SetImage(v string) { + // return if Service type is nil + if s == nil { + return + } + + s.Image = &v +} + +// SetStatus sets the Status field. +// +// When the provided Service type is nil, it +// will set nothing and immediately return. +func (s *Service) SetStatus(v string) { + // return if Service type is nil + if s == nil { + return + } + + s.Status = &v +} + +// SetError sets the Error field. +// +// When the provided Service type is nil, it +// will set nothing and immediately return. +func (s *Service) SetError(v string) { + // return if Service type is nil + if s == nil { + return + } + + s.Error = &v +} + +// SetExitCode sets the ExitCode field. +// +// When the provided Service type is nil, it +// will set nothing and immediately return. +func (s *Service) SetExitCode(v int) { + // return if Service type is nil + if s == nil { + return + } + + s.ExitCode = &v +} + +// SetCreated sets the Created field. +// +// When the provided Service type is nil, it +// will set nothing and immediately return. +func (s *Service) SetCreated(v int64) { + // return if Service type is nil + if s == nil { + return + } + + s.Created = &v +} + +// SetStarted sets the Started field. +// +// When the provided Service type is nil, it +// will set nothing and immediately return. +func (s *Service) SetStarted(v int64) { + // return if Service type is nil + if s == nil { + return + } + + s.Started = &v +} + +// SetFinished sets the Finished field. +// +// When the provided Service type is nil, it +// will set nothing and immediately return. +func (s *Service) SetFinished(v int64) { + // return if Service type is nil + if s == nil { + return + } + + s.Finished = &v +} + +// SetHost sets the Host field. +// +// When the provided Service type is nil, it +// will set nothing and immediately return. +func (s *Service) SetHost(v string) { + // return if Service type is nil + if s == nil { + return + } + + s.Host = &v +} + +// SetRuntime sets the Runtime field. +// +// When the provided Service type is nil, it +// will set nothing and immediately return. +func (s *Service) SetRuntime(v string) { + // return if Service type is nil + if s == nil { + return + } + + s.Runtime = &v +} + +// SetDistribution sets the Runtime field. +// +// When the provided Service type is nil, it +// will set nothing and immediately return. +func (s *Service) SetDistribution(v string) { + // return if Service type is nil + if s == nil { + return + } + + s.Distribution = &v +} + +// String implements the Stringer interface for the Service type. +func (s *Service) String() string { + return fmt.Sprintf(`{ + BuildID: %d, + Created: %d, + Distribution: %s, + Error: %s, + ExitCode: %d, + Finished: %d, + Host: %s, + ID: %d, + Image: %s, + Name: %s, + Number: %d, + RepoID: %d, + Runtime: %s, + Started: %d, + Status: %s, +}`, + s.GetBuildID(), + s.GetCreated(), + s.GetDistribution(), + s.GetError(), + s.GetExitCode(), + s.GetFinished(), + s.GetHost(), + s.GetID(), + s.GetImage(), + s.GetName(), + s.GetNumber(), + s.GetRepoID(), + s.GetRuntime(), + s.GetStarted(), + s.GetStatus(), + ) +} + +// ServiceFromBuildContainer creates a new Service based on a Build and pipeline Container. +func ServiceFromBuildContainer(build *Build, ctn *pipeline.Container) *Service { + // create new service type we want to return + s := new(Service) + + // default status to Pending + s.SetStatus(constants.StatusPending) + + // copy fields from build + if build != nil { + // set values from the build + s.SetHost(build.GetHost()) + s.SetRuntime(build.GetRuntime()) + s.SetDistribution(build.GetDistribution()) + } + + // copy fields from container + if ctn != nil && ctn.Name != "" { + // set values from the container + s.SetName(ctn.Name) + s.SetNumber(ctn.Number) + s.SetImage(ctn.Image) + } + + return s +} + +// ServiceFromContainerEnvironment converts the pipeline Container +// to an API Service using the container's Environment. +func ServiceFromContainerEnvironment(ctn *pipeline.Container) *Service { + // check if container or container environment are nil + if ctn == nil || ctn.Environment == nil { + return nil + } + + // create new service type we want to return + s := new(Service) + + // check if the VELA_SERVICE_DISTRIBUTION environment variable exists + value, ok := ctn.Environment["VELA_SERVICE_DISTRIBUTION"] + if ok { + // set the Distribution field to the value from environment variable + s.SetDistribution(value) + } + + // check if the VELA_SERVICE_HOST environment variable exists + value, ok = ctn.Environment["VELA_SERVICE_HOST"] + if ok { + // set the Host field to the value from environment variable + s.SetHost(value) + } + + // check if the VELA_SERVICE_IMAGE environment variable exists + value, ok = ctn.Environment["VELA_SERVICE_IMAGE"] + if ok { + // set the Image field to the value from environment variable + s.SetImage(value) + } + + // check if the VELA_SERVICE_NAME environment variable exists + value, ok = ctn.Environment["VELA_SERVICE_NAME"] + if ok { + // set the Name field to the value from environment variable + s.SetName(value) + } + + // check if the VELA_SERVICE_RUNTIME environment variable exists + value, ok = ctn.Environment["VELA_SERVICE_RUNTIME"] + if ok { + // set the Runtime field to the value from environment variable + s.SetRuntime(value) + } + + // check if the VELA_SERVICE_STATUS environment variable exists + value, ok = ctn.Environment["VELA_SERVICE_STATUS"] + if ok { + // set the Status field to the value from environment variable + s.SetStatus(value) + } + + // check if the VELA_SERVICE_CREATED environment variable exists + value, ok = ctn.Environment["VELA_SERVICE_CREATED"] + if ok { + // parse the environment variable value into an int64 + i, err := strconv.ParseInt(value, 10, 64) + if err == nil { + // set the Created field to the parsed int64 + s.SetCreated(i) + } + } + + // check if the VELA_SERVICE_EXIT_CODE environment variable exists + value, ok = ctn.Environment["VELA_SERVICE_EXIT_CODE"] + if ok { + // parse the environment variable value into an int + i, err := strconv.ParseInt(value, 10, 0) + if err == nil { + // set the ExitCode field to the parsed int + s.SetExitCode(int(i)) + } + } + + // check if the VELA_SERVICE_FINISHED environment variable exists + value, ok = ctn.Environment["VELA_SERVICE_FINISHED"] + if ok { + // parse the environment variable value into an int64 + i, err := strconv.ParseInt(value, 10, 64) + if err == nil { + // set the Finished field to the parsed int64 + s.SetFinished(i) + } + } + + // check if the VELA_SERVICE_NUMBER environment variable exists + value, ok = ctn.Environment["VELA_SERVICE_NUMBER"] + if ok { + // parse the environment variable value into an int + i, err := strconv.ParseInt(value, 10, 0) + if err == nil { + // set the Number field to the parsed int + s.SetNumber(int(i)) + } + } + + // check if the VELA_SERVICE_STARTED environment variable exists + value, ok = ctn.Environment["VELA_SERVICE_STARTED"] + if ok { + // parse the environment variable value into an int64 + i, err := strconv.ParseInt(value, 10, 64) + if err == nil { + // set the Started field to the parsed int64 + s.SetStarted(i) + } + } + + return s +} diff --git a/api/types/service_test.go b/api/types/service_test.go new file mode 100644 index 000000000..41e93bf21 --- /dev/null +++ b/api/types/service_test.go @@ -0,0 +1,449 @@ +// SPDX-License-Identifier: Apache-2.0 + +package types + +import ( + "fmt" + "reflect" + "testing" + "time" + + "github.com/go-vela/server/compiler/types/pipeline" +) + +func TestTypes_Service_Duration(t *testing.T) { + // setup types + unfinished := testService() + unfinished.SetFinished(0) + + // setup tests + tests := []struct { + service *Service + want string + }{ + { + service: testService(), + want: "1s", + }, + { + service: unfinished, + want: time.Since(time.Unix(unfinished.GetStarted(), 0)).Round(time.Second).String(), + }, + { + service: new(Service), + want: "...", + }, + } + + // run tests + for _, test := range tests { + got := test.service.Duration() + + if got != test.want { + t.Errorf("Duration is %v, want %v", got, test.want) + } + } +} + +func TestTypes_Service_Environment(t *testing.T) { + // setup types + want := map[string]string{ + "VELA_SERVICE_CREATED": "1563474076", + "VELA_SERVICE_DISTRIBUTION": "linux", + "VELA_SERVICE_EXIT_CODE": "0", + "VELA_SERVICE_HOST": "example.company.com", + "VELA_SERVICE_IMAGE": "postgres:12-alpine", + "VELA_SERVICE_NAME": "postgres", + "VELA_SERVICE_NUMBER": "1", + "VELA_SERVICE_RUNTIME": "docker", + "VELA_SERVICE_STARTED": "1563474078", + "VELA_SERVICE_STATUS": "running", + } + + // run test + got := testService().Environment() + + if !reflect.DeepEqual(got, want) { + t.Errorf("Environment is %v, want %v", got, want) + } +} + +func TestTypes_Service_Getters(t *testing.T) { + // setup tests + tests := []struct { + service *Service + want *Service + }{ + { + service: testService(), + want: testService(), + }, + { + service: new(Service), + want: new(Service), + }, + } + + // run tests + for _, test := range tests { + if test.service.GetID() != test.want.GetID() { + t.Errorf("GetID is %v, want %v", test.service.GetID(), test.want.GetID()) + } + + if test.service.GetBuildID() != test.want.GetBuildID() { + t.Errorf("GetBuildID is %v, want %v", test.service.GetBuildID(), test.want.GetBuildID()) + } + + if test.service.GetRepoID() != test.want.GetRepoID() { + t.Errorf("GetRepoID is %v, want %v", test.service.GetRepoID(), test.want.GetRepoID()) + } + + if test.service.GetNumber() != test.want.GetNumber() { + t.Errorf("GetNumber is %v, want %v", test.service.GetNumber(), test.want.GetNumber()) + } + + if test.service.GetName() != test.want.GetName() { + t.Errorf("GetName is %v, want %v", test.service.GetName(), test.want.GetName()) + } + + if test.service.GetImage() != test.want.GetImage() { + t.Errorf("GetImage is %v, want %v", test.service.GetImage(), test.want.GetImage()) + } + + if test.service.GetStatus() != test.want.GetStatus() { + t.Errorf("GetStatus is %v, want %v", test.service.GetStatus(), test.want.GetStatus()) + } + + if test.service.GetError() != test.want.GetError() { + t.Errorf("GetError is %v, want %v", test.service.GetError(), test.want.GetError()) + } + + if test.service.GetExitCode() != test.want.GetExitCode() { + t.Errorf("GetExitCode is %v, want %v", test.service.GetExitCode(), test.want.GetExitCode()) + } + + if test.service.GetCreated() != test.want.GetCreated() { + t.Errorf("GetCreated is %v, want %v", test.service.GetCreated(), test.want.GetCreated()) + } + + if test.service.GetStarted() != test.want.GetStarted() { + t.Errorf("GetStarted is %v, want %v", test.service.GetStarted(), test.want.GetStarted()) + } + + if test.service.GetFinished() != test.want.GetFinished() { + t.Errorf("GetFinished is %v, want %v", test.service.GetFinished(), test.want.GetFinished()) + } + + if test.service.GetHost() != test.want.GetHost() { + t.Errorf("GetHost is %v, want %v", test.service.GetHost(), test.want.GetHost()) + } + + if test.service.GetRuntime() != test.want.GetRuntime() { + t.Errorf("GetRuntime is %v, want %v", test.service.GetRuntime(), test.want.GetRuntime()) + } + + if test.service.GetDistribution() != test.want.GetDistribution() { + t.Errorf("GetDistribution is %v, want %v", test.service.GetDistribution(), test.want.GetDistribution()) + } + } +} + +func TestTypes_Service_Setters(t *testing.T) { + // setup types + var s *Service + + // setup tests + tests := []struct { + service *Service + want *Service + }{ + { + service: testService(), + want: testService(), + }, + { + service: s, + want: new(Service), + }, + } + + // run tests + for _, test := range tests { + test.want.SetID(test.service.GetID()) + test.want.SetBuildID(test.service.GetBuildID()) + test.want.SetRepoID(test.service.GetRepoID()) + test.want.SetNumber(test.service.GetNumber()) + test.want.SetName(test.service.GetName()) + test.want.SetImage(test.service.GetImage()) + test.want.SetStatus(test.service.GetStatus()) + test.want.SetError(test.service.GetError()) + test.want.SetExitCode(test.service.GetExitCode()) + test.want.SetCreated(test.service.GetCreated()) + test.want.SetStarted(test.service.GetStarted()) + test.want.SetFinished(test.service.GetFinished()) + test.want.SetHost(test.service.GetHost()) + test.want.SetRuntime(test.service.GetRuntime()) + test.want.SetDistribution(test.service.GetDistribution()) + + if test.want.GetID() != test.service.GetID() { + t.Errorf("SetID is %v, want %v", test.service.GetID(), test.service.GetID()) + } + + if test.want.GetBuildID() != test.service.GetBuildID() { + t.Errorf("SetBuildID is %v, want %v", test.service.GetBuildID(), test.service.GetBuildID()) + } + + if test.want.GetRepoID() != test.service.GetRepoID() { + t.Errorf("SetRepoID is %v, want %v", test.service.GetRepoID(), test.service.GetRepoID()) + } + + if test.want.GetNumber() != test.service.GetNumber() { + t.Errorf("SetNumber is %v, want %v", test.service.GetNumber(), test.service.GetNumber()) + } + + if test.want.GetName() != test.service.GetName() { + t.Errorf("SetName is %v, want %v", test.service.GetName(), test.service.GetName()) + } + + if test.want.GetImage() != test.service.GetImage() { + t.Errorf("SetImage is %v, want %v", test.service.GetImage(), test.service.GetImage()) + } + + if test.want.GetStatus() != test.service.GetStatus() { + t.Errorf("SetStatus is %v, want %v", test.service.GetStatus(), test.service.GetStatus()) + } + + if test.want.GetError() != test.service.GetError() { + t.Errorf("SetError is %v, want %v", test.service.GetError(), test.service.GetError()) + } + + if test.want.GetExitCode() != test.service.GetExitCode() { + t.Errorf("SetExitCode is %v, want %v", test.service.GetExitCode(), test.service.GetExitCode()) + } + + if test.want.GetCreated() != test.service.GetCreated() { + t.Errorf("SetCreated is %v, want %v", test.service.GetCreated(), test.service.GetCreated()) + } + + if test.want.GetStarted() != test.service.GetStarted() { + t.Errorf("SetStarted is %v, want %v", test.service.GetStarted(), test.service.GetStarted()) + } + + if test.want.GetFinished() != test.service.GetFinished() { + t.Errorf("SetFinished is %v, want %v", test.service.GetFinished(), test.service.GetFinished()) + } + + if test.want.GetHost() != test.service.GetHost() { + t.Errorf("SetHost is %v, want %v", test.service.GetHost(), test.service.GetHost()) + } + + if test.want.GetRuntime() != test.service.GetRuntime() { + t.Errorf("SetRuntime is %v, want %v", test.service.GetRuntime(), test.service.GetRuntime()) + } + + if test.want.GetDistribution() != test.service.GetDistribution() { + t.Errorf("SetDistribution is %v, want %v", test.service.GetDistribution(), test.service.GetDistribution()) + } + } +} + +func TestTypes_Service_String(t *testing.T) { + // setup types + s := testService() + + want := fmt.Sprintf(`{ + BuildID: %d, + Created: %d, + Distribution: %s, + Error: %s, + ExitCode: %d, + Finished: %d, + Host: %s, + ID: %d, + Image: %s, + Name: %s, + Number: %d, + RepoID: %d, + Runtime: %s, + Started: %d, + Status: %s, +}`, + s.GetBuildID(), + s.GetCreated(), + s.GetDistribution(), + s.GetError(), + s.GetExitCode(), + s.GetFinished(), + s.GetHost(), + s.GetID(), + s.GetImage(), + s.GetName(), + s.GetNumber(), + s.GetRepoID(), + s.GetRuntime(), + s.GetStarted(), + s.GetStatus(), + ) + + // run test + got := s.String() + + if !reflect.DeepEqual(got, want) { + t.Errorf("String is %v, want %v", got, want) + } +} + +func TestTypes_ServiceFromBuildContainer(t *testing.T) { + // setup types + s := testService() + s.SetStatus("pending") + + // modify fields that aren't set + s.ID = nil + s.BuildID = nil + s.RepoID = nil + s.ExitCode = nil + s.Created = nil + s.Started = nil + s.Finished = nil + + tests := []struct { + name string + container *pipeline.Container + build *Build + want *Service + }{ + { + name: "nil container with nil build", + container: nil, + build: nil, + want: &Service{Status: s.Status}, + }, + { + name: "empty container with nil build", + container: new(pipeline.Container), + build: nil, + want: &Service{Status: s.Status}, + }, + { + name: "nil container with build", + container: nil, + build: testBuild(), + want: &Service{ + Status: s.Status, + Host: s.Host, + Runtime: s.Runtime, + Distribution: s.Distribution, + }, + }, + { + name: "empty container with build", + container: new(pipeline.Container), + build: testBuild(), + want: &Service{ + Status: s.Status, + Host: s.Host, + Runtime: s.Runtime, + Distribution: s.Distribution, + }, + }, + { + name: "container with build", + container: &pipeline.Container{ + Name: s.GetName(), + Number: s.GetNumber(), + Image: s.GetImage(), + }, + build: testBuild(), + want: s, + }, + } + + // run tests + for _, test := range tests { + got := ServiceFromBuildContainer(test.build, test.container) + + if !reflect.DeepEqual(got, test.want) { + t.Errorf("ServiceFromBuildContainer for %s is %v, want %v", test.name, got, test.want) + } + } +} + +func TestTypes_ServiceFromContainerEnvironment(t *testing.T) { + // setup types + s := testService() + + // modify fields that aren't set via environment variables + s.ID = nil + s.BuildID = nil + s.RepoID = nil + + // setup tests + tests := []struct { + name string + container *pipeline.Container + want *Service + }{ + { + name: "nil container", + container: nil, + want: nil, + }, + { + name: "empty container", + container: new(pipeline.Container), + want: nil, + }, + { + name: "container", + container: &pipeline.Container{ + Environment: map[string]string{ + "VELA_SERVICE_CREATED": "1563474076", + "VELA_SERVICE_DISTRIBUTION": "linux", + "VELA_SERVICE_EXIT_CODE": "0", + "VELA_SERVICE_FINISHED": "1563474079", + "VELA_SERVICE_HOST": "example.company.com", + "VELA_SERVICE_IMAGE": "postgres:12-alpine", + "VELA_SERVICE_NAME": "postgres", + "VELA_SERVICE_NUMBER": "1", + "VELA_SERVICE_RUNTIME": "docker", + "VELA_SERVICE_STARTED": "1563474078", + "VELA_SERVICE_STATUS": "running", + }, + }, + want: s, + }, + } + + // run tests + for _, test := range tests { + got := ServiceFromContainerEnvironment(test.container) + + if !reflect.DeepEqual(got, test.want) { + t.Errorf("ServiceFromContainerEnvironment for %s is %v, want %v", test.name, got, test.want) + } + } +} + +// testService is a test helper function to create a Service +// type with all fields set to a fake value. +func testService() *Service { + s := new(Service) + + s.SetID(1) + s.SetBuildID(1) + s.SetRepoID(1) + s.SetNumber(1) + s.SetName("postgres") + s.SetImage("postgres:12-alpine") + s.SetStatus("running") + s.SetExitCode(0) + s.SetCreated(1563474076) + s.SetStarted(1563474078) + s.SetFinished(1563474079) + s.SetHost("example.company.com") + s.SetRuntime("docker") + s.SetDistribution("linux") + + return s +} diff --git a/api/types/step.go b/api/types/step.go new file mode 100644 index 000000000..52d96f45c --- /dev/null +++ b/api/types/step.go @@ -0,0 +1,727 @@ +// SPDX-License-Identifier: Apache-2.0 + +package types + +import ( + "fmt" + "strconv" + "time" + + "github.com/go-vela/server/compiler/types/pipeline" + "github.com/go-vela/server/constants" +) + +// Step is the API representation of a step in a build. +// +// swagger:model Step +type Step struct { + ID *int64 `json:"id,omitempty"` + BuildID *int64 `json:"build_id,omitempty"` + RepoID *int64 `json:"repo_id,omitempty"` + Number *int `json:"number,omitempty"` + Name *string `json:"name,omitempty"` + Image *string `json:"image,omitempty"` + Stage *string `json:"stage,omitempty"` + Status *string `json:"status,omitempty"` + Error *string `json:"error,omitempty"` + ExitCode *int `json:"exit_code,omitempty"` + Created *int64 `json:"created,omitempty"` + Started *int64 `json:"started,omitempty"` + Finished *int64 `json:"finished,omitempty"` + Host *string `json:"host,omitempty"` + Runtime *string `json:"runtime,omitempty"` + Distribution *string `json:"distribution,omitempty"` + ReportAs *string `json:"report_as,omitempty"` +} + +// Duration calculates and returns the total amount of +// time the step ran for in a human-readable format. +func (s *Step) Duration() string { + // check if the step doesn't have a started timestamp + if s.GetStarted() == 0 { + return "..." + } + + // capture started unix timestamp from the step + started := time.Unix(s.GetStarted(), 0) + + // check if the step doesn't have a finished timestamp + if s.GetFinished() == 0 { + // return the duration in a human-readable form by + // subtracting the step started time from the + // current time rounded to the nearest second + return time.Since(started).Round(time.Second).String() + } + + // capture finished unix timestamp from the step + finished := time.Unix(s.GetFinished(), 0) + + // calculate the duration by subtracting the step + // started time from the step finished time + duration := finished.Sub(started) + + // return the duration in a human-readable form + return duration.String() +} + +// Environment returns a list of environment variables +// provided from the fields of the Step type. +func (s *Step) Environment() map[string]string { + return map[string]string{ + "VELA_STEP_CREATED": ToString(s.GetCreated()), + "VELA_STEP_DISTRIBUTION": ToString(s.GetDistribution()), + "VELA_STEP_EXIT_CODE": ToString(s.GetExitCode()), + "VELA_STEP_HOST": ToString(s.GetHost()), + "VELA_STEP_IMAGE": ToString(s.GetImage()), + "VELA_STEP_NAME": ToString(s.GetName()), + "VELA_STEP_NUMBER": ToString(s.GetNumber()), + "VELA_STEP_RUNTIME": ToString(s.GetRuntime()), + "VELA_STEP_STAGE": ToString(s.GetStage()), + "VELA_STEP_STARTED": ToString(s.GetStarted()), + "VELA_STEP_STATUS": ToString(s.GetStatus()), + "VELA_STEP_REPORT_AS": ToString(s.GetReportAs()), + } +} + +// GetID returns the ID field. +// +// When the provided Step type is nil, or the field within +// the type is nil, it returns the zero value for the field. +func (s *Step) GetID() int64 { + // return zero value if Step type or ID field is nil + if s == nil || s.ID == nil { + return 0 + } + + return *s.ID +} + +// GetBuildID returns the BuildID field. +// +// When the provided Step type is nil, or the field within +// the type is nil, it returns the zero value for the field. +func (s *Step) GetBuildID() int64 { + // return zero value if Step type or BuildID field is nil + if s == nil || s.BuildID == nil { + return 0 + } + + return *s.BuildID +} + +// GetRepoID returns the RepoID field. +// +// When the provided Step type is nil, or the field within +// the type is nil, it returns the zero value for the field. +func (s *Step) GetRepoID() int64 { + // return zero value if Step type or RepoID field is nil + if s == nil || s.RepoID == nil { + return 0 + } + + return *s.RepoID +} + +// GetNumber returns the Number field. +// +// When the provided Step type is nil, or the field within +// the type is nil, it returns the zero value for the field. +func (s *Step) GetNumber() int { + // return zero value if Step type or Number field is nil + if s == nil || s.Number == nil { + return 0 + } + + return *s.Number +} + +// GetName returns the Name field. +// +// When the provided Step type is nil, or the field within +// the type is nil, it returns the zero value for the field. +func (s *Step) GetName() string { + // return zero value if Step type or Name field is nil + if s == nil || s.Name == nil { + return "" + } + + return *s.Name +} + +// GetImage returns the Image field. +// +// When the provided Step type is nil, or the field within +// the type is nil, it returns the zero value for the field. +func (s *Step) GetImage() string { + // return zero value if Step type of Image field is nil + if s == nil || s.Image == nil { + return "" + } + + return *s.Image +} + +// GetStage returns the Stage field. +// +// When the provided Step type is nil, or the field within +// the type is nil, it returns the zero value for the field. +func (s *Step) GetStage() string { + // return zero value if Step type or Stage field is nil + if s == nil || s.Stage == nil { + return "" + } + + return *s.Stage +} + +// GetStatus returns the Status field. +// +// When the provided Step type is nil, or the field within +// the type is nil, it returns the zero value for the field. +func (s *Step) GetStatus() string { + // return zero value if Step type or Status field is nil + if s == nil || s.Status == nil { + return "" + } + + return *s.Status +} + +// GetError returns the Error field. +// +// When the provided Step type is nil, or the field within +// the type is nil, it returns the zero value for the field. +func (s *Step) GetError() string { + // return zero value if Step type or Error field is nil + if s == nil || s.Error == nil { + return "" + } + + return *s.Error +} + +// GetExitCode returns the ExitCode field. +// +// When the provided Step type is nil, or the field within +// the type is nil, it returns the zero value for the field. +func (s *Step) GetExitCode() int { + // return zero value if Step type or ExitCode field is nil + if s == nil || s.ExitCode == nil { + return 0 + } + + return *s.ExitCode +} + +// GetCreated returns the Created field. +// +// When the provided Step type is nil, or the field within +// the type is nil, it returns the zero value for the field. +func (s *Step) GetCreated() int64 { + // return zero value if Step type or Created field is nil + if s == nil || s.Created == nil { + return 0 + } + + return *s.Created +} + +// GetStarted returns the Started field. +// +// When the provided Step type is nil, or the field within +// the type is nil, it returns the zero value for the field. +func (s *Step) GetStarted() int64 { + // return zero value if Step type or Started field is nil + if s == nil || s.Started == nil { + return 0 + } + + return *s.Started +} + +// GetFinished returns the Finished field. +// +// When the provided Step type is nil, or the field within +// the type is nil, it returns the zero value for the field. +func (s *Step) GetFinished() int64 { + // return zero value if Step type or Finished field is nil + if s == nil || s.Finished == nil { + return 0 + } + + return *s.Finished +} + +// GetHost returns the Host field. +// +// When the provided Step type is nil, or the field within +// the type is nil, it returns the zero value for the field. +func (s *Step) GetHost() string { + // return zero value if Step type or Host field is nil + if s == nil || s.Host == nil { + return "" + } + + return *s.Host +} + +// GetRuntime returns the Runtime field. +// +// When the provided Step type is nil, or the field within +// the type is nil, it returns the zero value for the field. +func (s *Step) GetRuntime() string { + // return zero value if Step type or Runtime field is nil + if s == nil || s.Runtime == nil { + return "" + } + + return *s.Runtime +} + +// GetDistribution returns the Runtime field. +// +// When the provided Step type is nil, or the field within +// the type is nil, it returns the zero value for the field. +func (s *Step) GetDistribution() string { + // return zero value if Step type or Distribution field is nil + if s == nil || s.Distribution == nil { + return "" + } + + return *s.Distribution +} + +// GetReportAs returns the ReportAs field. +// +// When the provided Step type is nil, or the field within +// the type is nil, it returns the zero value for the field. +func (s *Step) GetReportAs() string { + // return zero value if Step type or ReportAs field is nil + if s == nil || s.ReportAs == nil { + return "" + } + + return *s.ReportAs +} + +// SetID sets the ID field. +// +// When the provided Step type is nil, it +// will set nothing and immediately return. +func (s *Step) SetID(v int64) { + // return if Step type is nil + if s == nil { + return + } + + s.ID = &v +} + +// SetBuildID sets the BuildID field. +// +// When the provided Step type is nil, it +// will set nothing and immediately return. +func (s *Step) SetBuildID(v int64) { + // return if Step type is nil + if s == nil { + return + } + + s.BuildID = &v +} + +// SetRepoID sets the RepoID field. +// +// When the provided Step type is nil, it +// will set nothing and immediately return. +func (s *Step) SetRepoID(v int64) { + // return if Step type is nil + if s == nil { + return + } + + s.RepoID = &v +} + +// SetNumber sets the Number field. +// +// When the provided Step type is nil, it +// will set nothing and immediately return. +func (s *Step) SetNumber(v int) { + // return if Step type is nil + if s == nil { + return + } + + s.Number = &v +} + +// SetName sets the Name field. +// +// When the provided Step type is nil, it +// will set nothing and immediately return. +func (s *Step) SetName(v string) { + // return if Step type is nil + if s == nil { + return + } + + s.Name = &v +} + +// SetImage sets the Image field. +// +// When the provided Step type is nil, it +// will set nothing and immediately return. +func (s *Step) SetImage(v string) { + // return if Step type is nil + if s == nil { + return + } + + s.Image = &v +} + +// SetStage sets the Stage field. +// +// When the provided Step type is nil, it +// will set nothing and immediately return. +func (s *Step) SetStage(v string) { + // return if Step type is nil + if s == nil { + return + } + + s.Stage = &v +} + +// SetStatus sets the Status field. +// +// When the provided Step type is nil, it +// will set nothing and immediately return. +func (s *Step) SetStatus(v string) { + // return if Step type is nil + if s == nil { + return + } + + s.Status = &v +} + +// SetError sets the Error field. +// +// When the provided Step type is nil, it +// will set nothing and immediately return. +func (s *Step) SetError(v string) { + // return if Step type is nil + if s == nil { + return + } + + s.Error = &v +} + +// SetExitCode sets the ExitCode field. +// +// When the provided Step type is nil, it +// will set nothing and immediately return. +func (s *Step) SetExitCode(v int) { + // return if Step type is nil + if s == nil { + return + } + + s.ExitCode = &v +} + +// SetCreated sets the Created field. +// +// When the provided Step type is nil, it +// will set nothing and immediately return. +func (s *Step) SetCreated(v int64) { + // return if Step type is nil + if s == nil { + return + } + + s.Created = &v +} + +// SetStarted sets the Started field. +// +// When the provided Step type is nil, it +// will set nothing and immediately return. +func (s *Step) SetStarted(v int64) { + // return if Step type is nil + if s == nil { + return + } + + s.Started = &v +} + +// SetFinished sets the Finished field. +// +// When the provided Step type is nil, it +// will set nothing and immediately return. +func (s *Step) SetFinished(v int64) { + // return if Step type is nil + if s == nil { + return + } + + s.Finished = &v +} + +// SetHost sets the Host field. +// +// When the provided Step type is nil, it +// will set nothing and immediately return. +func (s *Step) SetHost(v string) { + // return if Step type is nil + if s == nil { + return + } + + s.Host = &v +} + +// SetRuntime sets the Runtime field. +// +// When the provided Step type is nil, it +// will set nothing and immediately return. +func (s *Step) SetRuntime(v string) { + // return if Step type is nil + if s == nil { + return + } + + s.Runtime = &v +} + +// SetDistribution sets the Distribution field. +// +// When the provided Step type is nil, it +// will set nothing and immediately return. +func (s *Step) SetDistribution(v string) { + // return if Step type is nil + if s == nil { + return + } + + s.Distribution = &v +} + +// SetReportAs sets the ReportAs field. +// +// When the provided Step type is nil, it +// will set nothing and immediately return. +func (s *Step) SetReportAs(v string) { + // return if Step type is nil + if s == nil { + return + } + + s.ReportAs = &v +} + +// String implements the Stringer interface for the Step type. +func (s *Step) String() string { + return fmt.Sprintf(`{ + BuildID: %d, + Created: %d, + Distribution: %s, + Error: %s, + ExitCode: %d, + Finished: %d, + Host: %s, + ID: %d, + Image: %s, + Name: %s, + Number: %d, + RepoID: %d, + ReportAs: %s, + Runtime: %s, + Stage: %s, + Started: %d, + Status: %s, +}`, + s.GetBuildID(), + s.GetCreated(), + s.GetDistribution(), + s.GetError(), + s.GetExitCode(), + s.GetFinished(), + s.GetHost(), + s.GetID(), + s.GetImage(), + s.GetName(), + s.GetNumber(), + s.GetRepoID(), + s.GetReportAs(), + s.GetRuntime(), + s.GetStage(), + s.GetStarted(), + s.GetStatus(), + ) +} + +// StepFromBuildContainer creates a new Step based on a Build and pipeline Container. +func StepFromBuildContainer(build *Build, ctn *pipeline.Container) *Step { + // create new step type we want to return + s := new(Step) + + // default status to Pending + s.SetStatus(constants.StatusPending) + + // copy fields from build + if build != nil { + // set values from the build + s.SetHost(build.GetHost()) + s.SetRuntime(build.GetRuntime()) + s.SetDistribution(build.GetDistribution()) + } + + // copy fields from container + if ctn != nil && ctn.Name != "" { + // set values from the container + s.SetName(ctn.Name) + s.SetNumber(ctn.Number) + s.SetImage(ctn.Image) + s.SetReportAs(ctn.ReportAs) + + // check if the VELA_STEP_STAGE environment variable exists + value, ok := ctn.Environment["VELA_STEP_STAGE"] + if ok { + // set the Stage field to the value from environment variable + s.SetStage(value) + } + } + + return s +} + +// StepFromContainerEnvironment converts the pipeline Container +// to an API Step using the container's Environment. +func StepFromContainerEnvironment(ctn *pipeline.Container) *Step { + // check if container or container environment are nil + if ctn == nil || ctn.Environment == nil { + return nil + } + + // create new step type we want to return + s := new(Step) + + // check if the VELA_STEP_DISTRIBUTION environment variable exists + value, ok := ctn.Environment["VELA_STEP_DISTRIBUTION"] + if ok { + // set the Distribution field to the value from environment variable + s.SetDistribution(value) + } + + // check if the VELA_STEP_HOST environment variable exists + value, ok = ctn.Environment["VELA_STEP_HOST"] + if ok { + // set the Host field to the value from environment variable + s.SetHost(value) + } + + // check if the VELA_STEP_IMAGE environment variable exists + value, ok = ctn.Environment["VELA_STEP_IMAGE"] + if ok { + // set the Image field to the value from environment variable + s.SetImage(value) + } + + // check if the VELA_STEP_NAME environment variable exists + value, ok = ctn.Environment["VELA_STEP_NAME"] + if ok { + // set the Name field to the value from environment variable + s.SetName(value) + } + + // check if the VELA_STEP_REPORT_AS environment variable exists + value, ok = ctn.Environment["VELA_STEP_REPORT_AS"] + if ok { + // set the ReportAs field to the value from environment variable + s.SetReportAs(value) + } + + // check if the VELA_STEP_RUNTIME environment variable exists + value, ok = ctn.Environment["VELA_STEP_RUNTIME"] + if ok { + // set the Runtime field to the value from environment variable + s.SetRuntime(value) + } + + // check if the VELA_STEP_STAGE environment variable exists + value, ok = ctn.Environment["VELA_STEP_STAGE"] + if ok { + // set the Stage field to the value from environment variable + s.SetStage(value) + } + + // check if the VELA_STEP_STATUS environment variable exists + value, ok = ctn.Environment["VELA_STEP_STATUS"] + if ok { + // set the Status field to the value from environment variable + s.SetStatus(value) + } + + // check if the VELA_STEP_CREATED environment variable exists + value, ok = ctn.Environment["VELA_STEP_CREATED"] + if ok { + // parse the environment variable value into an int64 + i, err := strconv.ParseInt(value, 10, 64) + if err == nil { + // set the Created field to the parsed int64 + s.SetCreated(i) + } + } + + // check if the VELA_STEP_EXIT_CODE environment variable exists + value, ok = ctn.Environment["VELA_STEP_EXIT_CODE"] + if ok { + // parse the environment variable value into an int + i, err := strconv.ParseInt(value, 10, 0) + if err == nil { + // set the ExitCode field to the parsed int + s.SetExitCode(int(i)) + } + } + + // check if the VELA_STEP_FINISHED environment variable exists + value, ok = ctn.Environment["VELA_STEP_FINISHED"] + if ok { + // parse the environment variable value into an int64 + i, err := strconv.ParseInt(value, 10, 64) + if err == nil { + // set the Finished field to the parsed int64 + s.SetFinished(i) + } + } + + // check if the VELA_STEP_NUMBER environment variable exists + value, ok = ctn.Environment["VELA_STEP_NUMBER"] + if ok { + // parse the environment variable value into an int + i, err := strconv.ParseInt(value, 10, 0) + if err == nil { + // set the Number field to the parsed int + s.SetNumber(int(i)) + } + } + + // check if the VELA_STEP_STARTED environment variable exists + value, ok = ctn.Environment["VELA_STEP_STARTED"] + if ok { + // parse the environment variable value into an int64 + i, err := strconv.ParseInt(value, 10, 64) + if err == nil { + // set the Started field to the parsed int64 + s.SetStarted(i) + } + } + + return s +} diff --git a/api/types/step_test.go b/api/types/step_test.go new file mode 100644 index 000000000..861f50f23 --- /dev/null +++ b/api/types/step_test.go @@ -0,0 +1,482 @@ +// SPDX-License-Identifier: Apache-2.0 + +package types + +import ( + "fmt" + "reflect" + "testing" + "time" + + "github.com/go-vela/server/compiler/types/pipeline" +) + +func TestTypes_Step_Duration(t *testing.T) { + // setup types + unfinished := testStep() + unfinished.SetFinished(0) + + // setup tests + tests := []struct { + step *Step + want string + }{ + { + step: testStep(), + want: "1s", + }, + { + step: unfinished, + want: time.Since(time.Unix(unfinished.GetStarted(), 0)).Round(time.Second).String(), + }, + { + step: new(Step), + want: "...", + }, + } + + // run tests + for _, test := range tests { + got := test.step.Duration() + + if got != test.want { + t.Errorf("Duration is %v, want %v", got, test.want) + } + } +} + +func TestTypes_Step_Environment(t *testing.T) { + // setup types + want := map[string]string{ + "VELA_STEP_CREATED": "1563474076", + "VELA_STEP_DISTRIBUTION": "linux", + "VELA_STEP_EXIT_CODE": "0", + "VELA_STEP_HOST": "example.company.com", + "VELA_STEP_IMAGE": "target/vela-git:v0.3.0", + "VELA_STEP_NAME": "clone", + "VELA_STEP_NUMBER": "1", + "VELA_STEP_REPORT_AS": "test", + "VELA_STEP_RUNTIME": "docker", + "VELA_STEP_STAGE": "", + "VELA_STEP_STARTED": "1563474078", + "VELA_STEP_STATUS": "running", + } + + // run test + got := testStep().Environment() + + if !reflect.DeepEqual(got, want) { + t.Errorf("Environment is %v, want %v", got, want) + } +} + +func TestTypes_Step_Getters(t *testing.T) { + // setup tests + tests := []struct { + step *Step + want *Step + }{ + { + step: testStep(), + want: testStep(), + }, + { + step: new(Step), + want: new(Step), + }, + } + + // run tests + for _, test := range tests { + if test.step.GetID() != test.want.GetID() { + t.Errorf("GetID is %v, want %v", test.step.GetID(), test.want.GetID()) + } + + if test.step.GetBuildID() != test.want.GetBuildID() { + t.Errorf("GetBuildID is %v, want %v", test.step.GetBuildID(), test.want.GetBuildID()) + } + + if test.step.GetRepoID() != test.want.GetRepoID() { + t.Errorf("GetRepoID is %v, want %v", test.step.GetRepoID(), test.want.GetRepoID()) + } + + if test.step.GetNumber() != test.want.GetNumber() { + t.Errorf("GetNumber is %v, want %v", test.step.GetNumber(), test.want.GetNumber()) + } + + if test.step.GetName() != test.want.GetName() { + t.Errorf("GetName is %v, want %v", test.step.GetName(), test.want.GetName()) + } + + if test.step.GetImage() != test.want.GetImage() { + t.Errorf("GetImage is %v, want %v", test.step.GetImage(), test.want.GetImage()) + } + + if test.step.GetStage() != test.want.GetStage() { + t.Errorf("GetStage is %v, want %v", test.step.GetStage(), test.want.GetStage()) + } + + if test.step.GetStatus() != test.want.GetStatus() { + t.Errorf("GetStatus is %v, want %v", test.step.GetStatus(), test.want.GetStatus()) + } + + if test.step.GetError() != test.want.GetError() { + t.Errorf("GetError is %v, want %v", test.step.GetError(), test.want.GetError()) + } + + if test.step.GetExitCode() != test.want.GetExitCode() { + t.Errorf("GetExitCode is %v, want %v", test.step.GetExitCode(), test.want.GetExitCode()) + } + + if test.step.GetCreated() != test.want.GetCreated() { + t.Errorf("GetCreated is %v, want %v", test.step.GetCreated(), test.want.GetCreated()) + } + + if test.step.GetStarted() != test.want.GetStarted() { + t.Errorf("GetStarted is %v, want %v", test.step.GetStarted(), test.want.GetStarted()) + } + + if test.step.GetFinished() != test.want.GetFinished() { + t.Errorf("GetFinished is %v, want %v", test.step.GetFinished(), test.want.GetFinished()) + } + + if test.step.GetHost() != test.want.GetHost() { + t.Errorf("GetHost is %v, want %v", test.step.GetHost(), test.want.GetHost()) + } + + if test.step.GetRuntime() != test.want.GetRuntime() { + t.Errorf("GetRuntime is %v, want %v", test.step.GetRuntime(), test.want.GetRuntime()) + } + + if test.step.GetDistribution() != test.want.GetDistribution() { + t.Errorf("GetDistribution is %v, want %v", test.step.GetDistribution(), test.want.GetDistribution()) + } + + if test.step.GetReportAs() != test.want.GetReportAs() { + t.Errorf("GetReportAs is %v, want %v", test.step.GetReportAs(), test.want.GetReportAs()) + } + } +} + +func TestTypes_Step_Setters(t *testing.T) { + // setup types + var s *Step + + // setup tests + tests := []struct { + step *Step + want *Step + }{ + { + step: testStep(), + want: testStep(), + }, + { + step: s, + want: new(Step), + }, + } + + // run tests + for _, test := range tests { + test.step.SetID(test.want.GetID()) + test.step.SetBuildID(test.want.GetBuildID()) + test.step.SetRepoID(test.want.GetRepoID()) + test.step.SetNumber(test.want.GetNumber()) + test.step.SetName(test.want.GetName()) + test.step.SetImage(test.want.GetImage()) + test.step.SetStage(test.want.GetStage()) + test.step.SetStatus(test.want.GetStatus()) + test.step.SetError(test.want.GetError()) + test.step.SetExitCode(test.want.GetExitCode()) + test.step.SetCreated(test.want.GetCreated()) + test.step.SetStarted(test.want.GetStarted()) + test.step.SetFinished(test.want.GetFinished()) + test.step.SetHost(test.want.GetHost()) + test.step.SetRuntime(test.want.GetRuntime()) + test.step.SetDistribution(test.want.GetDistribution()) + test.step.SetReportAs(test.want.GetReportAs()) + + if test.step.GetID() != test.want.GetID() { + t.Errorf("SetID is %v, want %v", test.step.GetID(), test.want.GetID()) + } + + if test.step.GetBuildID() != test.want.GetBuildID() { + t.Errorf("SetBuildID is %v, want %v", test.step.GetBuildID(), test.want.GetBuildID()) + } + + if test.step.GetRepoID() != test.want.GetRepoID() { + t.Errorf("SetRepoID is %v, want %v", test.step.GetRepoID(), test.want.GetRepoID()) + } + + if test.step.GetNumber() != test.want.GetNumber() { + t.Errorf("SetNumber is %v, want %v", test.step.GetNumber(), test.want.GetNumber()) + } + + if test.step.GetName() != test.want.GetName() { + t.Errorf("SetName is %v, want %v", test.step.GetName(), test.want.GetName()) + } + + if test.step.GetImage() != test.want.GetImage() { + t.Errorf("SetImage is %v, want %v", test.step.GetImage(), test.want.GetImage()) + } + + if test.step.GetStage() != test.want.GetStage() { + t.Errorf("SetStage is %v, want %v", test.step.GetStage(), test.want.GetStage()) + } + + if test.step.GetStatus() != test.want.GetStatus() { + t.Errorf("SetStatus is %v, want %v", test.step.GetStatus(), test.want.GetStatus()) + } + + if test.step.GetError() != test.want.GetError() { + t.Errorf("SetError is %v, want %v", test.step.GetError(), test.want.GetError()) + } + + if test.step.GetExitCode() != test.want.GetExitCode() { + t.Errorf("SetExitCode is %v, want %v", test.step.GetExitCode(), test.want.GetExitCode()) + } + + if test.step.GetCreated() != test.want.GetCreated() { + t.Errorf("SetCreated is %v, want %v", test.step.GetCreated(), test.want.GetCreated()) + } + + if test.step.GetStarted() != test.want.GetStarted() { + t.Errorf("SetStarted is %v, want %v", test.step.GetStarted(), test.want.GetStarted()) + } + + if test.step.GetFinished() != test.want.GetFinished() { + t.Errorf("SetFinished is %v, want %v", test.step.GetFinished(), test.want.GetFinished()) + } + + if test.step.GetHost() != test.want.GetHost() { + t.Errorf("SetHost is %v, want %v", test.step.GetHost(), test.want.GetHost()) + } + + if test.step.GetRuntime() != test.want.GetRuntime() { + t.Errorf("SetRuntime is %v, want %v", test.step.GetRuntime(), test.want.GetRuntime()) + } + + if test.step.GetDistribution() != test.want.GetDistribution() { + t.Errorf("SetDistribution is %v, want %v", test.step.GetDistribution(), test.want.GetDistribution()) + } + + if test.step.GetReportAs() != test.want.GetReportAs() { + t.Errorf("SetReportAs is %v, want %v", test.step.GetReportAs(), test.want.GetReportAs()) + } + } +} + +func TestTypes_Step_String(t *testing.T) { + // setup types + s := testStep() + + want := fmt.Sprintf(`{ + BuildID: %d, + Created: %d, + Distribution: %s, + Error: %s, + ExitCode: %d, + Finished: %d, + Host: %s, + ID: %d, + Image: %s, + Name: %s, + Number: %d, + RepoID: %d, + ReportAs: %s, + Runtime: %s, + Stage: %s, + Started: %d, + Status: %s, +}`, + s.GetBuildID(), + s.GetCreated(), + s.GetDistribution(), + s.GetError(), + s.GetExitCode(), + s.GetFinished(), + s.GetHost(), + s.GetID(), + s.GetImage(), + s.GetName(), + s.GetNumber(), + s.GetRepoID(), + s.GetReportAs(), + s.GetRuntime(), + s.GetStage(), + s.GetStarted(), + s.GetStatus(), + ) + + // run test + got := s.String() + + if !reflect.DeepEqual(got, want) { + t.Errorf("String is %v, want %v", got, want) + } +} + +func TestTypes_StepFromBuildContainer(t *testing.T) { + // setup types + s := testStep() + s.SetStage("clone") + s.SetStatus("pending") + + // modify fields that aren't set + s.ID = nil + s.BuildID = nil + s.RepoID = nil + s.ExitCode = nil + s.Created = nil + s.Started = nil + s.Finished = nil + + tests := []struct { + name string + container *pipeline.Container + build *Build + want *Step + }{ + { + name: "nil container with nil build", + container: nil, + build: nil, + want: &Step{Status: s.Status}, + }, + { + name: "empty container with nil build", + container: new(pipeline.Container), + build: nil, + want: &Step{Status: s.Status}, + }, + { + name: "nil container with build", + container: nil, + build: testBuild(), + want: &Step{ + Status: s.Status, + Host: s.Host, + Runtime: s.Runtime, + Distribution: s.Distribution, + }, + }, + { + name: "empty container with build", + container: new(pipeline.Container), + build: testBuild(), + want: &Step{ + Status: s.Status, + Host: s.Host, + Runtime: s.Runtime, + Distribution: s.Distribution, + }, + }, + { + name: "container with build", + container: &pipeline.Container{ + Name: s.GetName(), + Number: s.GetNumber(), + Image: s.GetImage(), + ReportAs: s.GetReportAs(), + Environment: map[string]string{ + "VELA_STEP_STAGE": "clone", + }, + }, + build: testBuild(), + want: s, + }, + } + + // run tests + for _, test := range tests { + got := StepFromBuildContainer(test.build, test.container) + + if !reflect.DeepEqual(got, test.want) { + t.Errorf("StepFromBuildContainer for %s is %v, want %v", test.name, got, test.want) + } + } +} + +func TestTypes_StepFromContainerEnvironment(t *testing.T) { + // setup types + s := testStep() + s.SetStage("clone") + + // modify fields that aren't set via environment variables + s.ID = nil + s.BuildID = nil + s.RepoID = nil + + // setup tests + tests := []struct { + name string + container *pipeline.Container + want *Step + }{ + { + name: "nil container", + container: nil, + want: nil, + }, + { + name: "empty container", + container: new(pipeline.Container), + want: nil, + }, + { + name: "container", + container: &pipeline.Container{ + Environment: map[string]string{ + "VELA_STEP_CREATED": "1563474076", + "VELA_STEP_DISTRIBUTION": "linux", + "VELA_STEP_EXIT_CODE": "0", + "VELA_STEP_FINISHED": "1563474079", + "VELA_STEP_HOST": "example.company.com", + "VELA_STEP_IMAGE": "target/vela-git:v0.3.0", + "VELA_STEP_NAME": "clone", + "VELA_STEP_NUMBER": "1", + "VELA_STEP_REPORT_AS": "test", + "VELA_STEP_RUNTIME": "docker", + "VELA_STEP_STAGE": "clone", + "VELA_STEP_STARTED": "1563474078", + "VELA_STEP_STATUS": "running", + }, + }, + want: s, + }, + } + + // run tests + for _, test := range tests { + got := StepFromContainerEnvironment(test.container) + + if !reflect.DeepEqual(got, test.want) { + t.Errorf("StepFromContainerEnvironment for %s is %v, want %v", test.name, got, test.want) + } + } +} + +// testStep is a test helper function to create a Step +// type with all fields set to a fake value. +func testStep() *Step { + s := new(Step) + + s.SetID(1) + s.SetBuildID(1) + s.SetRepoID(1) + s.SetNumber(1) + s.SetName("clone") + s.SetImage("target/vela-git:v0.3.0") + s.SetStatus("running") + s.SetExitCode(0) + s.SetCreated(1563474076) + s.SetStarted(1563474078) + s.SetFinished(1563474079) + s.SetHost("example.company.com") + s.SetRuntime("docker") + s.SetDistribution("linux") + s.SetReportAs("test") + + return s +} diff --git a/api/webhook/post.go b/api/webhook/post.go index 65feda064..d8ca86ab7 100644 --- a/api/webhook/post.go +++ b/api/webhook/post.go @@ -20,12 +20,12 @@ import ( "github.com/go-vela/server/api/build" "github.com/go-vela/server/api/types" "github.com/go-vela/server/compiler" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database" "github.com/go-vela/server/internal" "github.com/go-vela/server/queue" "github.com/go-vela/server/scm" "github.com/go-vela/server/util" - "github.com/go-vela/types/constants" ) var baseErr = "unable to process webhook" diff --git a/api/worker/create.go b/api/worker/create.go index cfac76e54..7b577e3e5 100644 --- a/api/worker/create.go +++ b/api/worker/create.go @@ -12,11 +12,11 @@ import ( "github.com/sirupsen/logrus" "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database" "github.com/go-vela/server/internal/token" "github.com/go-vela/server/router/middleware/claims" "github.com/go-vela/server/util" - "github.com/go-vela/types/constants" "github.com/go-vela/types/library" ) diff --git a/api/worker/refresh.go b/api/worker/refresh.go index 51098efe2..6b8d69fe6 100644 --- a/api/worker/refresh.go +++ b/api/worker/refresh.go @@ -11,12 +11,12 @@ import ( "github.com/gin-gonic/gin" "github.com/sirupsen/logrus" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database" "github.com/go-vela/server/internal/token" "github.com/go-vela/server/router/middleware/claims" "github.com/go-vela/server/router/middleware/worker" "github.com/go-vela/server/util" - "github.com/go-vela/types/constants" "github.com/go-vela/types/library" ) diff --git a/cmd/vela-server/main.go b/cmd/vela-server/main.go index d1207328f..5af8a852c 100644 --- a/cmd/vela-server/main.go +++ b/cmd/vela-server/main.go @@ -13,13 +13,13 @@ import ( _ "github.com/joho/godotenv/autoload" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database" "github.com/go-vela/server/queue" "github.com/go-vela/server/scm" "github.com/go-vela/server/secret" "github.com/go-vela/server/tracing" "github.com/go-vela/server/version" - "github.com/go-vela/types/constants" ) //nolint:funlen // ignore line length diff --git a/cmd/vela-server/schedule.go b/cmd/vela-server/schedule.go index 21729bed9..a06c724a1 100644 --- a/cmd/vela-server/schedule.go +++ b/cmd/vela-server/schedule.go @@ -16,12 +16,12 @@ import ( api "github.com/go-vela/server/api/types" "github.com/go-vela/server/api/types/settings" "github.com/go-vela/server/compiler" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database" "github.com/go-vela/server/internal" "github.com/go-vela/server/queue" "github.com/go-vela/server/scm" "github.com/go-vela/server/util" - "github.com/go-vela/types/constants" ) const ( diff --git a/cmd/vela-server/secret.go b/cmd/vela-server/secret.go index 2ca65615a..474b4d0d9 100644 --- a/cmd/vela-server/secret.go +++ b/cmd/vela-server/secret.go @@ -6,9 +6,9 @@ import ( "github.com/sirupsen/logrus" "github.com/urfave/cli/v2" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database" "github.com/go-vela/server/secret" - "github.com/go-vela/types/constants" ) // helper function to setup the secrets engines from the CLI arguments. diff --git a/cmd/vela-server/validate.go b/cmd/vela-server/validate.go index a8ba5e064..4dd9509df 100644 --- a/cmd/vela-server/validate.go +++ b/cmd/vela-server/validate.go @@ -10,7 +10,7 @@ import ( "github.com/sirupsen/logrus" "github.com/urfave/cli/v2" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) func validate(c *cli.Context) error { diff --git a/compiler/native/clone.go b/compiler/native/clone.go index da1aacdf3..f6f4ffdbc 100644 --- a/compiler/native/clone.go +++ b/compiler/native/clone.go @@ -4,7 +4,7 @@ package native import ( "github.com/go-vela/server/compiler/types/yaml" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) const ( diff --git a/compiler/native/compile.go b/compiler/native/compile.go index 088dbca15..00620e3f2 100644 --- a/compiler/native/compile.go +++ b/compiler/native/compile.go @@ -20,7 +20,7 @@ import ( "github.com/go-vela/server/compiler/types/pipeline" "github.com/go-vela/server/compiler/types/raw" "github.com/go-vela/server/compiler/types/yaml" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) // ModifyRequest contains the payload passed to the modification endpoint. diff --git a/compiler/native/compile_test.go b/compiler/native/compile_test.go index c575a3494..7b3ad7e6d 100644 --- a/compiler/native/compile_test.go +++ b/compiler/native/compile_test.go @@ -23,8 +23,8 @@ import ( "github.com/go-vela/server/compiler/types/pipeline" "github.com/go-vela/server/compiler/types/raw" "github.com/go-vela/server/compiler/types/yaml" + "github.com/go-vela/server/constants" "github.com/go-vela/server/internal" - "github.com/go-vela/types/constants" ) func TestNative_Compile_StagesPipeline(t *testing.T) { diff --git a/compiler/native/environment.go b/compiler/native/environment.go index d9a82ed55..d0c6ab0b8 100644 --- a/compiler/native/environment.go +++ b/compiler/native/environment.go @@ -10,8 +10,8 @@ import ( api "github.com/go-vela/server/api/types" "github.com/go-vela/server/compiler/types/raw" "github.com/go-vela/server/compiler/types/yaml" + "github.com/go-vela/server/constants" "github.com/go-vela/server/internal" - "github.com/go-vela/types/constants" "github.com/go-vela/types/library" ) diff --git a/compiler/native/expand.go b/compiler/native/expand.go index a971b8efd..0420338c0 100644 --- a/compiler/native/expand.go +++ b/compiler/native/expand.go @@ -16,7 +16,7 @@ import ( "github.com/go-vela/server/compiler/types/pipeline" "github.com/go-vela/server/compiler/types/raw" "github.com/go-vela/server/compiler/types/yaml" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) // ExpandStages injects the template for each diff --git a/compiler/native/initialize.go b/compiler/native/initialize.go index 21c9e3b16..bbfdb071c 100644 --- a/compiler/native/initialize.go +++ b/compiler/native/initialize.go @@ -4,7 +4,7 @@ package native import ( "github.com/go-vela/server/compiler/types/yaml" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) const ( diff --git a/compiler/native/parse.go b/compiler/native/parse.go index 47924ac0a..7afeefef3 100644 --- a/compiler/native/parse.go +++ b/compiler/native/parse.go @@ -13,7 +13,7 @@ import ( "github.com/go-vela/server/compiler/template/starlark" typesRaw "github.com/go-vela/server/compiler/types/raw" types "github.com/go-vela/server/compiler/types/yaml" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) // ParseRaw converts an object to a string. diff --git a/compiler/native/parse_test.go b/compiler/native/parse_test.go index 91b13c9cb..fa2635a48 100644 --- a/compiler/native/parse_test.go +++ b/compiler/native/parse_test.go @@ -16,7 +16,7 @@ import ( api "github.com/go-vela/server/api/types" "github.com/go-vela/server/compiler/types/raw" "github.com/go-vela/server/compiler/types/yaml" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) func TestNative_Parse_Metadata_Bytes(t *testing.T) { diff --git a/compiler/native/validate.go b/compiler/native/validate.go index cabe3f602..0c0775019 100644 --- a/compiler/native/validate.go +++ b/compiler/native/validate.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/go-multierror" "github.com/go-vela/server/compiler/types/yaml" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) // Validate verifies the yaml configuration is valid. diff --git a/compiler/types/pipeline/build.go b/compiler/types/pipeline/build.go index 681269d5d..aef5eaea8 100644 --- a/compiler/types/pipeline/build.go +++ b/compiler/types/pipeline/build.go @@ -8,7 +8,7 @@ import ( "unicode/utf8" "github.com/go-vela/server/compiler/types/raw" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) // Build is the pipeline representation of a build for a pipeline. diff --git a/compiler/types/pipeline/build_test.go b/compiler/types/pipeline/build_test.go index a693a89be..a94d05f85 100644 --- a/compiler/types/pipeline/build_test.go +++ b/compiler/types/pipeline/build_test.go @@ -6,7 +6,7 @@ import ( "reflect" "testing" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) func TestPipeline_Build_Purge(t *testing.T) { diff --git a/compiler/types/pipeline/container.go b/compiler/types/pipeline/container.go index 85a96d8b8..246076bd3 100644 --- a/compiler/types/pipeline/container.go +++ b/compiler/types/pipeline/container.go @@ -14,7 +14,7 @@ import ( "github.com/drone/envsubst" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) type ( diff --git a/compiler/types/pipeline/container_test.go b/compiler/types/pipeline/container_test.go index a7ae573c2..8d581f464 100644 --- a/compiler/types/pipeline/container_test.go +++ b/compiler/types/pipeline/container_test.go @@ -6,7 +6,7 @@ import ( "reflect" "testing" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) func TestPipeline_ContainerSlice_Purge(t *testing.T) { diff --git a/compiler/types/pipeline/ruleset.go b/compiler/types/pipeline/ruleset.go index 53126e6c5..a6e5101f6 100644 --- a/compiler/types/pipeline/ruleset.go +++ b/compiler/types/pipeline/ruleset.go @@ -8,7 +8,7 @@ import ( "regexp" "strings" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) type ( diff --git a/compiler/types/pipeline/ruleset_test.go b/compiler/types/pipeline/ruleset_test.go index 26a23823e..d6618d444 100644 --- a/compiler/types/pipeline/ruleset_test.go +++ b/compiler/types/pipeline/ruleset_test.go @@ -5,7 +5,7 @@ package pipeline import ( "testing" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) func TestPipeline_Ruleset_Match(t *testing.T) { diff --git a/compiler/types/pipeline/secret.go b/compiler/types/pipeline/secret.go index bbc5e2602..2f28821a7 100644 --- a/compiler/types/pipeline/secret.go +++ b/compiler/types/pipeline/secret.go @@ -7,7 +7,7 @@ import ( "fmt" "strings" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) type ( diff --git a/compiler/types/pipeline/stage.go b/compiler/types/pipeline/stage.go index 2325f340f..4a7001327 100644 --- a/compiler/types/pipeline/stage.go +++ b/compiler/types/pipeline/stage.go @@ -5,7 +5,7 @@ package pipeline import ( "fmt" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) type ( diff --git a/compiler/types/pipeline/stage_test.go b/compiler/types/pipeline/stage_test.go index 3ae29b10f..fb1071d81 100644 --- a/compiler/types/pipeline/stage_test.go +++ b/compiler/types/pipeline/stage_test.go @@ -6,7 +6,7 @@ import ( "reflect" "testing" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) func TestPipeline_StageSlice_Purge(t *testing.T) { diff --git a/compiler/types/yaml/ruleset.go b/compiler/types/yaml/ruleset.go index f0d4078d8..348f6315b 100644 --- a/compiler/types/yaml/ruleset.go +++ b/compiler/types/yaml/ruleset.go @@ -5,7 +5,7 @@ package yaml import ( "github.com/go-vela/server/compiler/types/pipeline" "github.com/go-vela/server/compiler/types/raw" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) type ( diff --git a/compiler/types/yaml/secret.go b/compiler/types/yaml/secret.go index 887e1a21c..a99f452e8 100644 --- a/compiler/types/yaml/secret.go +++ b/compiler/types/yaml/secret.go @@ -9,7 +9,7 @@ import ( "github.com/go-vela/server/compiler/types/pipeline" "github.com/go-vela/server/compiler/types/raw" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) type ( diff --git a/compiler/types/yaml/service.go b/compiler/types/yaml/service.go index 38fa87a90..f5d5103cc 100644 --- a/compiler/types/yaml/service.go +++ b/compiler/types/yaml/service.go @@ -8,7 +8,7 @@ import ( "github.com/go-vela/server/compiler/types/pipeline" "github.com/go-vela/server/compiler/types/raw" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) type ( diff --git a/compiler/types/yaml/step.go b/compiler/types/yaml/step.go index 42dd7c320..0b579f614 100644 --- a/compiler/types/yaml/step.go +++ b/compiler/types/yaml/step.go @@ -8,7 +8,7 @@ import ( "github.com/go-vela/server/compiler/types/pipeline" "github.com/go-vela/server/compiler/types/raw" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) type ( diff --git a/constants/action.go b/constants/action.go new file mode 100644 index 000000000..67e4e8354 --- /dev/null +++ b/constants/action.go @@ -0,0 +1,42 @@ +// SPDX-License-Identifier: Apache-2.0 + +package constants + +// Build and repo events. +const ( + // ActionOpened defines the action for opening pull requests. + ActionOpened = "opened" + + // ActionCreated defines the action for creating deployments or issue comments. + ActionCreated = "created" + + // ActionEdited defines the action for the editing of pull requests or issue comments. + ActionEdited = "edited" + + // ActionRenamed defines the action for renaming a repository. + ActionRenamed = "renamed" + + // ActionReopened defines the action for re-opening a pull request (or issue). + ActionReopened = "reopened" + + // ActionSynchronize defines the action for the synchronizing of pull requests. + ActionSynchronize = "synchronize" + + // ActionLabeled defines the action for the labeling of pull requests. + ActionLabeled = "labeled" + + // ActionUnlabeled defines the action for the unlabeling of pull requests. + ActionUnlabeled = "unlabeled" + + // ActionTransferred defines the action for transferring repository ownership. + ActionTransferred = "transferred" + + // ActionBranch defines the action for deleting a branch. + ActionBranch = "branch" + + // ActionTag defines the action for deleting a tag. + ActionTag = "tag" + + // ActionRun defines the action for running a schedule. + ActionRun = "run" +) diff --git a/constants/allow_events.go b/constants/allow_events.go new file mode 100644 index 000000000..5df539264 --- /dev/null +++ b/constants/allow_events.go @@ -0,0 +1,27 @@ +// SPDX-License-Identifier: Apache-2.0 + +package constants + +// Allowed repo events. NOTE: these can NOT change order. New events must be added at the end. +const ( + AllowPushBranch = 1 << iota // 00000001 = 1 + AllowPushTag // 00000010 = 2 + AllowPullOpen // 00000100 = 4 + AllowPullEdit // ... + AllowPullSync + _ // AllowPullAssigned - Not Implemented + _ // AllowPullMilestoned - Not Implemented + AllowPullLabel + _ // AllowPullLocked - Not Implemented + _ // AllowPullReady - Not Implemented + AllowPullReopen + _ // AllowPullReviewRequest - Not Implemented + _ // AllowPullClosed - Not Implemented + AllowDeployCreate + AllowCommentCreate + AllowCommentEdit + AllowSchedule + AllowPushDeleteBranch + AllowPushDeleteTag + AllowPullUnlabel +) diff --git a/constants/badge.go b/constants/badge.go new file mode 100644 index 000000000..b92638ac0 --- /dev/null +++ b/constants/badge.go @@ -0,0 +1,98 @@ +// SPDX-License-Identifier: Apache-2.0 + +package constants + +// Constants for build badges. +// +//nolint:godot // due to providing pretty printed svgs +const ( + // Badge for unknown state + // + // + // + // + // + // + // + // + // + // vela + // vela + // unknown + // unknown + // + // + BadgeUnknown = `velavelaunknownunknown` + + // Badge for success state + // + // + // + // + // + // + // + // + // + // vela + // vela + // success + // success + // + // + BadgeSuccess = `velavelasuccesssuccess` + + // Badge for failed state + // + // + // + // + // + // + // + // + // + // vela + // vela + // failed + // failed + // + // + BadgeFailed = `velavelafailedfailed` + + // Badge for error state + // + // + // + // + // + // + // + // + // + // vela + // vela + // error + // error + // + // + BadgeError = `velavelaerrorerror` + + // Badge for running status + // + // + // + // + // + // + // + // + // + // vela + // vela + // running + // running + // + // + BadgeRunning = `velavelarunningrunning` +) diff --git a/constants/compression.go b/constants/compression.go new file mode 100644 index 000000000..6a1d11a6d --- /dev/null +++ b/constants/compression.go @@ -0,0 +1,52 @@ +// SPDX-License-Identifier: Apache-2.0 + +package constants + +// Log Compression Levels. +const ( + // The default compression level for the compress/zlib library + // for log data stored in the database. + CompressionNegOne = -1 + + // Enables no compression for log data stored in the database. + // + // This produces no compression for the log data. + CompressionZero = 0 + + // Enables the best speed for log data stored in the database. + // + // This produces compression for the log data the fastest but + // has a tradeoff of producing the largest amounts of data. + CompressionOne = 1 + + // Second compression level for log data stored in the database. + CompressionTwo = 2 + + // Third compression level for log data stored in the database. + CompressionThree = 3 + + // Fourth compression level for log data stored in the database. + CompressionFour = 4 + + // Enables an even balance of speed and compression for log + // data stored in the database. + // + // This produces compression for the log data with an even + // balance of speed while producing smaller amounts of data. + CompressionFive = 5 + + // Sixth compression level for log data stored in the database. + CompressionSix = 6 + + // Seventh compression level for log data stored in the database. + CompressionSeven = 7 + + // Eighth compression level for log data stored in the database. + CompressionEight = 8 + + // Enables the best compression for log data stored in the database. + // + // This produces compression for the log data the slowest but + // has a tradeoff of producing the smallest amounts of data. + CompressionNine = 9 +) diff --git a/constants/doc.go b/constants/doc.go new file mode 100644 index 000000000..0e748959b --- /dev/null +++ b/constants/doc.go @@ -0,0 +1,8 @@ +// SPDX-License-Identifier: Apache-2.0 + +// Package constants provides the defined constant types for Vela. +// +// Usage: +// +// import "github.com/go-vela/types/constants" +package constants diff --git a/constants/event.go b/constants/event.go new file mode 100644 index 000000000..c2ec26aad --- /dev/null +++ b/constants/event.go @@ -0,0 +1,38 @@ +// SPDX-License-Identifier: Apache-2.0 + +package constants + +// Build and repo events. +const ( + // EventComment defines the event type for comments added to a pull request. + EventComment = "comment" + + // EventDelete defines the event type for build and repo delete events. + EventDelete = "delete" + + // EventDeploy defines the event type for build and repo deployment events. + EventDeploy = "deployment" + + // EventPull defines the event type for build and repo pull_request events. + EventPull = "pull_request" + + // EventPush defines the event type for build and repo push events. + EventPush = "push" + + // EventRepository defines the general event type for repo management. + EventRepository = "repository" + + // EventSchedule defines the event type for build and repo schedule events. + EventSchedule = "schedule" + + // EventTag defines the event type for build and repo tag events. + EventTag = "tag" + + // Alternates for common user inputs that do not match our set constants. + + // EventPullAlternate defines the alternate event type for build and repo pull_request events. + EventPullAlternate = "pull" + + // EventDeployAlternate defines the alternate event type for build and repo deployment events. + EventDeployAlternate = "deploy" +) diff --git a/constants/limit.go b/constants/limit.go index 8b492ec3e..4321c4e79 100644 --- a/constants/limit.go +++ b/constants/limit.go @@ -1,4 +1,5 @@ // SPDX-License-Identifier: Apache-2.0 + package constants // Limits and constraints. diff --git a/constants/matcher.go b/constants/matcher.go new file mode 100644 index 000000000..ef4c79470 --- /dev/null +++ b/constants/matcher.go @@ -0,0 +1,12 @@ +// SPDX-License-Identifier: Apache-2.0 + +package constants + +// Ruleset matchers. +const ( + // MatcherFilepath defines the ruleset type for the filepath matcher. + MatcherFilepath = "filepath" + + // MatcherRegex defines the ruleset type for the regex matcher. + MatcherRegex = "regexp" +) diff --git a/constants/operator.go b/constants/operator.go new file mode 100644 index 000000000..f6a209016 --- /dev/null +++ b/constants/operator.go @@ -0,0 +1,12 @@ +// SPDX-License-Identifier: Apache-2.0 + +package constants + +// Ruleset operators. +const ( + // OperatorAnd defines the ruleset type for the and operator. + OperatorAnd = "and" + + // OperatorOr defines the ruleset type for the or operator. + OperatorOr = "or" +) diff --git a/constants/pipeline.go b/constants/pipeline.go new file mode 100644 index 000000000..f3f49ff38 --- /dev/null +++ b/constants/pipeline.go @@ -0,0 +1,15 @@ +// SPDX-License-Identifier: Apache-2.0 + +package constants + +// Pipeline types. +const ( + // PipelineStages defines the type for a pipeline with stages. + PipelineStage = "stages" + + // PipelineStep defines the type for a pipeline with steps. + PipelineStep = "steps" + + // PipelineTemplate defines the type for a pipeline as a template. + PipelineTemplate = "template" +) diff --git a/constants/pull.go b/constants/pull.go new file mode 100644 index 000000000..131679984 --- /dev/null +++ b/constants/pull.go @@ -0,0 +1,22 @@ +// SPDX-License-Identifier: Apache-2.0 + +package constants + +// Service and step pull policies. +const ( + // PullAlways defines the pull policy type for + // a service or step to always pull an image. + PullAlways = "always" + + // PullNotPresent defines the pull policy type for + // a service or step to only pull an image if it doesn't exist. + PullNotPresent = "not_present" + + // PullOnStart defines the pull policy type for + // a service or step to only pull an image before the container starts. + PullOnStart = "on_start" + + // PullNever defines the pull policy type for + // a service or step to never pull an image. + PullNever = "never" +) diff --git a/constants/queue.go b/constants/queue.go new file mode 100644 index 000000000..fe3b8087e --- /dev/null +++ b/constants/queue.go @@ -0,0 +1,9 @@ +// SPDX-License-Identifier: Apache-2.0 + +package constants + +// Queue types. +const ( + // DefaultRoute defines the default route all workers listen on. + DefaultRoute = "vela" +) diff --git a/constants/table.go b/constants/table.go index 871225fe1..be640a576 100644 --- a/constants/table.go +++ b/constants/table.go @@ -1,4 +1,5 @@ // SPDX-License-Identifier: Apache-2.0 + package constants // Database tables. diff --git a/constants/worker_status.go b/constants/worker_status.go new file mode 100644 index 000000000..70d17111c --- /dev/null +++ b/constants/worker_status.go @@ -0,0 +1,21 @@ +// SPDX-License-Identifier: Apache-2.0 + +package constants + +// Worker statuses. +const ( + // WorkerStatusIdle defines the status for a worker + // where worker RunningBuildIDs.length = 0. + WorkerStatusIdle = "idle" + + // WorkerStatusAvailable defines the status type for a worker in an available state, + // where worker RunningBuildIDs.length > 0 and < worker BuildLimit. + WorkerStatusAvailable = "available" + + // WorkerStatusBusy defines the status type for a worker in an unavailable state, + // where worker BuildLimit == worker RunningBuildIDs.length. + WorkerStatusBusy = "busy" + + // WorkerStatusError defines the status for a worker in an error state. + WorkerStatusError = "error" +) diff --git a/constants/workspace.go b/constants/workspace.go new file mode 100644 index 000000000..9efb1b984 --- /dev/null +++ b/constants/workspace.go @@ -0,0 +1,12 @@ +// SPDX-License-Identifier: Apache-2.0 + +package constants + +// Service and Step workspace paths. +const ( + // WorkspaceDefault defines the default workspace path for a service or a step. + WorkspaceDefault = "/vela/src" + + // WorkspaceMount defines the mount workspace path for a service or a step. + WorkspaceMount = "/vela" +) diff --git a/database/build/build.go b/database/build/build.go index b425731f3..1dc82d36e 100644 --- a/database/build/build.go +++ b/database/build/build.go @@ -9,7 +9,7 @@ import ( "github.com/sirupsen/logrus" "gorm.io/gorm" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) type ( diff --git a/database/build/clean.go b/database/build/clean.go index 81a461469..521e24121 100644 --- a/database/build/clean.go +++ b/database/build/clean.go @@ -9,8 +9,8 @@ import ( "github.com/sirupsen/logrus" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/types" - "github.com/go-vela/types/constants" ) // CleanBuilds updates builds to an error with a provided message with a created timestamp prior to a defined moment. diff --git a/database/build/count.go b/database/build/count.go index 6b26c3f28..3d50bde6e 100644 --- a/database/build/count.go +++ b/database/build/count.go @@ -5,7 +5,7 @@ package build import ( "context" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) // CountBuilds gets the count of all builds from the database. diff --git a/database/build/count_deployment.go b/database/build/count_deployment.go index 631228915..f8ac7a061 100644 --- a/database/build/count_deployment.go +++ b/database/build/count_deployment.go @@ -8,7 +8,7 @@ import ( "github.com/sirupsen/logrus" api "github.com/go-vela/server/api/types" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) // CountBuildsForDeployment gets the count of builds by deployment URL from the database. diff --git a/database/build/count_org.go b/database/build/count_org.go index 5a349c730..e78e22480 100644 --- a/database/build/count_org.go +++ b/database/build/count_org.go @@ -7,7 +7,7 @@ import ( "github.com/sirupsen/logrus" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) // CountBuildsForOrg gets the count of builds by org name from the database. diff --git a/database/build/count_org_test.go b/database/build/count_org_test.go index 546e59678..5454b82dd 100644 --- a/database/build/count_org_test.go +++ b/database/build/count_org_test.go @@ -9,9 +9,9 @@ import ( "github.com/DATA-DOG/go-sqlmock" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/testutils" "github.com/go-vela/server/database/types" - "github.com/go-vela/types/constants" ) func TestBuild_Engine_CountBuildsForOrg(t *testing.T) { diff --git a/database/build/count_repo.go b/database/build/count_repo.go index 138b4d6d4..df59ee2fe 100644 --- a/database/build/count_repo.go +++ b/database/build/count_repo.go @@ -8,7 +8,7 @@ import ( "github.com/sirupsen/logrus" api "github.com/go-vela/server/api/types" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) // CountBuildsForRepo gets the count of builds by repo ID from the database. diff --git a/database/build/count_status.go b/database/build/count_status.go index 8fb401ffb..e3f199d2b 100644 --- a/database/build/count_status.go +++ b/database/build/count_status.go @@ -5,7 +5,7 @@ package build import ( "context" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) // CountBuildsForStatus gets the count of builds by status from the database. diff --git a/database/build/create.go b/database/build/create.go index 7789434cb..d8f122470 100644 --- a/database/build/create.go +++ b/database/build/create.go @@ -9,8 +9,8 @@ import ( "github.com/sirupsen/logrus" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/types" - "github.com/go-vela/types/constants" ) // CreateBuild creates a new build in the database. diff --git a/database/build/delete.go b/database/build/delete.go index f03387a5f..a5ba38ef2 100644 --- a/database/build/delete.go +++ b/database/build/delete.go @@ -8,8 +8,8 @@ import ( "github.com/sirupsen/logrus" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/types" - "github.com/go-vela/types/constants" ) // DeleteBuild deletes an existing build from the database. diff --git a/database/build/get.go b/database/build/get.go index dc7f0e2de..42aa5b8af 100644 --- a/database/build/get.go +++ b/database/build/get.go @@ -6,8 +6,8 @@ import ( "context" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/types" - "github.com/go-vela/types/constants" ) // GetBuild gets a build by ID from the database. diff --git a/database/build/get_repo.go b/database/build/get_repo.go index 1bc9dfb39..66250ef48 100644 --- a/database/build/get_repo.go +++ b/database/build/get_repo.go @@ -8,8 +8,8 @@ import ( "github.com/sirupsen/logrus" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/types" - "github.com/go-vela/types/constants" ) // GetBuildForRepo gets a build by repo ID and number from the database. diff --git a/database/build/get_repo_test.go b/database/build/get_repo_test.go index 327b2f14d..2be48a249 100644 --- a/database/build/get_repo_test.go +++ b/database/build/get_repo_test.go @@ -10,8 +10,8 @@ import ( "github.com/google/go-cmp/cmp" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/testutils" - "github.com/go-vela/types/constants" ) func TestBuild_Engine_GetBuildForRepo(t *testing.T) { diff --git a/database/build/get_test.go b/database/build/get_test.go index e4a26d852..3dc2e95e8 100644 --- a/database/build/get_test.go +++ b/database/build/get_test.go @@ -10,9 +10,9 @@ import ( "github.com/DATA-DOG/go-sqlmock" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/testutils" "github.com/go-vela/server/database/types" - "github.com/go-vela/types/constants" ) func TestBuild_Engine_GetBuild(t *testing.T) { diff --git a/database/build/last_repo.go b/database/build/last_repo.go index 517579240..c001bbf0d 100644 --- a/database/build/last_repo.go +++ b/database/build/last_repo.go @@ -10,8 +10,8 @@ import ( "gorm.io/gorm" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/types" - "github.com/go-vela/types/constants" ) // LastBuildForRepo gets the last build by repo ID and branch from the database. diff --git a/database/build/last_repo_test.go b/database/build/last_repo_test.go index 7b518afee..55b74e5b6 100644 --- a/database/build/last_repo_test.go +++ b/database/build/last_repo_test.go @@ -10,8 +10,8 @@ import ( "github.com/DATA-DOG/go-sqlmock" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/testutils" - "github.com/go-vela/types/constants" ) func TestBuild_Engine_LastBuildForRepo(t *testing.T) { diff --git a/database/build/list.go b/database/build/list.go index 4074618c7..1a3e22a5b 100644 --- a/database/build/list.go +++ b/database/build/list.go @@ -6,8 +6,8 @@ import ( "context" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/types" - "github.com/go-vela/types/constants" ) // ListBuilds gets a list of all builds from the database. diff --git a/database/build/list_dashboard.go b/database/build/list_dashboard.go index 7ba0c379a..65fc8549e 100644 --- a/database/build/list_dashboard.go +++ b/database/build/list_dashboard.go @@ -8,8 +8,8 @@ import ( "github.com/sirupsen/logrus" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/types" - "github.com/go-vela/types/constants" ) // ListBuildsForDashboardRepo gets a list of builds by repo ID from the database. diff --git a/database/build/list_org.go b/database/build/list_org.go index d1c33a7a7..5f8259753 100644 --- a/database/build/list_org.go +++ b/database/build/list_org.go @@ -8,8 +8,8 @@ import ( "github.com/sirupsen/logrus" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/types" - "github.com/go-vela/types/constants" ) // ListBuildsForOrg gets a list of builds by org name from the database. diff --git a/database/build/list_org_test.go b/database/build/list_org_test.go index 4d25d6062..965955891 100644 --- a/database/build/list_org_test.go +++ b/database/build/list_org_test.go @@ -10,9 +10,9 @@ import ( "github.com/google/go-cmp/cmp" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/testutils" "github.com/go-vela/server/database/types" - "github.com/go-vela/types/constants" ) func TestBuild_Engine_ListBuildsForOrg(t *testing.T) { diff --git a/database/build/list_pending_running.go b/database/build/list_pending_running.go index 6a08dcbac..9e7d1e244 100644 --- a/database/build/list_pending_running.go +++ b/database/build/list_pending_running.go @@ -6,8 +6,8 @@ import ( "context" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/types" - "github.com/go-vela/types/constants" ) // ListPendingAndRunningBuilds gets a list of all pending and running builds in the provided timeframe from the database. diff --git a/database/build/list_pending_running_repo.go b/database/build/list_pending_running_repo.go index c475ccc1a..36a41d69a 100644 --- a/database/build/list_pending_running_repo.go +++ b/database/build/list_pending_running_repo.go @@ -6,8 +6,8 @@ import ( "context" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/types" - "github.com/go-vela/types/constants" ) // ListPendingAndRunningBuilds gets a list of all pending and running builds in the provided timeframe from the database. diff --git a/database/build/list_pending_running_test.go b/database/build/list_pending_running_test.go index c164827d8..840b30622 100644 --- a/database/build/list_pending_running_test.go +++ b/database/build/list_pending_running_test.go @@ -10,9 +10,9 @@ import ( "github.com/DATA-DOG/go-sqlmock" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/testutils" "github.com/go-vela/server/database/types" - "github.com/go-vela/types/constants" ) func TestBuild_Engine_ListPendingAndRunningBuilds(t *testing.T) { diff --git a/database/build/list_repo.go b/database/build/list_repo.go index 772a7ee6b..470b448d3 100644 --- a/database/build/list_repo.go +++ b/database/build/list_repo.go @@ -8,8 +8,8 @@ import ( "github.com/sirupsen/logrus" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/types" - "github.com/go-vela/types/constants" ) // ListBuildsForRepo gets a list of builds by repo ID from the database. diff --git a/database/build/list_repo_test.go b/database/build/list_repo_test.go index 0933d0ea3..8071e3a67 100644 --- a/database/build/list_repo_test.go +++ b/database/build/list_repo_test.go @@ -11,8 +11,8 @@ import ( "github.com/DATA-DOG/go-sqlmock" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/testutils" - "github.com/go-vela/types/constants" ) func TestBuild_Engine_ListBuildsForRepo(t *testing.T) { diff --git a/database/build/list_test.go b/database/build/list_test.go index 15688d252..e440a162c 100644 --- a/database/build/list_test.go +++ b/database/build/list_test.go @@ -10,9 +10,9 @@ import ( "github.com/DATA-DOG/go-sqlmock" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/testutils" "github.com/go-vela/server/database/types" - "github.com/go-vela/types/constants" ) func TestBuild_Engine_ListBuilds(t *testing.T) { diff --git a/database/build/table.go b/database/build/table.go index 2a7af528c..756a621cb 100644 --- a/database/build/table.go +++ b/database/build/table.go @@ -5,7 +5,7 @@ package build import ( "context" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) const ( diff --git a/database/build/update.go b/database/build/update.go index 07b029093..2d838d9db 100644 --- a/database/build/update.go +++ b/database/build/update.go @@ -9,8 +9,8 @@ import ( "github.com/sirupsen/logrus" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/types" - "github.com/go-vela/types/constants" ) // UpdateBuild updates an existing build in the database. diff --git a/database/dashboard/table.go b/database/dashboard/table.go index cef302382..b10917a27 100644 --- a/database/dashboard/table.go +++ b/database/dashboard/table.go @@ -5,7 +5,7 @@ package dashboard import ( "context" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) const ( diff --git a/database/database.go b/database/database.go index 6f21ec40a..3976edad1 100644 --- a/database/database.go +++ b/database/database.go @@ -13,6 +13,7 @@ import ( "gorm.io/driver/sqlite" "gorm.io/gorm" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/build" "github.com/go-vela/server/database/dashboard" "github.com/go-vela/server/database/deployment" @@ -30,7 +31,6 @@ import ( "github.com/go-vela/server/database/user" "github.com/go-vela/server/database/worker" "github.com/go-vela/server/tracing" - "github.com/go-vela/types/constants" ) type ( diff --git a/database/deployment/count.go b/database/deployment/count.go index f1c9e5b14..124990d0e 100644 --- a/database/deployment/count.go +++ b/database/deployment/count.go @@ -5,7 +5,7 @@ package deployment import ( "context" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) // CountDeployments gets the count of all deployments from the database. diff --git a/database/deployment/count_repo.go b/database/deployment/count_repo.go index 8a2afd6fc..1746b876c 100644 --- a/database/deployment/count_repo.go +++ b/database/deployment/count_repo.go @@ -8,7 +8,7 @@ import ( "github.com/sirupsen/logrus" api "github.com/go-vela/server/api/types" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) // CountDeploymentsForRepo gets the count of deployments by repo ID from the database. diff --git a/database/deployment/create.go b/database/deployment/create.go index b3c85a188..d58feda5f 100644 --- a/database/deployment/create.go +++ b/database/deployment/create.go @@ -8,8 +8,8 @@ import ( "github.com/sirupsen/logrus" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/types" - "github.com/go-vela/types/constants" ) // CreateDeployment creates a new deployment in the database. diff --git a/database/deployment/delete.go b/database/deployment/delete.go index b0f76c7fc..d668f5ef0 100644 --- a/database/deployment/delete.go +++ b/database/deployment/delete.go @@ -8,8 +8,8 @@ import ( "github.com/sirupsen/logrus" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/types" - "github.com/go-vela/types/constants" ) // DeleteDeployment deletes an existing deployment from the database. diff --git a/database/deployment/deployment.go b/database/deployment/deployment.go index e1fbefad0..ce890809e 100644 --- a/database/deployment/deployment.go +++ b/database/deployment/deployment.go @@ -9,7 +9,7 @@ import ( "github.com/sirupsen/logrus" "gorm.io/gorm" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) type ( diff --git a/database/deployment/get.go b/database/deployment/get.go index aef68bc7f..7e51a4ef5 100644 --- a/database/deployment/get.go +++ b/database/deployment/get.go @@ -7,8 +7,8 @@ import ( "strconv" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/types" - "github.com/go-vela/types/constants" ) // GetDeployment gets a deployment by ID from the database. diff --git a/database/deployment/get_repo.go b/database/deployment/get_repo.go index f9894789a..43615e798 100644 --- a/database/deployment/get_repo.go +++ b/database/deployment/get_repo.go @@ -9,8 +9,8 @@ import ( "github.com/sirupsen/logrus" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/types" - "github.com/go-vela/types/constants" ) // GetDeploymentForRepo gets a deployment by repo ID and number from the database. diff --git a/database/deployment/list.go b/database/deployment/list.go index b5101eb06..6c2b7f0a8 100644 --- a/database/deployment/list.go +++ b/database/deployment/list.go @@ -7,8 +7,8 @@ import ( "strconv" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/types" - "github.com/go-vela/types/constants" ) // ListDeployments gets a list of all deployments from the database. diff --git a/database/deployment/list_repo.go b/database/deployment/list_repo.go index 08419397a..b4d11c3a9 100644 --- a/database/deployment/list_repo.go +++ b/database/deployment/list_repo.go @@ -9,8 +9,8 @@ import ( "github.com/sirupsen/logrus" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/types" - "github.com/go-vela/types/constants" ) // ListDeploymentsForRepo gets a list of deployments by repo ID from the database. diff --git a/database/deployment/table.go b/database/deployment/table.go index 9baef0284..13ad4248b 100644 --- a/database/deployment/table.go +++ b/database/deployment/table.go @@ -5,7 +5,7 @@ package deployment import ( "context" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) const ( diff --git a/database/deployment/update.go b/database/deployment/update.go index 0cb7c8b51..7179ce87d 100644 --- a/database/deployment/update.go +++ b/database/deployment/update.go @@ -8,8 +8,8 @@ import ( "github.com/sirupsen/logrus" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/types" - "github.com/go-vela/types/constants" ) // UpdateDeployment updates an existing deployment in the database. diff --git a/database/executable/clean.go b/database/executable/clean.go index ba4c06172..4a770f3dd 100644 --- a/database/executable/clean.go +++ b/database/executable/clean.go @@ -7,7 +7,7 @@ import ( "github.com/sirupsen/logrus" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) const CleanExecutablesPostgres = ` diff --git a/database/executable/clean_test.go b/database/executable/clean_test.go index 92c8be8e8..56d837c2e 100644 --- a/database/executable/clean_test.go +++ b/database/executable/clean_test.go @@ -9,7 +9,7 @@ import ( "github.com/DATA-DOG/go-sqlmock" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" "github.com/go-vela/types/database" "github.com/go-vela/types/library" ) diff --git a/database/executable/create.go b/database/executable/create.go index e231f01fb..5246eccb1 100644 --- a/database/executable/create.go +++ b/database/executable/create.go @@ -8,7 +8,7 @@ import ( "github.com/sirupsen/logrus" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" "github.com/go-vela/types/database" "github.com/go-vela/types/library" ) diff --git a/database/executable/executable.go b/database/executable/executable.go index 8ac0475ef..cb32b2a52 100644 --- a/database/executable/executable.go +++ b/database/executable/executable.go @@ -9,7 +9,7 @@ import ( "github.com/sirupsen/logrus" "gorm.io/gorm" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) type ( diff --git a/database/executable/executable_test.go b/database/executable/executable_test.go index 2869001a8..141323ee8 100644 --- a/database/executable/executable_test.go +++ b/database/executable/executable_test.go @@ -13,7 +13,7 @@ import ( "gorm.io/driver/sqlite" "gorm.io/gorm" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" "github.com/go-vela/types/library" ) diff --git a/database/executable/pop.go b/database/executable/pop.go index 9625ad984..e3a2445e8 100644 --- a/database/executable/pop.go +++ b/database/executable/pop.go @@ -7,7 +7,7 @@ import ( "gorm.io/gorm/clause" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" "github.com/go-vela/types/database" "github.com/go-vela/types/library" ) diff --git a/database/executable/table.go b/database/executable/table.go index 0a7a3c147..bbe8e615b 100644 --- a/database/executable/table.go +++ b/database/executable/table.go @@ -5,7 +5,7 @@ package executable import ( "context" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) const ( diff --git a/database/flags.go b/database/flags.go index 129143655..035b016aa 100644 --- a/database/flags.go +++ b/database/flags.go @@ -7,7 +7,7 @@ import ( "github.com/urfave/cli/v2" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) // Flags represents all supported command line interface (CLI) flags for the database. diff --git a/database/hook/last_repo.go b/database/hook/last_repo.go index 0073d8a8b..8d17aef0b 100644 --- a/database/hook/last_repo.go +++ b/database/hook/last_repo.go @@ -10,8 +10,8 @@ import ( "gorm.io/gorm" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/types" - "github.com/go-vela/types/constants" ) // LastHookForRepo gets the last hook by repo ID from the database. diff --git a/database/integration_test.go b/database/integration_test.go index 85f5a2318..2f5646aa2 100644 --- a/database/integration_test.go +++ b/database/integration_test.go @@ -17,6 +17,7 @@ import ( api "github.com/go-vela/server/api/types" "github.com/go-vela/server/api/types/settings" "github.com/go-vela/server/compiler/types/raw" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/build" "github.com/go-vela/server/database/dashboard" "github.com/go-vela/server/database/deployment" @@ -35,7 +36,6 @@ import ( "github.com/go-vela/server/database/user" "github.com/go-vela/server/database/worker" "github.com/go-vela/server/tracing" - "github.com/go-vela/types/constants" "github.com/go-vela/types/library" ) @@ -52,8 +52,8 @@ type Resources struct { Repos []*api.Repo Schedules []*api.Schedule Secrets []*api.Secret - Services []*library.Service - Steps []*library.Step + Services []*api.Service + Steps []*api.Step Users []*api.User Workers []*api.Worker Platform []*settings.Platform @@ -1935,8 +1935,8 @@ func testServices(t *testing.T, db Interface, resources *Resources) { if err != nil { t.Errorf("unable to list services for build %d: %v", resources.Builds[0].GetID(), err) } - if !cmp.Equal(list, []*library.Service{resources.Services[1], resources.Services[0]}) { - t.Errorf("ListServicesForBuild() is %v, want %v", list, []*library.Service{resources.Services[1], resources.Services[0]}) + if !cmp.Equal(list, []*api.Service{resources.Services[1], resources.Services[0]}) { + t.Errorf("ListServicesForBuild() is %v, want %v", list, []*api.Service{resources.Services[1], resources.Services[0]}) } if int(count) != len(resources.Services) { t.Errorf("ListServicesForBuild() is %v, want %v", count, len(resources.Services)) @@ -2090,8 +2090,8 @@ func testSteps(t *testing.T, db Interface, resources *Resources) { if err != nil { t.Errorf("unable to list steps for build %d: %v", resources.Builds[0].GetID(), err) } - if !cmp.Equal(list, []*library.Step{resources.Steps[1], resources.Steps[0]}) { - t.Errorf("ListStepsForBuild() is %v, want %v", list, []*library.Step{resources.Steps[1], resources.Steps[0]}) + if !cmp.Equal(list, []*api.Step{resources.Steps[1], resources.Steps[0]}) { + t.Errorf("ListStepsForBuild() is %v, want %v", list, []*api.Step{resources.Steps[1], resources.Steps[0]}) } if int(count) != len(resources.Steps) { t.Errorf("ListStepsForBuild() is %v, want %v", count, len(resources.Steps)) @@ -2877,7 +2877,7 @@ func newResources() *Resources { secretShared.SetUpdatedAt(time.Now().Add(time.Hour * 1).UTC().Unix()) secretShared.SetUpdatedBy("octokitty") - serviceOne := new(library.Service) + serviceOne := new(api.Service) serviceOne.SetID(1) serviceOne.SetBuildID(1) serviceOne.SetRepoID(1) @@ -2894,7 +2894,7 @@ func newResources() *Resources { serviceOne.SetRuntime("docker") serviceOne.SetDistribution("linux") - serviceTwo := new(library.Service) + serviceTwo := new(api.Service) serviceTwo.SetID(2) serviceTwo.SetBuildID(1) serviceTwo.SetRepoID(1) @@ -2911,7 +2911,7 @@ func newResources() *Resources { serviceTwo.SetRuntime("docker") serviceTwo.SetDistribution("linux") - stepOne := new(library.Step) + stepOne := new(api.Step) stepOne.SetID(1) stepOne.SetBuildID(1) stepOne.SetRepoID(1) @@ -2930,7 +2930,7 @@ func newResources() *Resources { stepOne.SetDistribution("linux") stepOne.SetReportAs("") - stepTwo := new(library.Step) + stepTwo := new(api.Step) stepTwo.SetID(2) stepTwo.SetBuildID(1) stepTwo.SetRepoID(1) @@ -2995,8 +2995,8 @@ func newResources() *Resources { Repos: []*api.Repo{repoOne, repoTwo}, Schedules: []*api.Schedule{scheduleOne, scheduleTwo}, Secrets: []*api.Secret{secretOrg, secretRepo, secretShared}, - Services: []*library.Service{serviceOne, serviceTwo}, - Steps: []*library.Step{stepOne, stepTwo}, + Services: []*api.Service{serviceOne, serviceTwo}, + Steps: []*api.Step{stepOne, stepTwo}, Users: []*api.User{userOne, userTwo}, Workers: []*api.Worker{workerOne, workerTwo}, } diff --git a/database/jwk/table.go b/database/jwk/table.go index ee5895fcb..81f8ccfc2 100644 --- a/database/jwk/table.go +++ b/database/jwk/table.go @@ -5,7 +5,7 @@ package jwk import ( "context" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) const ( diff --git a/database/log/count.go b/database/log/count.go index d31c37f62..dd30fe00f 100644 --- a/database/log/count.go +++ b/database/log/count.go @@ -5,7 +5,7 @@ package log import ( "context" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) // CountLogs gets the count of all logs from the database. diff --git a/database/log/count_build.go b/database/log/count_build.go index 36cd2984f..ff6eb84fb 100644 --- a/database/log/count_build.go +++ b/database/log/count_build.go @@ -6,7 +6,7 @@ import ( "context" api "github.com/go-vela/server/api/types" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) // CountLogsForBuild gets the count of logs by build ID from the database. diff --git a/database/log/create.go b/database/log/create.go index 4d0ee3428..385bca9fd 100644 --- a/database/log/create.go +++ b/database/log/create.go @@ -7,7 +7,7 @@ import ( "context" "fmt" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" "github.com/go-vela/types/database" "github.com/go-vela/types/library" ) diff --git a/database/log/delete.go b/database/log/delete.go index 394321159..1ee187bbc 100644 --- a/database/log/delete.go +++ b/database/log/delete.go @@ -5,7 +5,7 @@ package log import ( "context" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" "github.com/go-vela/types/database" "github.com/go-vela/types/library" ) diff --git a/database/log/get.go b/database/log/get.go index cf66dbfd7..19f78f0dc 100644 --- a/database/log/get.go +++ b/database/log/get.go @@ -5,7 +5,7 @@ package log import ( "context" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" "github.com/go-vela/types/database" "github.com/go-vela/types/library" ) diff --git a/database/log/get_service.go b/database/log/get_service.go index ad4156a8d..2fd0f6c40 100644 --- a/database/log/get_service.go +++ b/database/log/get_service.go @@ -6,13 +6,14 @@ package log import ( "context" - "github.com/go-vela/types/constants" + api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/types/database" "github.com/go-vela/types/library" ) // GetLogForService gets a log by service ID from the database. -func (e *engine) GetLogForService(ctx context.Context, s *library.Service) (*library.Log, error) { +func (e *engine) GetLogForService(ctx context.Context, s *api.Service) (*library.Log, error) { e.logger.Tracef("getting log for service %d for build %d", s.GetID(), s.GetBuildID()) // variable to store query results diff --git a/database/log/get_step.go b/database/log/get_step.go index 6d0084712..526023b51 100644 --- a/database/log/get_step.go +++ b/database/log/get_step.go @@ -6,13 +6,14 @@ package log import ( "context" - "github.com/go-vela/types/constants" + api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/types/database" "github.com/go-vela/types/library" ) // GetLogForStep gets a log by step ID from the database. -func (e *engine) GetLogForStep(ctx context.Context, s *library.Step) (*library.Log, error) { +func (e *engine) GetLogForStep(ctx context.Context, s *api.Step) (*library.Log, error) { e.logger.Tracef("getting log for step %d for build %d", s.GetID(), s.GetBuildID()) // variable to store query results diff --git a/database/log/interface.go b/database/log/interface.go index 97ace05c6..4cd0bdabf 100644 --- a/database/log/interface.go +++ b/database/log/interface.go @@ -38,9 +38,9 @@ type LogInterface interface { // GetLog defines a function that gets a log by ID. GetLog(context.Context, int64) (*library.Log, error) // GetLogForService defines a function that gets a log by service ID. - GetLogForService(context.Context, *library.Service) (*library.Log, error) + GetLogForService(context.Context, *api.Service) (*library.Log, error) // GetLogForStep defines a function that gets a log by step ID. - GetLogForStep(context.Context, *library.Step) (*library.Log, error) + GetLogForStep(context.Context, *api.Step) (*library.Log, error) // ListLogs defines a function that gets a list of all logs. ListLogs(context.Context) ([]*library.Log, error) // ListLogsForBuild defines a function that gets a list of logs by build ID. diff --git a/database/log/list.go b/database/log/list.go index ed6ecdcb7..34a57db4a 100644 --- a/database/log/list.go +++ b/database/log/list.go @@ -5,7 +5,7 @@ package log import ( "context" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" "github.com/go-vela/types/database" "github.com/go-vela/types/library" ) diff --git a/database/log/list_build.go b/database/log/list_build.go index f27798b78..c5013d17c 100644 --- a/database/log/list_build.go +++ b/database/log/list_build.go @@ -6,7 +6,7 @@ import ( "context" api "github.com/go-vela/server/api/types" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" "github.com/go-vela/types/database" "github.com/go-vela/types/library" ) diff --git a/database/log/log.go b/database/log/log.go index e95dc6d04..f990eff40 100644 --- a/database/log/log.go +++ b/database/log/log.go @@ -9,7 +9,7 @@ import ( "github.com/sirupsen/logrus" "gorm.io/gorm" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) type ( diff --git a/database/log/table.go b/database/log/table.go index fbf74cd28..6ac0e53f9 100644 --- a/database/log/table.go +++ b/database/log/table.go @@ -5,7 +5,7 @@ package log import ( "context" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) const ( diff --git a/database/log/update.go b/database/log/update.go index ae9819e4a..13a65d4ee 100644 --- a/database/log/update.go +++ b/database/log/update.go @@ -7,7 +7,7 @@ import ( "context" "fmt" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" "github.com/go-vela/types/database" "github.com/go-vela/types/library" ) diff --git a/database/pipeline/count.go b/database/pipeline/count.go index 818982b52..b7f3d83f7 100644 --- a/database/pipeline/count.go +++ b/database/pipeline/count.go @@ -5,7 +5,7 @@ package pipeline import ( "context" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) // CountPipelines gets the count of all pipelines from the database. diff --git a/database/pipeline/count_repo.go b/database/pipeline/count_repo.go index 147ae552b..3c174e340 100644 --- a/database/pipeline/count_repo.go +++ b/database/pipeline/count_repo.go @@ -8,7 +8,7 @@ import ( "github.com/sirupsen/logrus" api "github.com/go-vela/server/api/types" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) // CountPipelinesForRepo gets the count of pipelines by repo ID from the database. diff --git a/database/pipeline/create.go b/database/pipeline/create.go index d6ce01cd0..032742533 100644 --- a/database/pipeline/create.go +++ b/database/pipeline/create.go @@ -8,8 +8,8 @@ import ( "github.com/sirupsen/logrus" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/types" - "github.com/go-vela/types/constants" ) // CreatePipeline creates a new pipeline in the database. diff --git a/database/pipeline/delete.go b/database/pipeline/delete.go index ecd87611e..fb9ad8407 100644 --- a/database/pipeline/delete.go +++ b/database/pipeline/delete.go @@ -8,8 +8,8 @@ import ( "github.com/sirupsen/logrus" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/types" - "github.com/go-vela/types/constants" ) // DeletePipeline deletes an existing pipeline from the database. diff --git a/database/pipeline/get.go b/database/pipeline/get.go index 0721ba36d..e7d570ece 100644 --- a/database/pipeline/get.go +++ b/database/pipeline/get.go @@ -6,8 +6,8 @@ import ( "context" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/types" - "github.com/go-vela/types/constants" ) // GetPipeline gets a pipeline by ID from the database. diff --git a/database/pipeline/get_repo.go b/database/pipeline/get_repo.go index b84c320f3..5da0f9281 100644 --- a/database/pipeline/get_repo.go +++ b/database/pipeline/get_repo.go @@ -8,8 +8,8 @@ import ( "github.com/sirupsen/logrus" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/types" - "github.com/go-vela/types/constants" ) // GetPipelineForRepo gets a pipeline by number and repo ID from the database. diff --git a/database/pipeline/list.go b/database/pipeline/list.go index e288965bd..85e39a3cd 100644 --- a/database/pipeline/list.go +++ b/database/pipeline/list.go @@ -6,8 +6,8 @@ import ( "context" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/types" - "github.com/go-vela/types/constants" ) // ListPipelines gets a list of all pipelines from the database. diff --git a/database/pipeline/list_repo.go b/database/pipeline/list_repo.go index 5476cd925..cc179febe 100644 --- a/database/pipeline/list_repo.go +++ b/database/pipeline/list_repo.go @@ -8,8 +8,8 @@ import ( "github.com/sirupsen/logrus" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/types" - "github.com/go-vela/types/constants" ) // ListPipelinesForRepo gets a list of pipelines by repo ID from the database. diff --git a/database/pipeline/pipeline.go b/database/pipeline/pipeline.go index 433f9d2fc..18beb9cf8 100644 --- a/database/pipeline/pipeline.go +++ b/database/pipeline/pipeline.go @@ -9,7 +9,7 @@ import ( "github.com/sirupsen/logrus" "gorm.io/gorm" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) type ( diff --git a/database/pipeline/table.go b/database/pipeline/table.go index 919b1b652..4bd874c83 100644 --- a/database/pipeline/table.go +++ b/database/pipeline/table.go @@ -5,7 +5,7 @@ package pipeline import ( "context" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) const ( diff --git a/database/pipeline/update.go b/database/pipeline/update.go index 23251f1a1..66eecaefa 100644 --- a/database/pipeline/update.go +++ b/database/pipeline/update.go @@ -8,8 +8,8 @@ import ( "github.com/sirupsen/logrus" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/types" - "github.com/go-vela/types/constants" ) // UpdatePipeline updates an existing pipeline in the database. diff --git a/database/repo/count.go b/database/repo/count.go index 6db509b06..585b2417b 100644 --- a/database/repo/count.go +++ b/database/repo/count.go @@ -5,7 +5,7 @@ package repo import ( "context" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) // CountRepos gets the count of all repos from the database. diff --git a/database/repo/count_org.go b/database/repo/count_org.go index 915a0d9a7..cb5c53868 100644 --- a/database/repo/count_org.go +++ b/database/repo/count_org.go @@ -7,7 +7,7 @@ import ( "github.com/sirupsen/logrus" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) // CountReposForOrg gets the count of repos by org name from the database. diff --git a/database/repo/count_user.go b/database/repo/count_user.go index 57f3ecb3c..7fd8c212d 100644 --- a/database/repo/count_user.go +++ b/database/repo/count_user.go @@ -8,7 +8,7 @@ import ( "github.com/sirupsen/logrus" api "github.com/go-vela/server/api/types" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) // CountReposForUser gets the count of repos by user ID from the database. diff --git a/database/repo/create.go b/database/repo/create.go index 7500b4101..618ff3a2c 100644 --- a/database/repo/create.go +++ b/database/repo/create.go @@ -10,8 +10,8 @@ import ( "github.com/sirupsen/logrus" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/types" - "github.com/go-vela/types/constants" ) // CreateRepo creates a new repo in the database. diff --git a/database/repo/delete.go b/database/repo/delete.go index cfd6dffa3..ad0ac6299 100644 --- a/database/repo/delete.go +++ b/database/repo/delete.go @@ -8,8 +8,8 @@ import ( "github.com/sirupsen/logrus" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/types" - "github.com/go-vela/types/constants" ) // DeleteRepo deletes an existing repo from the database. diff --git a/database/repo/get.go b/database/repo/get.go index 15a301290..f1b80f30b 100644 --- a/database/repo/get.go +++ b/database/repo/get.go @@ -6,8 +6,8 @@ import ( "context" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/types" - "github.com/go-vela/types/constants" ) // GetRepo gets a repo by ID from the database. diff --git a/database/repo/get_org.go b/database/repo/get_org.go index 38b32d4ca..368832eb5 100644 --- a/database/repo/get_org.go +++ b/database/repo/get_org.go @@ -8,8 +8,8 @@ import ( "github.com/sirupsen/logrus" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/types" - "github.com/go-vela/types/constants" ) // GetRepoForOrg gets a repo by org and repo name from the database. diff --git a/database/repo/get_org_test.go b/database/repo/get_org_test.go index 1570398c0..ed912ca1f 100644 --- a/database/repo/get_org_test.go +++ b/database/repo/get_org_test.go @@ -10,9 +10,9 @@ import ( "github.com/google/go-cmp/cmp" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/testutils" "github.com/go-vela/server/database/types" - "github.com/go-vela/types/constants" ) func TestRepo_Engine_GetRepoForOrg(t *testing.T) { diff --git a/database/repo/get_test.go b/database/repo/get_test.go index bab82c6f3..720f9bf07 100644 --- a/database/repo/get_test.go +++ b/database/repo/get_test.go @@ -10,9 +10,9 @@ import ( "github.com/DATA-DOG/go-sqlmock" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/testutils" "github.com/go-vela/server/database/types" - "github.com/go-vela/types/constants" ) func TestRepo_Engine_GetRepo(t *testing.T) { diff --git a/database/repo/list.go b/database/repo/list.go index 980044d97..84e5c5c95 100644 --- a/database/repo/list.go +++ b/database/repo/list.go @@ -6,8 +6,8 @@ import ( "context" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/types" - "github.com/go-vela/types/constants" ) // ListRepos gets a list of all repos from the database. diff --git a/database/repo/list_org.go b/database/repo/list_org.go index 1b39feea8..b390192d4 100644 --- a/database/repo/list_org.go +++ b/database/repo/list_org.go @@ -8,8 +8,8 @@ import ( "github.com/sirupsen/logrus" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/types" - "github.com/go-vela/types/constants" ) // ListReposForOrg gets a list of repos by org name from the database. diff --git a/database/repo/list_org_test.go b/database/repo/list_org_test.go index 9a7bb5aa6..9aad55864 100644 --- a/database/repo/list_org_test.go +++ b/database/repo/list_org_test.go @@ -11,9 +11,9 @@ import ( "github.com/google/go-cmp/cmp" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/testutils" "github.com/go-vela/server/database/types" - "github.com/go-vela/types/constants" ) func TestRepo_Engine_ListReposForOrg(t *testing.T) { diff --git a/database/repo/list_test.go b/database/repo/list_test.go index a4f40dcbe..176d70369 100644 --- a/database/repo/list_test.go +++ b/database/repo/list_test.go @@ -10,9 +10,9 @@ import ( "github.com/DATA-DOG/go-sqlmock" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/testutils" "github.com/go-vela/server/database/types" - "github.com/go-vela/types/constants" ) func TestRepo_Engine_ListRepos(t *testing.T) { diff --git a/database/repo/list_user.go b/database/repo/list_user.go index 997fe15f4..c32d5d05e 100644 --- a/database/repo/list_user.go +++ b/database/repo/list_user.go @@ -8,8 +8,8 @@ import ( "github.com/sirupsen/logrus" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/types" - "github.com/go-vela/types/constants" ) // ListReposForUser gets a list of repos by user ID from the database. diff --git a/database/repo/list_user_test.go b/database/repo/list_user_test.go index 49261c95e..5b9fda28a 100644 --- a/database/repo/list_user_test.go +++ b/database/repo/list_user_test.go @@ -11,9 +11,9 @@ import ( "github.com/DATA-DOG/go-sqlmock" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/testutils" "github.com/go-vela/server/database/types" - "github.com/go-vela/types/constants" ) func TestRepo_Engine_ListReposForUser(t *testing.T) { diff --git a/database/repo/repo.go b/database/repo/repo.go index 2a915192f..55e47587b 100644 --- a/database/repo/repo.go +++ b/database/repo/repo.go @@ -9,7 +9,7 @@ import ( "github.com/sirupsen/logrus" "gorm.io/gorm" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) type ( diff --git a/database/repo/table.go b/database/repo/table.go index 0b16bae94..f49c26933 100644 --- a/database/repo/table.go +++ b/database/repo/table.go @@ -5,7 +5,7 @@ package repo import ( "context" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) const ( diff --git a/database/repo/update.go b/database/repo/update.go index 05af67470..1e4fe88fa 100644 --- a/database/repo/update.go +++ b/database/repo/update.go @@ -10,8 +10,8 @@ import ( "github.com/sirupsen/logrus" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/types" - "github.com/go-vela/types/constants" ) // UpdateRepo updates an existing repo in the database. diff --git a/database/repo/update_test.go b/database/repo/update_test.go index e175a349a..a447d6973 100644 --- a/database/repo/update_test.go +++ b/database/repo/update_test.go @@ -10,8 +10,8 @@ import ( "github.com/DATA-DOG/go-sqlmock" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/testutils" - "github.com/go-vela/types/constants" ) func TestRepo_Engine_UpdateRepo(t *testing.T) { diff --git a/database/schedule/count.go b/database/schedule/count.go index e199e8ed0..e55ef0175 100644 --- a/database/schedule/count.go +++ b/database/schedule/count.go @@ -5,7 +5,7 @@ package schedule import ( "context" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) // CountSchedules gets the count of all schedules from the database. diff --git a/database/schedule/count_active.go b/database/schedule/count_active.go index 5aa6e7209..5f8197e28 100644 --- a/database/schedule/count_active.go +++ b/database/schedule/count_active.go @@ -5,7 +5,7 @@ package schedule import ( "context" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) // CountActiveSchedules gets the count of all active schedules from the database. diff --git a/database/schedule/count_active_test.go b/database/schedule/count_active_test.go index a94af19c6..5cb6efb4f 100644 --- a/database/schedule/count_active_test.go +++ b/database/schedule/count_active_test.go @@ -12,8 +12,8 @@ import ( "github.com/google/go-cmp/cmp" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/testutils" - "github.com/go-vela/types/constants" ) func TestSchedule_Engine_CountActiveSchedules(t *testing.T) { diff --git a/database/schedule/count_repo.go b/database/schedule/count_repo.go index 41246b800..79b4eef98 100644 --- a/database/schedule/count_repo.go +++ b/database/schedule/count_repo.go @@ -8,7 +8,7 @@ import ( "github.com/sirupsen/logrus" api "github.com/go-vela/server/api/types" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) // CountSchedulesForRepo gets the count of schedules by repo ID from the database. diff --git a/database/schedule/count_repo_test.go b/database/schedule/count_repo_test.go index 2b95abd10..847b341cc 100644 --- a/database/schedule/count_repo_test.go +++ b/database/schedule/count_repo_test.go @@ -12,8 +12,8 @@ import ( "github.com/google/go-cmp/cmp" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/testutils" - "github.com/go-vela/types/constants" ) func TestSchedule_Engine_CountSchedulesForRepo(t *testing.T) { diff --git a/database/schedule/count_test.go b/database/schedule/count_test.go index 13be42a30..df58cdd45 100644 --- a/database/schedule/count_test.go +++ b/database/schedule/count_test.go @@ -12,8 +12,8 @@ import ( "github.com/google/go-cmp/cmp" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/testutils" - "github.com/go-vela/types/constants" ) func TestSchedule_Engine_CountSchedules(t *testing.T) { diff --git a/database/schedule/create.go b/database/schedule/create.go index 891237c26..ac2ded2b2 100644 --- a/database/schedule/create.go +++ b/database/schedule/create.go @@ -8,8 +8,8 @@ import ( "github.com/sirupsen/logrus" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/types" - "github.com/go-vela/types/constants" ) // CreateSchedule creates a new schedule in the database. diff --git a/database/schedule/create_test.go b/database/schedule/create_test.go index ac028099e..cb29cd8aa 100644 --- a/database/schedule/create_test.go +++ b/database/schedule/create_test.go @@ -12,8 +12,8 @@ import ( "github.com/google/go-cmp/cmp" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/testutils" - "github.com/go-vela/types/constants" ) func TestSchedule_Engine_CreateSchedule(t *testing.T) { diff --git a/database/schedule/delete.go b/database/schedule/delete.go index 8f28c1173..6ce7db101 100644 --- a/database/schedule/delete.go +++ b/database/schedule/delete.go @@ -8,8 +8,8 @@ import ( "github.com/sirupsen/logrus" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/types" - "github.com/go-vela/types/constants" ) // DeleteSchedule deletes an existing schedule from the database. diff --git a/database/schedule/delete_test.go b/database/schedule/delete_test.go index 971377d92..ca7351863 100644 --- a/database/schedule/delete_test.go +++ b/database/schedule/delete_test.go @@ -11,8 +11,8 @@ import ( "github.com/adhocore/gronx" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/testutils" - "github.com/go-vela/types/constants" ) func TestSchedule_Engine_DeleteSchedule(t *testing.T) { diff --git a/database/schedule/get.go b/database/schedule/get.go index 887d4e002..db02cb521 100644 --- a/database/schedule/get.go +++ b/database/schedule/get.go @@ -6,8 +6,8 @@ import ( "context" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/types" - "github.com/go-vela/types/constants" ) // GetSchedule gets a schedule by ID from the database. diff --git a/database/schedule/get_repo.go b/database/schedule/get_repo.go index 8f0cff429..6602ea5a8 100644 --- a/database/schedule/get_repo.go +++ b/database/schedule/get_repo.go @@ -8,8 +8,8 @@ import ( "github.com/sirupsen/logrus" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/types" - "github.com/go-vela/types/constants" ) // GetScheduleForRepo gets a schedule by repo ID and name from the database. diff --git a/database/schedule/get_repo_test.go b/database/schedule/get_repo_test.go index 346119b3b..07f49bcf3 100644 --- a/database/schedule/get_repo_test.go +++ b/database/schedule/get_repo_test.go @@ -12,8 +12,8 @@ import ( "github.com/google/go-cmp/cmp" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/testutils" - "github.com/go-vela/types/constants" ) func TestSchedule_Engine_GetScheduleForRepo(t *testing.T) { diff --git a/database/schedule/get_test.go b/database/schedule/get_test.go index 5d6f44fca..88ad9df3c 100644 --- a/database/schedule/get_test.go +++ b/database/schedule/get_test.go @@ -12,9 +12,9 @@ import ( "github.com/google/go-cmp/cmp" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/testutils" "github.com/go-vela/server/database/types" - "github.com/go-vela/types/constants" ) func TestSchedule_Engine_GetSchedule(t *testing.T) { diff --git a/database/schedule/list.go b/database/schedule/list.go index 44f548352..53e3c6361 100644 --- a/database/schedule/list.go +++ b/database/schedule/list.go @@ -6,8 +6,8 @@ import ( "context" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/types" - "github.com/go-vela/types/constants" ) // ListSchedules gets a list of all schedules from the database. diff --git a/database/schedule/list_active.go b/database/schedule/list_active.go index 8952de929..665682e2c 100644 --- a/database/schedule/list_active.go +++ b/database/schedule/list_active.go @@ -6,8 +6,8 @@ import ( "context" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/types" - "github.com/go-vela/types/constants" ) // ListActiveSchedules gets a list of all active schedules from the database. diff --git a/database/schedule/list_active_test.go b/database/schedule/list_active_test.go index 385cdf595..d015f0e38 100644 --- a/database/schedule/list_active_test.go +++ b/database/schedule/list_active_test.go @@ -12,9 +12,9 @@ import ( "github.com/google/go-cmp/cmp" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/testutils" "github.com/go-vela/server/database/types" - "github.com/go-vela/types/constants" ) func TestSchedule_Engine_ListActiveSchedules(t *testing.T) { diff --git a/database/schedule/list_repo.go b/database/schedule/list_repo.go index 766e5e1c0..2f23d985d 100644 --- a/database/schedule/list_repo.go +++ b/database/schedule/list_repo.go @@ -8,8 +8,8 @@ import ( "github.com/sirupsen/logrus" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/types" - "github.com/go-vela/types/constants" ) // ListSchedulesForRepo gets a list of schedules by repo ID from the database. diff --git a/database/schedule/list_repo_test.go b/database/schedule/list_repo_test.go index d73107f6e..a1b8f7131 100644 --- a/database/schedule/list_repo_test.go +++ b/database/schedule/list_repo_test.go @@ -12,8 +12,8 @@ import ( "github.com/google/go-cmp/cmp" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/testutils" - "github.com/go-vela/types/constants" ) func TestSchedule_Engine_ListSchedulesForRepo(t *testing.T) { diff --git a/database/schedule/list_test.go b/database/schedule/list_test.go index b699a12c4..5d8b5d738 100644 --- a/database/schedule/list_test.go +++ b/database/schedule/list_test.go @@ -12,9 +12,9 @@ import ( "github.com/google/go-cmp/cmp" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/testutils" "github.com/go-vela/server/database/types" - "github.com/go-vela/types/constants" ) func TestSchedule_Engine_ListSchedules(t *testing.T) { diff --git a/database/schedule/schedule.go b/database/schedule/schedule.go index b7a83b2dd..66d345f1d 100644 --- a/database/schedule/schedule.go +++ b/database/schedule/schedule.go @@ -9,7 +9,7 @@ import ( "github.com/sirupsen/logrus" "gorm.io/gorm" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) type ( diff --git a/database/schedule/table.go b/database/schedule/table.go index 86eda10bc..c6db79c4a 100644 --- a/database/schedule/table.go +++ b/database/schedule/table.go @@ -5,7 +5,7 @@ package schedule import ( "context" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) const ( diff --git a/database/schedule/update.go b/database/schedule/update.go index d2f9cbf33..8ff3c478c 100644 --- a/database/schedule/update.go +++ b/database/schedule/update.go @@ -8,8 +8,8 @@ import ( "github.com/sirupsen/logrus" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/types" - "github.com/go-vela/types/constants" ) // UpdateSchedule updates an existing schedule in the database. diff --git a/database/schedule/update_test.go b/database/schedule/update_test.go index c936b2ab1..bcf675edb 100644 --- a/database/schedule/update_test.go +++ b/database/schedule/update_test.go @@ -12,8 +12,8 @@ import ( "github.com/google/go-cmp/cmp" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/testutils" - "github.com/go-vela/types/constants" ) func TestSchedule_Engine_UpdateSchedule_Config(t *testing.T) { diff --git a/database/secret/count.go b/database/secret/count.go index 2b9b36ad0..0af09e015 100644 --- a/database/secret/count.go +++ b/database/secret/count.go @@ -5,7 +5,7 @@ package secret import ( "context" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) // CountSecrets gets the count of all secrets from the database. diff --git a/database/secret/count_org.go b/database/secret/count_org.go index 85fb17624..ecea526c1 100644 --- a/database/secret/count_org.go +++ b/database/secret/count_org.go @@ -7,7 +7,7 @@ import ( "github.com/sirupsen/logrus" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) // CountSecretsForOrg gets the count of secrets by org name from the database. diff --git a/database/secret/count_org_test.go b/database/secret/count_org_test.go index 315862543..bcad30bc0 100644 --- a/database/secret/count_org_test.go +++ b/database/secret/count_org_test.go @@ -9,8 +9,8 @@ import ( "github.com/DATA-DOG/go-sqlmock" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/testutils" - "github.com/go-vela/types/constants" ) func TestSecret_Engine_CountSecretsForOrg(t *testing.T) { diff --git a/database/secret/count_repo.go b/database/secret/count_repo.go index 6430f7fe9..08772e47f 100644 --- a/database/secret/count_repo.go +++ b/database/secret/count_repo.go @@ -8,7 +8,7 @@ import ( "github.com/sirupsen/logrus" api "github.com/go-vela/server/api/types" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) // CountSecretsForRepo gets the count of secrets by org and repo name from the database. diff --git a/database/secret/count_repo_test.go b/database/secret/count_repo_test.go index 41fa3f8a5..fad58a926 100644 --- a/database/secret/count_repo_test.go +++ b/database/secret/count_repo_test.go @@ -9,8 +9,8 @@ import ( "github.com/DATA-DOG/go-sqlmock" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/testutils" - "github.com/go-vela/types/constants" ) func TestSecret_Engine_CountSecretsForRepo(t *testing.T) { diff --git a/database/secret/count_team.go b/database/secret/count_team.go index af158dcbc..03346756d 100644 --- a/database/secret/count_team.go +++ b/database/secret/count_team.go @@ -8,7 +8,7 @@ import ( "github.com/sirupsen/logrus" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) // CountSecretsForTeam gets the count of secrets by org and team name from the database. diff --git a/database/secret/count_team_test.go b/database/secret/count_team_test.go index f38cbbd3b..316510b43 100644 --- a/database/secret/count_team_test.go +++ b/database/secret/count_team_test.go @@ -9,8 +9,8 @@ import ( "github.com/DATA-DOG/go-sqlmock" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/testutils" - "github.com/go-vela/types/constants" ) func TestSecret_Engine_CountSecretsForTeam(t *testing.T) { diff --git a/database/secret/create.go b/database/secret/create.go index ec38cc748..c0ac65dc7 100644 --- a/database/secret/create.go +++ b/database/secret/create.go @@ -10,8 +10,8 @@ import ( "github.com/sirupsen/logrus" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/types" - "github.com/go-vela/types/constants" ) // CreateSecret creates a new secret in the database. diff --git a/database/secret/delete.go b/database/secret/delete.go index 309a0cf61..59c781237 100644 --- a/database/secret/delete.go +++ b/database/secret/delete.go @@ -8,8 +8,8 @@ import ( "github.com/sirupsen/logrus" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/types" - "github.com/go-vela/types/constants" ) // DeleteSecret deletes an existing secret from the database. diff --git a/database/secret/get.go b/database/secret/get.go index c43cf2bb2..7b546a035 100644 --- a/database/secret/get.go +++ b/database/secret/get.go @@ -6,8 +6,8 @@ import ( "context" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/types" - "github.com/go-vela/types/constants" ) // GetSecret gets a secret by ID from the database. diff --git a/database/secret/get_org.go b/database/secret/get_org.go index ee4c3391c..9782391b0 100644 --- a/database/secret/get_org.go +++ b/database/secret/get_org.go @@ -8,8 +8,8 @@ import ( "github.com/sirupsen/logrus" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/types" - "github.com/go-vela/types/constants" ) // GetSecretForOrg gets a secret by org name from the database. diff --git a/database/secret/get_org_test.go b/database/secret/get_org_test.go index 5261c49f5..71298a4ab 100644 --- a/database/secret/get_org_test.go +++ b/database/secret/get_org_test.go @@ -10,8 +10,8 @@ import ( "github.com/DATA-DOG/go-sqlmock" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/testutils" - "github.com/go-vela/types/constants" ) func TestSecret_Engine_GetSecretForOrg(t *testing.T) { diff --git a/database/secret/get_repo.go b/database/secret/get_repo.go index b22264482..dc83a60fa 100644 --- a/database/secret/get_repo.go +++ b/database/secret/get_repo.go @@ -8,8 +8,8 @@ import ( "github.com/sirupsen/logrus" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/types" - "github.com/go-vela/types/constants" ) // GetSecretForRepo gets a secret by org and repo name from the database. diff --git a/database/secret/get_repo_test.go b/database/secret/get_repo_test.go index e9ccb8550..f2ab5b8ef 100644 --- a/database/secret/get_repo_test.go +++ b/database/secret/get_repo_test.go @@ -10,8 +10,8 @@ import ( "github.com/DATA-DOG/go-sqlmock" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/testutils" - "github.com/go-vela/types/constants" ) func TestSecret_Engine_GetSecretForRepo(t *testing.T) { diff --git a/database/secret/get_team.go b/database/secret/get_team.go index 6c4a0f285..baae49f70 100644 --- a/database/secret/get_team.go +++ b/database/secret/get_team.go @@ -8,8 +8,8 @@ import ( "github.com/sirupsen/logrus" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/types" - "github.com/go-vela/types/constants" ) // GetSecretForTeam gets a secret by org and team name from the database. diff --git a/database/secret/get_team_test.go b/database/secret/get_team_test.go index 1b2cf0777..757f0ed39 100644 --- a/database/secret/get_team_test.go +++ b/database/secret/get_team_test.go @@ -10,8 +10,8 @@ import ( "github.com/DATA-DOG/go-sqlmock" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/testutils" - "github.com/go-vela/types/constants" ) func TestSecret_Engine_GetSecretForTeam(t *testing.T) { diff --git a/database/secret/list.go b/database/secret/list.go index 876f90281..0f11b750f 100644 --- a/database/secret/list.go +++ b/database/secret/list.go @@ -6,8 +6,8 @@ import ( "context" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/types" - "github.com/go-vela/types/constants" ) // ListSecrets gets a list of all secrets from the database. diff --git a/database/secret/list_org.go b/database/secret/list_org.go index b02a466c6..a32ddda34 100644 --- a/database/secret/list_org.go +++ b/database/secret/list_org.go @@ -8,8 +8,8 @@ import ( "github.com/sirupsen/logrus" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/types" - "github.com/go-vela/types/constants" ) // ListSecretsForOrg gets a list of secrets by org name from the database. diff --git a/database/secret/list_org_test.go b/database/secret/list_org_test.go index a4da8ab07..f5a274679 100644 --- a/database/secret/list_org_test.go +++ b/database/secret/list_org_test.go @@ -10,8 +10,8 @@ import ( "github.com/DATA-DOG/go-sqlmock" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/testutils" - "github.com/go-vela/types/constants" ) func TestSecret_Engine_ListSecretsForOrg(t *testing.T) { diff --git a/database/secret/list_repo.go b/database/secret/list_repo.go index 8b69b6a17..59520ea12 100644 --- a/database/secret/list_repo.go +++ b/database/secret/list_repo.go @@ -8,8 +8,8 @@ import ( "github.com/sirupsen/logrus" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/types" - "github.com/go-vela/types/constants" ) // ListSecretsForRepo gets a list of secrets by org name from the database. diff --git a/database/secret/list_repo_test.go b/database/secret/list_repo_test.go index aa0b6df0f..685cc52bb 100644 --- a/database/secret/list_repo_test.go +++ b/database/secret/list_repo_test.go @@ -10,8 +10,8 @@ import ( "github.com/DATA-DOG/go-sqlmock" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/testutils" - "github.com/go-vela/types/constants" ) func TestSecret_Engine_ListSecretsForRepo(t *testing.T) { diff --git a/database/secret/list_team.go b/database/secret/list_team.go index 16787a2e7..ae56a3da4 100644 --- a/database/secret/list_team.go +++ b/database/secret/list_team.go @@ -9,8 +9,8 @@ import ( "github.com/sirupsen/logrus" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/types" - "github.com/go-vela/types/constants" ) // ListSecretsForTeam gets a list of secrets by org and team name from the database. diff --git a/database/secret/list_team_test.go b/database/secret/list_team_test.go index f49c206a8..382f6864c 100644 --- a/database/secret/list_team_test.go +++ b/database/secret/list_team_test.go @@ -10,8 +10,8 @@ import ( "github.com/DATA-DOG/go-sqlmock" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/testutils" - "github.com/go-vela/types/constants" ) func TestSecret_Engine_ListSecretsForTeam(t *testing.T) { diff --git a/database/secret/secret.go b/database/secret/secret.go index 4a7c772e8..b0119503f 100644 --- a/database/secret/secret.go +++ b/database/secret/secret.go @@ -9,7 +9,7 @@ import ( "github.com/sirupsen/logrus" "gorm.io/gorm" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) type ( diff --git a/database/secret/table.go b/database/secret/table.go index 650a3f3f4..f521459a2 100644 --- a/database/secret/table.go +++ b/database/secret/table.go @@ -5,7 +5,7 @@ package secret import ( "context" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) const ( diff --git a/database/secret/update.go b/database/secret/update.go index e88c9fc54..d512e7e33 100644 --- a/database/secret/update.go +++ b/database/secret/update.go @@ -10,8 +10,8 @@ import ( "github.com/sirupsen/logrus" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/types" - "github.com/go-vela/types/constants" ) // UpdateSecret updates an existing secret in the database. diff --git a/database/service/clean.go b/database/service/clean.go index d234b4478..ac3bce1be 100644 --- a/database/service/clean.go +++ b/database/service/clean.go @@ -8,21 +8,21 @@ import ( "github.com/sirupsen/logrus" - "github.com/go-vela/types/constants" - "github.com/go-vela/types/database" - "github.com/go-vela/types/library" + api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" + "github.com/go-vela/server/database/types" ) // CleanServices updates services to an error with a created timestamp prior to a defined moment. func (e *engine) CleanServices(ctx context.Context, msg string, before int64) (int64, error) { logrus.Tracef("cleaning pending or running steps in the database created prior to %d", before) - s := new(library.Service) + s := new(api.Service) s.SetStatus(constants.StatusError) s.SetError(msg) s.SetFinished(time.Now().UTC().Unix()) - service := database.ServiceFromLibrary(s) + service := types.ServiceFromAPI(s) // send query to the database result := e.client. diff --git a/database/service/count.go b/database/service/count.go index 86e76cfe2..dabefecc2 100644 --- a/database/service/count.go +++ b/database/service/count.go @@ -5,7 +5,7 @@ package service import ( "context" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) // CountServices gets the count of all services from the database. diff --git a/database/service/count_build.go b/database/service/count_build.go index 0f00403e2..0bf016e6e 100644 --- a/database/service/count_build.go +++ b/database/service/count_build.go @@ -8,7 +8,7 @@ import ( "github.com/sirupsen/logrus" api "github.com/go-vela/server/api/types" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) // CountServicesForBuild gets the count of services by build ID from the database. diff --git a/database/service/create.go b/database/service/create.go index 3ecb96e04..dfe32683b 100644 --- a/database/service/create.go +++ b/database/service/create.go @@ -7,25 +7,19 @@ import ( "github.com/sirupsen/logrus" - "github.com/go-vela/types/constants" - "github.com/go-vela/types/database" - "github.com/go-vela/types/library" + api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" + "github.com/go-vela/server/database/types" ) // CreateService creates a new service in the database. -func (e *engine) CreateService(ctx context.Context, s *library.Service) (*library.Service, error) { +func (e *engine) CreateService(ctx context.Context, s *api.Service) (*api.Service, error) { e.logger.WithFields(logrus.Fields{ "service": s.GetNumber(), }).Tracef("creating service %s in the database", s.GetName()) - // cast the library type to database type - // - // https://pkg.go.dev/github.com/go-vela/types/database#ServiceFromLibrary - service := database.ServiceFromLibrary(s) + service := types.ServiceFromAPI(s) - // validate the necessary fields are populated - // - // https://pkg.go.dev/github.com/go-vela/types/database#Service.Validate err := service.Validate() if err != nil { return nil, err @@ -37,5 +31,5 @@ func (e *engine) CreateService(ctx context.Context, s *library.Service) (*librar Table(constants.TableService). Create(service) - return service.ToLibrary(), result.Error + return service.ToAPI(), result.Error } diff --git a/database/service/delete.go b/database/service/delete.go index 835a25992..3fd77c9c7 100644 --- a/database/service/delete.go +++ b/database/service/delete.go @@ -7,21 +7,18 @@ import ( "github.com/sirupsen/logrus" - "github.com/go-vela/types/constants" - "github.com/go-vela/types/database" - "github.com/go-vela/types/library" + api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" + "github.com/go-vela/server/database/types" ) // DeleteService deletes an existing service from the database. -func (e *engine) DeleteService(ctx context.Context, s *library.Service) error { +func (e *engine) DeleteService(ctx context.Context, s *api.Service) error { e.logger.WithFields(logrus.Fields{ "service": s.GetNumber(), }).Tracef("deleting service %s", s.GetName()) - // cast the library type to database type - // - // https://pkg.go.dev/github.com/go-vela/types/database#ServiceFromLibrary - service := database.ServiceFromLibrary(s) + service := types.ServiceFromAPI(s) // send query to the database return e.client. diff --git a/database/service/get.go b/database/service/get.go index 37cf9a5d0..fc5697405 100644 --- a/database/service/get.go +++ b/database/service/get.go @@ -5,17 +5,17 @@ package service import ( "context" - "github.com/go-vela/types/constants" - "github.com/go-vela/types/database" - "github.com/go-vela/types/library" + api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" + "github.com/go-vela/server/database/types" ) // GetService gets a service by ID from the database. -func (e *engine) GetService(ctx context.Context, id int64) (*library.Service, error) { +func (e *engine) GetService(ctx context.Context, id int64) (*api.Service, error) { e.logger.Tracef("getting service %d", id) // variable to store query results - s := new(database.Service) + s := new(types.Service) // send query to the database and store result in variable err := e.client. @@ -28,8 +28,5 @@ func (e *engine) GetService(ctx context.Context, id int64) (*library.Service, er return nil, err } - // return the service - // - // https://pkg.go.dev/github.com/go-vela/types/database#Service.ToLibrary - return s.ToLibrary(), nil + return s.ToAPI(), nil } diff --git a/database/service/get_build.go b/database/service/get_build.go index e85ddc368..b6a77915d 100644 --- a/database/service/get_build.go +++ b/database/service/get_build.go @@ -8,20 +8,19 @@ import ( "github.com/sirupsen/logrus" api "github.com/go-vela/server/api/types" - "github.com/go-vela/types/constants" - "github.com/go-vela/types/database" - "github.com/go-vela/types/library" + "github.com/go-vela/server/constants" + "github.com/go-vela/server/database/types" ) // GetServiceForBuild gets a service by number and build ID from the database. -func (e *engine) GetServiceForBuild(ctx context.Context, b *api.Build, number int) (*library.Service, error) { +func (e *engine) GetServiceForBuild(ctx context.Context, b *api.Build, number int) (*api.Service, error) { e.logger.WithFields(logrus.Fields{ "build": b.GetNumber(), "service": number, }).Tracef("getting service %d", number) // variable to store query results - s := new(database.Service) + s := new(types.Service) // send query to the database and store result in variable err := e.client. @@ -35,8 +34,5 @@ func (e *engine) GetServiceForBuild(ctx context.Context, b *api.Build, number in return nil, err } - // return the service - // - // https://pkg.go.dev/github.com/go-vela/types/database#Service.ToLibrary - return s.ToLibrary(), nil + return s.ToAPI(), nil } diff --git a/database/service/get_build_test.go b/database/service/get_build_test.go index da26e4ce9..8afa50390 100644 --- a/database/service/get_build_test.go +++ b/database/service/get_build_test.go @@ -9,8 +9,8 @@ import ( "github.com/DATA-DOG/go-sqlmock" + api "github.com/go-vela/server/api/types" "github.com/go-vela/server/database/testutils" - "github.com/go-vela/types/library" ) func TestService_Engine_GetServiceForBuild(t *testing.T) { @@ -52,7 +52,7 @@ func TestService_Engine_GetServiceForBuild(t *testing.T) { failure bool name string database *engine - want *library.Service + want *api.Service }{ { failure: false, diff --git a/database/service/get_test.go b/database/service/get_test.go index 612811eed..a07d26c43 100644 --- a/database/service/get_test.go +++ b/database/service/get_test.go @@ -9,8 +9,8 @@ import ( "github.com/DATA-DOG/go-sqlmock" + api "github.com/go-vela/server/api/types" "github.com/go-vela/server/database/testutils" - "github.com/go-vela/types/library" ) func TestService_Engine_GetService(t *testing.T) { @@ -47,7 +47,7 @@ func TestService_Engine_GetService(t *testing.T) { failure bool name string database *engine - want *library.Service + want *api.Service }{ { failure: false, diff --git a/database/service/interface.go b/database/service/interface.go index 40fc30293..161103d26 100644 --- a/database/service/interface.go +++ b/database/service/interface.go @@ -6,7 +6,6 @@ import ( "context" api "github.com/go-vela/server/api/types" - "github.com/go-vela/types/library" ) // ServiceInterface represents the Vela interface for service @@ -32,21 +31,21 @@ type ServiceInterface interface { // CountServicesForBuild defines a function that gets the count of services by build ID. CountServicesForBuild(context.Context, *api.Build, map[string]interface{}) (int64, error) // CreateService defines a function that creates a new service. - CreateService(context.Context, *library.Service) (*library.Service, error) + CreateService(context.Context, *api.Service) (*api.Service, error) // DeleteService defines a function that deletes an existing service. - DeleteService(context.Context, *library.Service) error + DeleteService(context.Context, *api.Service) error // GetService defines a function that gets a service by ID. - GetService(context.Context, int64) (*library.Service, error) + GetService(context.Context, int64) (*api.Service, error) // GetServiceForBuild defines a function that gets a service by number and build ID. - GetServiceForBuild(context.Context, *api.Build, int) (*library.Service, error) + GetServiceForBuild(context.Context, *api.Build, int) (*api.Service, error) // ListServices defines a function that gets a list of all services. - ListServices(context.Context) ([]*library.Service, error) + ListServices(context.Context) ([]*api.Service, error) // ListServicesForBuild defines a function that gets a list of services by build ID. - ListServicesForBuild(context.Context, *api.Build, map[string]interface{}, int, int) ([]*library.Service, int64, error) + ListServicesForBuild(context.Context, *api.Build, map[string]interface{}, int, int) ([]*api.Service, int64, error) // ListServiceImageCount defines a function that gets a list of all service images and the count of their occurrence. ListServiceImageCount(context.Context) (map[string]float64, error) // ListServiceStatusCount defines a function that gets a list of all service statuses and the count of their occurrence. ListServiceStatusCount(context.Context) (map[string]float64, error) // UpdateService defines a function that updates an existing service. - UpdateService(context.Context, *library.Service) (*library.Service, error) + UpdateService(context.Context, *api.Service) (*api.Service, error) } diff --git a/database/service/list.go b/database/service/list.go index 6dd70fdd1..6f09c6dcd 100644 --- a/database/service/list.go +++ b/database/service/list.go @@ -5,19 +5,19 @@ package service import ( "context" - "github.com/go-vela/types/constants" - "github.com/go-vela/types/database" - "github.com/go-vela/types/library" + api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" + "github.com/go-vela/server/database/types" ) // ListServices gets a list of all services from the database. -func (e *engine) ListServices(ctx context.Context) ([]*library.Service, error) { +func (e *engine) ListServices(ctx context.Context) ([]*api.Service, error) { e.logger.Trace("listing all services") // variables to store query results and return value count := int64(0) - w := new([]database.Service) - services := []*library.Service{} + w := new([]types.Service) + services := []*api.Service{} // count the results count, err := e.CountServices(ctx) @@ -45,10 +45,7 @@ func (e *engine) ListServices(ctx context.Context) ([]*library.Service, error) { // https://golang.org/doc/faq#closures_and_goroutines tmp := service - // convert query result to library type - // - // https://pkg.go.dev/github.com/go-vela/types/database#Service.ToLibrary - services = append(services, tmp.ToLibrary()) + services = append(services, tmp.ToAPI()) } return services, nil diff --git a/database/service/list_build.go b/database/service/list_build.go index faf8c81fb..7aa897aa4 100644 --- a/database/service/list_build.go +++ b/database/service/list_build.go @@ -8,21 +8,20 @@ import ( "github.com/sirupsen/logrus" api "github.com/go-vela/server/api/types" - "github.com/go-vela/types/constants" - "github.com/go-vela/types/database" - "github.com/go-vela/types/library" + "github.com/go-vela/server/constants" + "github.com/go-vela/server/database/types" ) // ListServicesForBuild gets a list of all services from the database. -func (e *engine) ListServicesForBuild(ctx context.Context, b *api.Build, filters map[string]interface{}, page int, perPage int) ([]*library.Service, int64, error) { +func (e *engine) ListServicesForBuild(ctx context.Context, b *api.Build, filters map[string]interface{}, page int, perPage int) ([]*api.Service, int64, error) { e.logger.WithFields(logrus.Fields{ "build": b.GetNumber(), }).Tracef("listing services for build %d", b.GetNumber()) // variables to store query results and return value count := int64(0) - s := new([]database.Service) - services := []*library.Service{} + s := new([]types.Service) + services := []*api.Service{} // count the results count, err := e.CountServicesForBuild(ctx, b, filters) @@ -58,10 +57,7 @@ func (e *engine) ListServicesForBuild(ctx context.Context, b *api.Build, filters // https://golang.org/doc/faq#closures_and_goroutines tmp := service - // convert query result to library type - // - // https://pkg.go.dev/github.com/go-vela/types/database#Service.ToLibrary - services = append(services, tmp.ToLibrary()) + services = append(services, tmp.ToAPI()) } return services, count, nil diff --git a/database/service/list_build_test.go b/database/service/list_build_test.go index cd09061ee..cf00dbc54 100644 --- a/database/service/list_build_test.go +++ b/database/service/list_build_test.go @@ -9,8 +9,8 @@ import ( "github.com/DATA-DOG/go-sqlmock" + api "github.com/go-vela/server/api/types" "github.com/go-vela/server/database/testutils" - "github.com/go-vela/types/library" ) func TestService_Engine_ListServicesForBuild(t *testing.T) { @@ -72,19 +72,19 @@ func TestService_Engine_ListServicesForBuild(t *testing.T) { failure bool name string database *engine - want []*library.Service + want []*api.Service }{ { failure: false, name: "postgres", database: _postgres, - want: []*library.Service{_serviceTwo, _serviceOne}, + want: []*api.Service{_serviceTwo, _serviceOne}, }, { failure: false, name: "sqlite3", database: _sqlite, - want: []*library.Service{_serviceTwo, _serviceOne}, + want: []*api.Service{_serviceTwo, _serviceOne}, }, } diff --git a/database/service/list_image.go b/database/service/list_image.go index dbff3913c..cc17ec885 100644 --- a/database/service/list_image.go +++ b/database/service/list_image.go @@ -6,7 +6,7 @@ import ( "context" "database/sql" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) // ListServiceImageCount gets a list of all service images and the count of their occurrence from the database. diff --git a/database/service/list_status.go b/database/service/list_status.go index b2570b55d..9593daa10 100644 --- a/database/service/list_status.go +++ b/database/service/list_status.go @@ -6,7 +6,7 @@ import ( "context" "database/sql" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) // ListServiceStatusCount gets a list of all service statuses and the count of their occurrence from the database. diff --git a/database/service/list_test.go b/database/service/list_test.go index 462dae56c..7b6afa58e 100644 --- a/database/service/list_test.go +++ b/database/service/list_test.go @@ -9,8 +9,8 @@ import ( "github.com/DATA-DOG/go-sqlmock" + api "github.com/go-vela/server/api/types" "github.com/go-vela/server/database/testutils" - "github.com/go-vela/types/library" ) func TestService_Engine_ListServices(t *testing.T) { @@ -67,19 +67,19 @@ func TestService_Engine_ListServices(t *testing.T) { failure bool name string database *engine - want []*library.Service + want []*api.Service }{ { failure: false, name: "postgres", database: _postgres, - want: []*library.Service{_serviceOne, _serviceTwo}, + want: []*api.Service{_serviceOne, _serviceTwo}, }, { failure: false, name: "sqlite3", database: _sqlite, - want: []*library.Service{_serviceOne, _serviceTwo}, + want: []*api.Service{_serviceOne, _serviceTwo}, }, } diff --git a/database/service/service.go b/database/service/service.go index f02f6ae6b..a35b47bd3 100644 --- a/database/service/service.go +++ b/database/service/service.go @@ -9,7 +9,7 @@ import ( "github.com/sirupsen/logrus" "gorm.io/gorm" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) type ( diff --git a/database/service/table.go b/database/service/table.go index 426eb2333..04b9e977a 100644 --- a/database/service/table.go +++ b/database/service/table.go @@ -5,7 +5,7 @@ package service import ( "context" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) const ( diff --git a/database/service/update.go b/database/service/update.go index a53b9ae41..a3e4a38e8 100644 --- a/database/service/update.go +++ b/database/service/update.go @@ -7,25 +7,19 @@ import ( "github.com/sirupsen/logrus" - "github.com/go-vela/types/constants" - "github.com/go-vela/types/database" - "github.com/go-vela/types/library" + api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" + "github.com/go-vela/server/database/types" ) // UpdateService updates an existing service in the database. -func (e *engine) UpdateService(ctx context.Context, s *library.Service) (*library.Service, error) { +func (e *engine) UpdateService(ctx context.Context, s *api.Service) (*api.Service, error) { e.logger.WithFields(logrus.Fields{ "service": s.GetNumber(), }).Tracef("updating service %s", s.GetName()) - // cast the library type to database type - // - // https://pkg.go.dev/github.com/go-vela/types/database#ServiceFromLibrary - service := database.ServiceFromLibrary(s) + service := types.ServiceFromAPI(s) - // validate the necessary fields are populated - // - // https://pkg.go.dev/github.com/go-vela/types/database#Service.Validate err := service.Validate() if err != nil { return nil, err @@ -37,5 +31,5 @@ func (e *engine) UpdateService(ctx context.Context, s *library.Service) (*librar Table(constants.TableService). Save(service) - return service.ToLibrary(), result.Error + return service.ToAPI(), result.Error } diff --git a/database/settings/table.go b/database/settings/table.go index 3eba03cfe..3c1836a55 100644 --- a/database/settings/table.go +++ b/database/settings/table.go @@ -5,7 +5,7 @@ package settings import ( "context" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) const ( diff --git a/database/step/clean.go b/database/step/clean.go index b7d8cb8f6..5ce04a1ed 100644 --- a/database/step/clean.go +++ b/database/step/clean.go @@ -8,21 +8,21 @@ import ( "github.com/sirupsen/logrus" - "github.com/go-vela/types/constants" - "github.com/go-vela/types/database" - "github.com/go-vela/types/library" + api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" + "github.com/go-vela/server/database/types" ) // CleanSteps updates steps to an error with a created timestamp prior to a defined moment. func (e *engine) CleanSteps(ctx context.Context, msg string, before int64) (int64, error) { logrus.Tracef("cleaning pending or running steps in the database created prior to %d", before) - s := new(library.Step) + s := new(api.Step) s.SetStatus(constants.StatusError) s.SetError(msg) s.SetFinished(time.Now().UTC().Unix()) - step := database.StepFromLibrary(s) + step := types.StepFromAPI(s) // send query to the database result := e.client. diff --git a/database/step/count.go b/database/step/count.go index bb9f0ce3a..0264283dc 100644 --- a/database/step/count.go +++ b/database/step/count.go @@ -5,7 +5,7 @@ package step import ( "context" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) // CountSteps gets the count of all steps from the database. diff --git a/database/step/count_build.go b/database/step/count_build.go index 4a0cefda5..cce1d20a7 100644 --- a/database/step/count_build.go +++ b/database/step/count_build.go @@ -8,7 +8,7 @@ import ( "github.com/sirupsen/logrus" api "github.com/go-vela/server/api/types" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) // CountStepsForBuild gets the count of steps by build ID from the database. diff --git a/database/step/create.go b/database/step/create.go index 9e46cf146..bb8b17396 100644 --- a/database/step/create.go +++ b/database/step/create.go @@ -7,25 +7,19 @@ import ( "github.com/sirupsen/logrus" - "github.com/go-vela/types/constants" - "github.com/go-vela/types/database" - "github.com/go-vela/types/library" + api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" + "github.com/go-vela/server/database/types" ) // CreateStep creates a new step in the database. -func (e *engine) CreateStep(ctx context.Context, s *library.Step) (*library.Step, error) { +func (e *engine) CreateStep(ctx context.Context, s *api.Step) (*api.Step, error) { e.logger.WithFields(logrus.Fields{ "step": s.GetNumber(), }).Tracef("creating step %s in the database", s.GetName()) - // cast the library type to database type - // - // https://pkg.go.dev/github.com/go-vela/types/database#StepFromLibrary - step := database.StepFromLibrary(s) + step := types.StepFromAPI(s) - // validate the necessary fields are populated - // - // https://pkg.go.dev/github.com/go-vela/types/database#Step.Validate err := step.Validate() if err != nil { return nil, err @@ -37,5 +31,5 @@ func (e *engine) CreateStep(ctx context.Context, s *library.Step) (*library.Step Table(constants.TableStep). Create(step) - return step.ToLibrary(), result.Error + return step.ToAPI(), result.Error } diff --git a/database/step/delete.go b/database/step/delete.go index 7c9139f6b..70c30e228 100644 --- a/database/step/delete.go +++ b/database/step/delete.go @@ -7,13 +7,13 @@ import ( "github.com/sirupsen/logrus" - "github.com/go-vela/types/constants" - "github.com/go-vela/types/database" - "github.com/go-vela/types/library" + api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" + "github.com/go-vela/server/database/types" ) // DeleteStep deletes an existing step from the database. -func (e *engine) DeleteStep(ctx context.Context, s *library.Step) error { +func (e *engine) DeleteStep(ctx context.Context, s *api.Step) error { e.logger.WithFields(logrus.Fields{ "step": s.GetNumber(), }).Tracef("deleting step %s", s.GetName()) @@ -21,7 +21,7 @@ func (e *engine) DeleteStep(ctx context.Context, s *library.Step) error { // cast the library type to database type // // https://pkg.go.dev/github.com/go-vela/types/database#StepFromLibrary - step := database.StepFromLibrary(s) + step := types.StepFromAPI(s) // send query to the database return e.client. diff --git a/database/step/get.go b/database/step/get.go index a05a56fce..51a5778f7 100644 --- a/database/step/get.go +++ b/database/step/get.go @@ -5,17 +5,17 @@ package step import ( "context" - "github.com/go-vela/types/constants" - "github.com/go-vela/types/database" - "github.com/go-vela/types/library" + api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" + "github.com/go-vela/server/database/types" ) // GetStep gets a step by ID from the database. -func (e *engine) GetStep(ctx context.Context, id int64) (*library.Step, error) { +func (e *engine) GetStep(ctx context.Context, id int64) (*api.Step, error) { e.logger.Tracef("getting step %d", id) // variable to store query results - s := new(database.Step) + s := new(types.Step) // send query to the database and store result in variable err := e.client. @@ -28,8 +28,5 @@ func (e *engine) GetStep(ctx context.Context, id int64) (*library.Step, error) { return nil, err } - // return the step - // - // https://pkg.go.dev/github.com/go-vela/types/database#Step.ToLibrary - return s.ToLibrary(), nil + return s.ToAPI(), nil } diff --git a/database/step/get_build.go b/database/step/get_build.go index de847a769..0f8d495c5 100644 --- a/database/step/get_build.go +++ b/database/step/get_build.go @@ -8,20 +8,19 @@ import ( "github.com/sirupsen/logrus" api "github.com/go-vela/server/api/types" - "github.com/go-vela/types/constants" - "github.com/go-vela/types/database" - "github.com/go-vela/types/library" + "github.com/go-vela/server/constants" + "github.com/go-vela/server/database/types" ) // GetStepForBuild gets a step by number and build ID from the database. -func (e *engine) GetStepForBuild(ctx context.Context, b *api.Build, number int) (*library.Step, error) { +func (e *engine) GetStepForBuild(ctx context.Context, b *api.Build, number int) (*api.Step, error) { e.logger.WithFields(logrus.Fields{ "build": b.GetNumber(), "step": number, }).Tracef("getting step %d", number) // variable to store query results - s := new(database.Step) + s := new(types.Step) // send query to the database and store result in variable err := e.client. @@ -35,8 +34,5 @@ func (e *engine) GetStepForBuild(ctx context.Context, b *api.Build, number int) return nil, err } - // return the step - // - // https://pkg.go.dev/github.com/go-vela/types/database#Step.ToLibrary - return s.ToLibrary(), nil + return s.ToAPI(), nil } diff --git a/database/step/get_build_test.go b/database/step/get_build_test.go index c5490aa58..e39ef5c6c 100644 --- a/database/step/get_build_test.go +++ b/database/step/get_build_test.go @@ -9,8 +9,8 @@ import ( "github.com/DATA-DOG/go-sqlmock" "github.com/google/go-cmp/cmp" + api "github.com/go-vela/server/api/types" "github.com/go-vela/server/database/testutils" - "github.com/go-vela/types/library" ) func TestStep_Engine_GetStepForBuild(t *testing.T) { @@ -54,7 +54,7 @@ func TestStep_Engine_GetStepForBuild(t *testing.T) { failure bool name string database *engine - want *library.Step + want *api.Step }{ { failure: false, diff --git a/database/step/get_test.go b/database/step/get_test.go index 4c05103ea..ef5acc816 100644 --- a/database/step/get_test.go +++ b/database/step/get_test.go @@ -9,8 +9,8 @@ import ( "github.com/DATA-DOG/go-sqlmock" + api "github.com/go-vela/server/api/types" "github.com/go-vela/server/database/testutils" - "github.com/go-vela/types/library" ) func TestStep_Engine_GetStep(t *testing.T) { @@ -49,7 +49,7 @@ func TestStep_Engine_GetStep(t *testing.T) { failure bool name string database *engine - want *library.Step + want *api.Step }{ { failure: false, diff --git a/database/step/interface.go b/database/step/interface.go index 6de0cc168..ef74d05ea 100644 --- a/database/step/interface.go +++ b/database/step/interface.go @@ -6,7 +6,6 @@ import ( "context" api "github.com/go-vela/server/api/types" - "github.com/go-vela/types/library" ) // StepInterface represents the Vela interface for step @@ -32,21 +31,21 @@ type StepInterface interface { // CountStepsForBuild defines a function that gets the count of steps by build ID. CountStepsForBuild(context.Context, *api.Build, map[string]interface{}) (int64, error) // CreateStep defines a function that creates a new step. - CreateStep(context.Context, *library.Step) (*library.Step, error) + CreateStep(context.Context, *api.Step) (*api.Step, error) // DeleteStep defines a function that deletes an existing step. - DeleteStep(context.Context, *library.Step) error + DeleteStep(context.Context, *api.Step) error // GetStep defines a function that gets a step by ID. - GetStep(context.Context, int64) (*library.Step, error) + GetStep(context.Context, int64) (*api.Step, error) // GetStepForBuild defines a function that gets a step by number and build ID. - GetStepForBuild(context.Context, *api.Build, int) (*library.Step, error) + GetStepForBuild(context.Context, *api.Build, int) (*api.Step, error) // ListSteps defines a function that gets a list of all steps. - ListSteps(ctx context.Context) ([]*library.Step, error) + ListSteps(ctx context.Context) ([]*api.Step, error) // ListStepsForBuild defines a function that gets a list of steps by build ID. - ListStepsForBuild(context.Context, *api.Build, map[string]interface{}, int, int) ([]*library.Step, int64, error) + ListStepsForBuild(context.Context, *api.Build, map[string]interface{}, int, int) ([]*api.Step, int64, error) // ListStepImageCount defines a function that gets a list of all step images and the count of their occurrence. ListStepImageCount(context.Context) (map[string]float64, error) // ListStepStatusCount defines a function that gets a list of all step statuses and the count of their occurrence. ListStepStatusCount(context.Context) (map[string]float64, error) // UpdateStep defines a function that updates an existing step. - UpdateStep(context.Context, *library.Step) (*library.Step, error) + UpdateStep(context.Context, *api.Step) (*api.Step, error) } diff --git a/database/step/list.go b/database/step/list.go index 9eb72996c..3904d9efa 100644 --- a/database/step/list.go +++ b/database/step/list.go @@ -5,19 +5,19 @@ package step import ( "context" - "github.com/go-vela/types/constants" - "github.com/go-vela/types/database" - "github.com/go-vela/types/library" + api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" + "github.com/go-vela/server/database/types" ) // ListSteps gets a list of all steps from the database. -func (e *engine) ListSteps(ctx context.Context) ([]*library.Step, error) { +func (e *engine) ListSteps(ctx context.Context) ([]*api.Step, error) { e.logger.Trace("listing all steps") // variables to store query results and return value count := int64(0) - w := new([]database.Step) - steps := []*library.Step{} + w := new([]types.Step) + steps := []*api.Step{} // count the results count, err := e.CountSteps(ctx) @@ -45,10 +45,7 @@ func (e *engine) ListSteps(ctx context.Context) ([]*library.Step, error) { // https://golang.org/doc/faq#closures_and_goroutines tmp := step - // convert query result to library type - // - // https://pkg.go.dev/github.com/go-vela/types/database#Step.ToLibrary - steps = append(steps, tmp.ToLibrary()) + steps = append(steps, tmp.ToAPI()) } return steps, nil diff --git a/database/step/list_build.go b/database/step/list_build.go index 1ba16fdb0..819156746 100644 --- a/database/step/list_build.go +++ b/database/step/list_build.go @@ -8,21 +8,20 @@ import ( "github.com/sirupsen/logrus" api "github.com/go-vela/server/api/types" - "github.com/go-vela/types/constants" - "github.com/go-vela/types/database" - "github.com/go-vela/types/library" + "github.com/go-vela/server/constants" + "github.com/go-vela/server/database/types" ) // ListStepsForBuild gets a list of all steps from the database. -func (e *engine) ListStepsForBuild(ctx context.Context, b *api.Build, filters map[string]interface{}, page int, perPage int) ([]*library.Step, int64, error) { +func (e *engine) ListStepsForBuild(ctx context.Context, b *api.Build, filters map[string]interface{}, page int, perPage int) ([]*api.Step, int64, error) { e.logger.WithFields(logrus.Fields{ "build": b.GetNumber(), }).Tracef("listing steps for build %d", b.GetNumber()) // variables to store query results and return value count := int64(0) - s := new([]database.Step) - steps := []*library.Step{} + s := new([]types.Step) + steps := []*api.Step{} // count the results count, err := e.CountStepsForBuild(ctx, b, filters) @@ -58,10 +57,7 @@ func (e *engine) ListStepsForBuild(ctx context.Context, b *api.Build, filters ma // https://golang.org/doc/faq#closures_and_goroutines tmp := step - // convert query result to library type - // - // https://pkg.go.dev/github.com/go-vela/types/database#Step.ToLibrary - steps = append(steps, tmp.ToLibrary()) + steps = append(steps, tmp.ToAPI()) } return steps, count, nil diff --git a/database/step/list_build_test.go b/database/step/list_build_test.go index 327076fec..4bb43b044 100644 --- a/database/step/list_build_test.go +++ b/database/step/list_build_test.go @@ -9,8 +9,8 @@ import ( "github.com/DATA-DOG/go-sqlmock" + api "github.com/go-vela/server/api/types" "github.com/go-vela/server/database/testutils" - "github.com/go-vela/types/library" ) func TestStep_Engine_ListStepsForBuild(t *testing.T) { @@ -75,19 +75,19 @@ func TestStep_Engine_ListStepsForBuild(t *testing.T) { failure bool name string database *engine - want []*library.Step + want []*api.Step }{ { failure: false, name: "postgres", database: _postgres, - want: []*library.Step{_stepTwo, _stepOne}, + want: []*api.Step{_stepTwo, _stepOne}, }, { failure: false, name: "sqlite3", database: _sqlite, - want: []*library.Step{_stepTwo, _stepOne}, + want: []*api.Step{_stepTwo, _stepOne}, }, } diff --git a/database/step/list_image.go b/database/step/list_image.go index c485ec741..3a1b5b9be 100644 --- a/database/step/list_image.go +++ b/database/step/list_image.go @@ -6,7 +6,7 @@ import ( "context" "database/sql" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) // ListStepImageCount gets a list of all step images and the count of their occurrence from the database. diff --git a/database/step/list_status.go b/database/step/list_status.go index 75c19a805..f11135e7f 100644 --- a/database/step/list_status.go +++ b/database/step/list_status.go @@ -6,7 +6,7 @@ import ( "context" "database/sql" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) // ListStepStatusCount gets a list of all step statuses and the count of their occurrence from the database. diff --git a/database/step/list_test.go b/database/step/list_test.go index 921a3f2f7..99819c59f 100644 --- a/database/step/list_test.go +++ b/database/step/list_test.go @@ -9,8 +9,8 @@ import ( "github.com/DATA-DOG/go-sqlmock" + api "github.com/go-vela/server/api/types" "github.com/go-vela/server/database/testutils" - "github.com/go-vela/types/library" ) func TestStep_Engine_ListSteps(t *testing.T) { @@ -69,19 +69,19 @@ func TestStep_Engine_ListSteps(t *testing.T) { failure bool name string database *engine - want []*library.Step + want []*api.Step }{ { failure: false, name: "postgres", database: _postgres, - want: []*library.Step{_stepOne, _stepTwo}, + want: []*api.Step{_stepOne, _stepTwo}, }, { failure: false, name: "sqlite3", database: _sqlite, - want: []*library.Step{_stepOne, _stepTwo}, + want: []*api.Step{_stepOne, _stepTwo}, }, } diff --git a/database/step/step.go b/database/step/step.go index edb3cb26e..a1465f778 100644 --- a/database/step/step.go +++ b/database/step/step.go @@ -9,7 +9,7 @@ import ( "github.com/sirupsen/logrus" "gorm.io/gorm" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) type ( diff --git a/database/step/table.go b/database/step/table.go index c7560326d..af7431c70 100644 --- a/database/step/table.go +++ b/database/step/table.go @@ -5,7 +5,7 @@ package step import ( "context" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) const ( diff --git a/database/step/update.go b/database/step/update.go index d467a2b65..524eea7f0 100644 --- a/database/step/update.go +++ b/database/step/update.go @@ -7,25 +7,19 @@ import ( "github.com/sirupsen/logrus" - "github.com/go-vela/types/constants" - "github.com/go-vela/types/database" - "github.com/go-vela/types/library" + api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" + "github.com/go-vela/server/database/types" ) // UpdateStep updates an existing step in the database. -func (e *engine) UpdateStep(ctx context.Context, s *library.Step) (*library.Step, error) { +func (e *engine) UpdateStep(ctx context.Context, s *api.Step) (*api.Step, error) { e.logger.WithFields(logrus.Fields{ "step": s.GetNumber(), }).Tracef("updating step %s in the database", s.GetName()) - // cast the library type to database type - // - // https://pkg.go.dev/github.com/go-vela/types/database#StepFromLibrary - step := database.StepFromLibrary(s) + step := types.StepFromAPI(s) - // validate the necessary fields are populated - // - // https://pkg.go.dev/github.com/go-vela/types/database#Step.Validate err := step.Validate() if err != nil { return nil, err @@ -37,5 +31,5 @@ func (e *engine) UpdateStep(ctx context.Context, s *library.Step) (*library.Step Table(constants.TableStep). Save(step) - return step.ToLibrary(), result.Error + return step.ToAPI(), result.Error } diff --git a/database/testutils/api_resources.go b/database/testutils/api_resources.go index 28c947fc6..bb6b451a3 100644 --- a/database/testutils/api_resources.go +++ b/database/testutils/api_resources.go @@ -210,8 +210,8 @@ func APISecret() *api.Secret { } } -func APIService() *library.Service { - return &library.Service{ +func APIService() *api.Service { + return &api.Service{ ID: new(int64), BuildID: new(int64), RepoID: new(int64), @@ -230,8 +230,8 @@ func APIService() *library.Service { } } -func APIStep() *library.Step { - return &library.Step{ +func APIStep() *api.Step { + return &api.Step{ ID: new(int64), BuildID: new(int64), RepoID: new(int64), diff --git a/database/types/deployment.go b/database/types/deployment.go index df300d6be..965c8dbc6 100644 --- a/database/types/deployment.go +++ b/database/types/deployment.go @@ -11,8 +11,8 @@ import ( api "github.com/go-vela/server/api/types" "github.com/go-vela/server/compiler/types/raw" + "github.com/go-vela/server/constants" "github.com/go-vela/server/util" - "github.com/go-vela/types/constants" ) var ( diff --git a/database/types/pipeline_test.go b/database/types/pipeline_test.go index 63648acdf..659e3fb9c 100644 --- a/database/types/pipeline_test.go +++ b/database/types/pipeline_test.go @@ -8,7 +8,7 @@ import ( "testing" api "github.com/go-vela/server/api/types" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) func TestDatabase_Pipeline_Compress(t *testing.T) { diff --git a/database/types/repo.go b/database/types/repo.go index 584d12923..e406c0c5c 100644 --- a/database/types/repo.go +++ b/database/types/repo.go @@ -10,8 +10,8 @@ import ( "github.com/lib/pq" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/util" - "github.com/go-vela/types/constants" ) var ( diff --git a/database/types/repo_test.go b/database/types/repo_test.go index d41ca7f8b..949985490 100644 --- a/database/types/repo_test.go +++ b/database/types/repo_test.go @@ -10,8 +10,8 @@ import ( "github.com/google/go-cmp/cmp" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/testutils" - "github.com/go-vela/types/constants" ) func TestTypes_Repo_Decrypt(t *testing.T) { diff --git a/database/types/schedule_test.go b/database/types/schedule_test.go index aa7ad21be..10b4da233 100644 --- a/database/types/schedule_test.go +++ b/database/types/schedule_test.go @@ -11,8 +11,8 @@ import ( "github.com/adhocore/gronx" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/testutils" - "github.com/go-vela/types/constants" ) func TestTypes_Schedule_Nullify(t *testing.T) { diff --git a/database/types/secret.go b/database/types/secret.go index 8a3a7d285..1d4dc130e 100644 --- a/database/types/secret.go +++ b/database/types/secret.go @@ -11,8 +11,8 @@ import ( "github.com/lib/pq" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/util" - "github.com/go-vela/types/constants" ) var ( diff --git a/database/types/service.go b/database/types/service.go new file mode 100644 index 000000000..f3b508ed6 --- /dev/null +++ b/database/types/service.go @@ -0,0 +1,231 @@ +// SPDX-License-Identifier: Apache-2.0 + +package types + +import ( + "database/sql" + "errors" + + api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/util" +) + +var ( + // ErrEmptyServiceBuildID defines the error type when a + // Service type has an empty BuildID field provided. + ErrEmptyServiceBuildID = errors.New("empty service build_id provided") + + // ErrEmptyServiceName defines the error type when a + // Service type has an empty Name field provided. + ErrEmptyServiceName = errors.New("empty service name provided") + + // ErrEmptyServiceImage defines the error type when a + // Service type has an empty Image field provided. + ErrEmptyServiceImage = errors.New("empty service image provided") + + // ErrEmptyServiceNumber defines the error type when a + // Service type has an empty Number field provided. + ErrEmptyServiceNumber = errors.New("empty service number provided") + + // ErrEmptyServiceRepoID defines the error type when a + // Service type has an empty RepoID field provided. + ErrEmptyServiceRepoID = errors.New("empty service repo_id provided") +) + +// Service is the database representation of a service in a build. +type Service struct { + ID sql.NullInt64 `sql:"id"` + BuildID sql.NullInt64 `sql:"build_id"` + RepoID sql.NullInt64 `sql:"repo_id"` + Number sql.NullInt32 `sql:"number"` + Name sql.NullString `sql:"name"` + Image sql.NullString `sql:"image"` + Status sql.NullString `sql:"status"` + Error sql.NullString `sql:"error"` + ExitCode sql.NullInt32 `sql:"exit_code"` + Created sql.NullInt64 `sql:"created"` + Started sql.NullInt64 `sql:"started"` + Finished sql.NullInt64 `sql:"finished"` + Host sql.NullString `sql:"host"` + Runtime sql.NullString `sql:"runtime"` + Distribution sql.NullString `sql:"distribution"` +} + +// Nullify ensures the valid flag for +// the sql.Null types are properly set. +// +// When a field within the Service type is the zero +// value for the field, the valid flag is set to +// false causing it to be NULL in the database. +func (s *Service) Nullify() *Service { + if s == nil { + return nil + } + + // check if the ID field should be false + if s.ID.Int64 == 0 { + s.ID.Valid = false + } + + // check if the BuildID field should be false + if s.BuildID.Int64 == 0 { + s.BuildID.Valid = false + } + + // check if the RepoID field should be false + if s.RepoID.Int64 == 0 { + s.RepoID.Valid = false + } + + // check if the Number field should be false + if s.Number.Int32 == 0 { + s.Number.Valid = false + } + + // check if the Name field should be false + if len(s.Name.String) == 0 { + s.Name.Valid = false + } + + // check if the Image field should be false + if len(s.Image.String) == 0 { + s.Image.Valid = false + } + + // check if the Status field should be false + if len(s.Status.String) == 0 { + s.Status.Valid = false + } + + // check if the Error field should be false + if len(s.Error.String) == 0 { + s.Error.Valid = false + } + + // check if the ExitCode field should be false + if s.ExitCode.Int32 == 0 { + s.ExitCode.Valid = false + } + + // check if Created field should be false + if s.Created.Int64 == 0 { + s.Created.Valid = false + } + + // check if Started field should be false + if s.Started.Int64 == 0 { + s.Started.Valid = false + } + + // check if Finished field should be false + if s.Finished.Int64 == 0 { + s.Finished.Valid = false + } + + // check if the Host field should be false + if len(s.Host.String) == 0 { + s.Host.Valid = false + } + + // check if the Runtime field should be false + if len(s.Runtime.String) == 0 { + s.Runtime.Valid = false + } + + // check if the Distribution field should be false + if len(s.Distribution.String) == 0 { + s.Distribution.Valid = false + } + + return s +} + +// ToAPI converts the Service type +// to a API Service type. +func (s *Service) ToAPI() *api.Service { + service := new(api.Service) + + service.SetID(s.ID.Int64) + service.SetBuildID(s.BuildID.Int64) + service.SetRepoID(s.RepoID.Int64) + service.SetNumber(int(s.Number.Int32)) + service.SetName(s.Name.String) + service.SetImage(s.Image.String) + service.SetStatus(s.Status.String) + service.SetError(s.Error.String) + service.SetExitCode(int(s.ExitCode.Int32)) + service.SetCreated(s.Created.Int64) + service.SetStarted(s.Started.Int64) + service.SetFinished(s.Finished.Int64) + service.SetHost(s.Host.String) + service.SetRuntime(s.Runtime.String) + service.SetDistribution(s.Distribution.String) + + return service +} + +// Validate verifies the necessary fields for +// the Service type are populated correctly. +func (s *Service) Validate() error { + // verify the BuildID field is populated + if s.BuildID.Int64 <= 0 { + return ErrEmptyServiceBuildID + } + + // verify the RepoID field is populated + if s.RepoID.Int64 <= 0 { + return ErrEmptyServiceRepoID + } + + // verify the Number field is populated + if s.Number.Int32 <= 0 { + return ErrEmptyServiceNumber + } + + // verify the Name field is populated + if len(s.Name.String) == 0 { + return ErrEmptyServiceName + } + + // verify the Image field is populated + if len(s.Image.String) == 0 { + return ErrEmptyServiceImage + } + + // ensure that all Service string fields + // that can be returned as JSON are sanitized + // to avoid unsafe HTML content + s.Name = sql.NullString{String: util.Sanitize(s.Name.String), Valid: s.Name.Valid} + s.Image = sql.NullString{String: util.Sanitize(s.Image.String), Valid: s.Image.Valid} + s.Status = sql.NullString{String: util.Sanitize(s.Status.String), Valid: s.Status.Valid} + s.Error = sql.NullString{String: util.Sanitize(s.Error.String), Valid: s.Error.Valid} + s.Host = sql.NullString{String: util.Sanitize(s.Host.String), Valid: s.Host.Valid} + s.Runtime = sql.NullString{String: util.Sanitize(s.Runtime.String), Valid: s.Runtime.Valid} + s.Distribution = sql.NullString{String: util.Sanitize(s.Distribution.String), Valid: s.Distribution.Valid} + + return nil +} + +// ServiceFromAPI converts the API Service type +// to a database Service type. +func ServiceFromAPI(s *api.Service) *Service { + service := &Service{ + ID: sql.NullInt64{Int64: s.GetID(), Valid: true}, + BuildID: sql.NullInt64{Int64: s.GetBuildID(), Valid: true}, + RepoID: sql.NullInt64{Int64: s.GetRepoID(), Valid: true}, + Number: sql.NullInt32{Int32: int32(s.GetNumber()), Valid: true}, + Name: sql.NullString{String: s.GetName(), Valid: true}, + Image: sql.NullString{String: s.GetImage(), Valid: true}, + Status: sql.NullString{String: s.GetStatus(), Valid: true}, + Error: sql.NullString{String: s.GetError(), Valid: true}, + ExitCode: sql.NullInt32{Int32: int32(s.GetExitCode()), Valid: true}, + Created: sql.NullInt64{Int64: s.GetCreated(), Valid: true}, + Started: sql.NullInt64{Int64: s.GetStarted(), Valid: true}, + Finished: sql.NullInt64{Int64: s.GetFinished(), Valid: true}, + Host: sql.NullString{String: s.GetHost(), Valid: true}, + Runtime: sql.NullString{String: s.GetRuntime(), Valid: true}, + Distribution: sql.NullString{String: s.GetDistribution(), Valid: true}, + } + + return service.Nullify() +} diff --git a/database/types/service_test.go b/database/types/service_test.go new file mode 100644 index 000000000..ce39d90db --- /dev/null +++ b/database/types/service_test.go @@ -0,0 +1,221 @@ +// SPDX-License-Identifier: Apache-2.0 + +package types + +import ( + "database/sql" + "reflect" + "testing" + + api "github.com/go-vela/server/api/types" +) + +func TestDatabase_Service_Nullify(t *testing.T) { + // setup types + var s *Service + + want := &Service{ + ID: sql.NullInt64{Int64: 0, Valid: false}, + BuildID: sql.NullInt64{Int64: 0, Valid: false}, + RepoID: sql.NullInt64{Int64: 0, Valid: false}, + Number: sql.NullInt32{Int32: 0, Valid: false}, + Name: sql.NullString{String: "", Valid: false}, + Image: sql.NullString{String: "", Valid: false}, + Status: sql.NullString{String: "", Valid: false}, + Error: sql.NullString{String: "", Valid: false}, + ExitCode: sql.NullInt32{Int32: 0, Valid: false}, + Created: sql.NullInt64{Int64: 0, Valid: false}, + Started: sql.NullInt64{Int64: 0, Valid: false}, + Finished: sql.NullInt64{Int64: 0, Valid: false}, + Host: sql.NullString{String: "", Valid: false}, + Runtime: sql.NullString{String: "", Valid: false}, + Distribution: sql.NullString{String: "", Valid: false}, + } + + // setup tests + tests := []struct { + service *Service + want *Service + }{ + { + service: testService(), + want: testService(), + }, + { + service: s, + want: nil, + }, + { + service: new(Service), + want: want, + }, + } + + // run tests + for _, test := range tests { + got := test.service.Nullify() + + if !reflect.DeepEqual(got, test.want) { + t.Errorf("Nullify is %v, want %v", got, test.want) + } + } +} + +func TestDatabase_Service_ToAPI(t *testing.T) { + // setup types + want := new(api.Service) + + want.SetID(1) + want.SetBuildID(1) + want.SetRepoID(1) + want.SetNumber(1) + want.SetName("postgres") + want.SetImage("postgres:12-alpine") + want.SetStatus("running") + want.SetError("") + want.SetExitCode(0) + want.SetCreated(1563474076) + want.SetStarted(1563474078) + want.SetFinished(1563474079) + want.SetHost("example.company.com") + want.SetRuntime("docker") + want.SetDistribution("linux") + + // run test + got := testService().ToAPI() + + if !reflect.DeepEqual(got, want) { + t.Errorf("ToAPI is %v, want %v", got, want) + } +} + +func TestDatabase_Service_Validate(t *testing.T) { + tests := []struct { + failure bool + service *Service + }{ + { + failure: false, + service: testService(), + }, + { // no build_id set for service + failure: true, + service: &Service{ + ID: sql.NullInt64{Int64: 1, Valid: true}, + RepoID: sql.NullInt64{Int64: 1, Valid: true}, + Number: sql.NullInt32{Int32: 1, Valid: true}, + Name: sql.NullString{String: "postgres", Valid: true}, + Image: sql.NullString{String: "postgres:12-alpine", Valid: true}, + }, + }, + { // no repo_id set for service + failure: true, + service: &Service{ + ID: sql.NullInt64{Int64: 1, Valid: true}, + BuildID: sql.NullInt64{Int64: 1, Valid: true}, + Number: sql.NullInt32{Int32: 1, Valid: true}, + Name: sql.NullString{String: "postgres", Valid: true}, + Image: sql.NullString{String: "postgres:12-alpine", Valid: true}, + }, + }, + { // no number set for service + failure: true, + service: &Service{ + ID: sql.NullInt64{Int64: 1, Valid: true}, + BuildID: sql.NullInt64{Int64: 1, Valid: true}, + RepoID: sql.NullInt64{Int64: 1, Valid: true}, + Name: sql.NullString{String: "postgres", Valid: true}, + Image: sql.NullString{String: "postgres:12-alpine", Valid: true}, + }, + }, + { // no name set for service + failure: true, + service: &Service{ + ID: sql.NullInt64{Int64: 1, Valid: true}, + BuildID: sql.NullInt64{Int64: 1, Valid: true}, + RepoID: sql.NullInt64{Int64: 1, Valid: true}, + Number: sql.NullInt32{Int32: 1, Valid: true}, + Image: sql.NullString{String: "postgres:12-alpine", Valid: true}, + }, + }, + { // no image set for service + failure: true, + service: &Service{ + ID: sql.NullInt64{Int64: 1, Valid: true}, + BuildID: sql.NullInt64{Int64: 1, Valid: true}, + RepoID: sql.NullInt64{Int64: 1, Valid: true}, + Number: sql.NullInt32{Int32: 1, Valid: true}, + Name: sql.NullString{String: "postgres", Valid: true}, + }, + }, + } + + // run tests + for _, test := range tests { + err := test.service.Validate() + + if test.failure { + if err == nil { + t.Errorf("Validate should have returned err") + } + + continue + } + + if err != nil { + t.Errorf("Validate returned err: %v", err) + } + } +} + +func TestDatabase_ServiceFromAPI(t *testing.T) { + // setup types + s := new(api.Service) + + s.SetID(1) + s.SetBuildID(1) + s.SetRepoID(1) + s.SetNumber(1) + s.SetName("postgres") + s.SetImage("postgres:12-alpine") + s.SetStatus("running") + s.SetError("") + s.SetExitCode(0) + s.SetCreated(1563474076) + s.SetStarted(1563474078) + s.SetFinished(1563474079) + s.SetHost("example.company.com") + s.SetRuntime("docker") + s.SetDistribution("linux") + + want := testService() + + // run test + got := ServiceFromAPI(s) + + if !reflect.DeepEqual(got, want) { + t.Errorf("ServiceFromAPI is %v, want %v", got, want) + } +} + +// testService is a test helper function to create a Service +// type with all fields set to a fake value. +func testService() *Service { + return &Service{ + ID: sql.NullInt64{Int64: 1, Valid: true}, + BuildID: sql.NullInt64{Int64: 1, Valid: true}, + RepoID: sql.NullInt64{Int64: 1, Valid: true}, + Number: sql.NullInt32{Int32: 1, Valid: true}, + Name: sql.NullString{String: "postgres", Valid: true}, + Image: sql.NullString{String: "postgres:12-alpine", Valid: true}, + Status: sql.NullString{String: "running", Valid: true}, + Error: sql.NullString{String: "", Valid: false}, + ExitCode: sql.NullInt32{Int32: 0, Valid: false}, + Created: sql.NullInt64{Int64: 1563474076, Valid: true}, + Started: sql.NullInt64{Int64: 1563474078, Valid: true}, + Finished: sql.NullInt64{Int64: 1563474079, Valid: true}, + Host: sql.NullString{String: "example.company.com", Valid: true}, + Runtime: sql.NullString{String: "docker", Valid: true}, + Distribution: sql.NullString{String: "linux", Valid: true}, + } +} diff --git a/database/types/step.go b/database/types/step.go new file mode 100644 index 000000000..4bd09c0b5 --- /dev/null +++ b/database/types/step.go @@ -0,0 +1,249 @@ +// SPDX-License-Identifier: Apache-2.0 + +package types + +import ( + "database/sql" + "errors" + + api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/util" +) + +var ( + // ErrEmptyStepBuildID defines the error type when a + // Step type has an empty BuildID field provided. + ErrEmptyStepBuildID = errors.New("empty step build_id provided") + + // ErrEmptyStepName defines the error type when a + // Step type has an empty Name field provided. + ErrEmptyStepName = errors.New("empty step name provided") + + // ErrEmptyStepImage defines the error type when a + // Step type has an empty Image field provided. + ErrEmptyStepImage = errors.New("empty step image provided") + + // ErrEmptyStepNumber defines the error type when a + // Step type has an empty Number field provided. + ErrEmptyStepNumber = errors.New("empty step number provided") + + // ErrEmptyStepRepoID defines the error type when a + // Step type has an empty RepoID field provided. + ErrEmptyStepRepoID = errors.New("empty step repo_id provided") +) + +// Step is the database representation of a step in a build. +type Step struct { + ID sql.NullInt64 `sql:"id"` + BuildID sql.NullInt64 `sql:"build_id"` + RepoID sql.NullInt64 `sql:"repo_id"` + Number sql.NullInt32 `sql:"number"` + Name sql.NullString `sql:"name"` + Image sql.NullString `sql:"image"` + Stage sql.NullString `sql:"stage"` + Status sql.NullString `sql:"status"` + Error sql.NullString `sql:"error"` + ExitCode sql.NullInt32 `sql:"exit_code"` + Created sql.NullInt64 `sql:"created"` + Started sql.NullInt64 `sql:"started"` + Finished sql.NullInt64 `sql:"finished"` + Host sql.NullString `sql:"host"` + Runtime sql.NullString `sql:"runtime"` + Distribution sql.NullString `sql:"distribution"` + ReportAs sql.NullString `sql:"report_as"` +} + +// Nullify ensures the valid flag for +// the sql.Null types are properly set. +// +// When a field within the Step type is the zero +// value for the field, the valid flag is set to +// false causing it to be NULL in the database. +func (s *Step) Nullify() *Step { + if s == nil { + return nil + } + + // check if the ID field should be false + if s.ID.Int64 == 0 { + s.ID.Valid = false + } + + // check if the BuildID field should be false + if s.BuildID.Int64 == 0 { + s.BuildID.Valid = false + } + + // check if the RepoID field should be false + if s.RepoID.Int64 == 0 { + s.RepoID.Valid = false + } + + // check if the Number field should be false + if s.Number.Int32 == 0 { + s.Number.Valid = false + } + + // check if the Name field should be false + if len(s.Name.String) == 0 { + s.Name.Valid = false + } + + // check if the Image field should be false + if len(s.Image.String) == 0 { + s.Image.Valid = false + } + + // check if the Stage field should be false + if len(s.Stage.String) == 0 { + s.Stage.Valid = false + } + + // check if the Status field should be false + if len(s.Status.String) == 0 { + s.Status.Valid = false + } + + // check if the Error field should be false + if len(s.Error.String) == 0 { + s.Error.Valid = false + } + + // check if the ExitCode field should be false + if s.ExitCode.Int32 == 0 { + s.ExitCode.Valid = false + } + + // check if Created field should be false + if s.Created.Int64 == 0 { + s.Created.Valid = false + } + + // check if Started field should be false + if s.Started.Int64 == 0 { + s.Started.Valid = false + } + + // check if Finished field should be false + if s.Finished.Int64 == 0 { + s.Finished.Valid = false + } + + // check if the Host field should be false + if len(s.Host.String) == 0 { + s.Host.Valid = false + } + + // check if the Runtime field should be false + if len(s.Runtime.String) == 0 { + s.Runtime.Valid = false + } + + // check if the Distribution field should be false + if len(s.Distribution.String) == 0 { + s.Distribution.Valid = false + } + + // check if the ReportAs field should be false + if len(s.ReportAs.String) == 0 { + s.ReportAs.Valid = false + } + + return s +} + +// ToAPI converts the Step type +// to a API Step type. +func (s *Step) ToAPI() *api.Step { + step := new(api.Step) + + step.SetID(s.ID.Int64) + step.SetBuildID(s.BuildID.Int64) + step.SetRepoID(s.RepoID.Int64) + step.SetNumber(int(s.Number.Int32)) + step.SetName(s.Name.String) + step.SetImage(s.Image.String) + step.SetStage(s.Stage.String) + step.SetStatus(s.Status.String) + step.SetError(s.Error.String) + step.SetExitCode(int(s.ExitCode.Int32)) + step.SetCreated(s.Created.Int64) + step.SetStarted(s.Started.Int64) + step.SetFinished(s.Finished.Int64) + step.SetHost(s.Host.String) + step.SetRuntime(s.Runtime.String) + step.SetDistribution(s.Distribution.String) + step.SetReportAs(s.ReportAs.String) + + return step +} + +// Validate verifies the necessary fields for +// the Step type are populated correctly. +func (s *Step) Validate() error { + // verify the BuildID field is populated + if s.BuildID.Int64 <= 0 { + return ErrEmptyStepBuildID + } + + // verify the RepoID field is populated + if s.RepoID.Int64 <= 0 { + return ErrEmptyStepRepoID + } + + // verify the Number field is populated + if s.Number.Int32 <= 0 { + return ErrEmptyStepNumber + } + + // verify the Name field is populated + if len(s.Name.String) == 0 { + return ErrEmptyStepName + } + + // verify the Image field is populated + if len(s.Image.String) == 0 { + return ErrEmptyStepImage + } + + // ensure that all Step string fields + // that can be returned as JSON are sanitized + // to avoid unsafe HTML content + s.Name = sql.NullString{String: util.Sanitize(s.Name.String), Valid: s.Name.Valid} + s.Image = sql.NullString{String: util.Sanitize(s.Image.String), Valid: s.Image.Valid} + s.Stage = sql.NullString{String: util.Sanitize(s.Stage.String), Valid: s.Stage.Valid} + s.Status = sql.NullString{String: util.Sanitize(s.Status.String), Valid: s.Status.Valid} + s.Error = sql.NullString{String: util.Sanitize(s.Error.String), Valid: s.Error.Valid} + s.Host = sql.NullString{String: util.Sanitize(s.Host.String), Valid: s.Host.Valid} + s.Runtime = sql.NullString{String: util.Sanitize(s.Runtime.String), Valid: s.Runtime.Valid} + s.Distribution = sql.NullString{String: util.Sanitize(s.Distribution.String), Valid: s.Distribution.Valid} + s.ReportAs = sql.NullString{String: util.Sanitize(s.ReportAs.String), Valid: s.ReportAs.Valid} + + return nil +} + +// StepFromAPI converts the API Step type +// to a database Step type. +func StepFromAPI(s *api.Step) *Step { + step := &Step{ + ID: sql.NullInt64{Int64: s.GetID(), Valid: true}, + BuildID: sql.NullInt64{Int64: s.GetBuildID(), Valid: true}, + RepoID: sql.NullInt64{Int64: s.GetRepoID(), Valid: true}, + Number: sql.NullInt32{Int32: int32(s.GetNumber()), Valid: true}, + Name: sql.NullString{String: s.GetName(), Valid: true}, + Image: sql.NullString{String: s.GetImage(), Valid: true}, + Stage: sql.NullString{String: s.GetStage(), Valid: true}, + Status: sql.NullString{String: s.GetStatus(), Valid: true}, + Error: sql.NullString{String: s.GetError(), Valid: true}, + ExitCode: sql.NullInt32{Int32: int32(s.GetExitCode()), Valid: true}, + Created: sql.NullInt64{Int64: s.GetCreated(), Valid: true}, + Started: sql.NullInt64{Int64: s.GetStarted(), Valid: true}, + Finished: sql.NullInt64{Int64: s.GetFinished(), Valid: true}, + Host: sql.NullString{String: s.GetHost(), Valid: true}, + Runtime: sql.NullString{String: s.GetRuntime(), Valid: true}, + Distribution: sql.NullString{String: s.GetDistribution(), Valid: true}, + ReportAs: sql.NullString{String: s.GetReportAs(), Valid: true}, + } + + return step.Nullify() +} diff --git a/database/types/step_test.go b/database/types/step_test.go new file mode 100644 index 000000000..6d6aa2829 --- /dev/null +++ b/database/types/step_test.go @@ -0,0 +1,230 @@ +// SPDX-License-Identifier: Apache-2.0 + +package types + +import ( + "database/sql" + "reflect" + "testing" + + api "github.com/go-vela/server/api/types" +) + +func TestDatabase_Step_Nullify(t *testing.T) { + // setup types + var s *Step + + want := &Step{ + ID: sql.NullInt64{Int64: 0, Valid: false}, + BuildID: sql.NullInt64{Int64: 0, Valid: false}, + RepoID: sql.NullInt64{Int64: 0, Valid: false}, + Number: sql.NullInt32{Int32: 0, Valid: false}, + Name: sql.NullString{String: "", Valid: false}, + Image: sql.NullString{String: "", Valid: false}, + Stage: sql.NullString{String: "", Valid: false}, + Status: sql.NullString{String: "", Valid: false}, + Error: sql.NullString{String: "", Valid: false}, + ExitCode: sql.NullInt32{Int32: 0, Valid: false}, + Created: sql.NullInt64{Int64: 0, Valid: false}, + Started: sql.NullInt64{Int64: 0, Valid: false}, + Finished: sql.NullInt64{Int64: 0, Valid: false}, + Host: sql.NullString{String: "", Valid: false}, + Runtime: sql.NullString{String: "", Valid: false}, + Distribution: sql.NullString{String: "", Valid: false}, + ReportAs: sql.NullString{String: "", Valid: false}, + } + + // setup tests + tests := []struct { + step *Step + want *Step + }{ + { + step: testStep(), + want: testStep(), + }, + { + step: s, + want: nil, + }, + { + step: new(Step), + want: want, + }, + } + + // run tests + for _, test := range tests { + got := test.step.Nullify() + + if !reflect.DeepEqual(got, test.want) { + t.Errorf("Nullify is %v, want %v", got, test.want) + } + } +} + +func TestDatabase_Step_ToAPI(t *testing.T) { + // setup types + want := new(api.Step) + + want.SetID(1) + want.SetBuildID(1) + want.SetRepoID(1) + want.SetNumber(1) + want.SetName("clone") + want.SetImage("target/vela-git:v0.3.0") + want.SetStage("") + want.SetStatus("running") + want.SetError("") + want.SetExitCode(0) + want.SetCreated(1563474076) + want.SetStarted(1563474078) + want.SetFinished(1563474079) + want.SetHost("example.company.com") + want.SetRuntime("docker") + want.SetDistribution("linux") + want.SetReportAs("test") + + // run test + got := testStep().ToAPI() + + if !reflect.DeepEqual(got, want) { + t.Errorf("ToLibrary is %v, want %v", got, want) + } +} + +func TestDatabase_Step_Validate(t *testing.T) { + // setup types + tests := []struct { + failure bool + step *Step + }{ + { + failure: false, + step: testStep(), + }, + { // no build_id set for step + failure: true, + step: &Step{ + ID: sql.NullInt64{Int64: 1, Valid: true}, + RepoID: sql.NullInt64{Int64: 1, Valid: true}, + Number: sql.NullInt32{Int32: 1, Valid: true}, + Name: sql.NullString{String: "clone", Valid: true}, + Image: sql.NullString{String: "target/vela-git:v0.3.0", Valid: true}, + }, + }, + { // no repo_id set for step + failure: true, + step: &Step{ + ID: sql.NullInt64{Int64: 1, Valid: true}, + BuildID: sql.NullInt64{Int64: 1, Valid: true}, + Number: sql.NullInt32{Int32: 1, Valid: true}, + Name: sql.NullString{String: "clone", Valid: true}, + Image: sql.NullString{String: "target/vela-git:v0.3.0", Valid: true}, + }, + }, + { // no name set for step + failure: true, + step: &Step{ + ID: sql.NullInt64{Int64: 1, Valid: true}, + BuildID: sql.NullInt64{Int64: 1, Valid: true}, + RepoID: sql.NullInt64{Int64: 1, Valid: true}, + Number: sql.NullInt32{Int32: 1, Valid: true}, + Image: sql.NullString{String: "target/vela-git:v0.3.0", Valid: true}, + }, + }, + { // no number set for step + failure: true, + step: &Step{ + ID: sql.NullInt64{Int64: 1, Valid: true}, + BuildID: sql.NullInt64{Int64: 1, Valid: true}, + RepoID: sql.NullInt64{Int64: 1, Valid: true}, + Name: sql.NullString{String: "clone", Valid: true}, + Image: sql.NullString{String: "target/vela-git:v0.3.0", Valid: true}, + }, + }, + { // no image set for step + failure: true, + step: &Step{ + ID: sql.NullInt64{Int64: 1, Valid: true}, + BuildID: sql.NullInt64{Int64: 1, Valid: true}, + RepoID: sql.NullInt64{Int64: 1, Valid: true}, + Number: sql.NullInt32{Int32: 1, Valid: true}, + Name: sql.NullString{String: "clone", Valid: true}, + }, + }, + } + + // run tests + for _, test := range tests { + err := test.step.Validate() + + if test.failure { + if err == nil { + t.Errorf("Validate should have returned err") + } + + continue + } + + if err != nil { + t.Errorf("Validate returned err: %v", err) + } + } +} + +func TestDatabase_StepFromAPI(t *testing.T) { + // setup types + s := new(api.Step) + + s.SetID(1) + s.SetBuildID(1) + s.SetRepoID(1) + s.SetNumber(1) + s.SetName("clone") + s.SetImage("target/vela-git:v0.3.0") + s.SetStage("") + s.SetStatus("running") + s.SetError("") + s.SetExitCode(0) + s.SetCreated(1563474076) + s.SetStarted(1563474078) + s.SetFinished(1563474079) + s.SetHost("example.company.com") + s.SetRuntime("docker") + s.SetDistribution("linux") + s.SetReportAs("test") + + want := testStep() + + // run test + got := StepFromAPI(s) + + if !reflect.DeepEqual(got, want) { + t.Errorf("StepFromLibrary is %v, want %v", got, want) + } +} + +// testStep is a test helper function to create a Step +// type with all fields set to a fake value. +func testStep() *Step { + return &Step{ + ID: sql.NullInt64{Int64: 1, Valid: true}, + BuildID: sql.NullInt64{Int64: 1, Valid: true}, + RepoID: sql.NullInt64{Int64: 1, Valid: true}, + Number: sql.NullInt32{Int32: 1, Valid: true}, + Name: sql.NullString{String: "clone", Valid: true}, + Image: sql.NullString{String: "target/vela-git:v0.3.0", Valid: true}, + Stage: sql.NullString{String: "", Valid: false}, + Status: sql.NullString{String: "running", Valid: true}, + Error: sql.NullString{String: "", Valid: false}, + ExitCode: sql.NullInt32{Int32: 0, Valid: false}, + Created: sql.NullInt64{Int64: 1563474076, Valid: true}, + Started: sql.NullInt64{Int64: 1563474078, Valid: true}, + Finished: sql.NullInt64{Int64: 1563474079, Valid: true}, + Host: sql.NullString{String: "example.company.com", Valid: true}, + Runtime: sql.NullString{String: "docker", Valid: true}, + Distribution: sql.NullString{String: "linux", Valid: true}, + ReportAs: sql.NullString{String: "test", Valid: true}, + } +} diff --git a/database/types/worker.go b/database/types/worker.go index 16062e65b..7dfe1ffab 100644 --- a/database/types/worker.go +++ b/database/types/worker.go @@ -10,8 +10,8 @@ import ( "github.com/lib/pq" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/util" - "github.com/go-vela/types/constants" ) var ( diff --git a/database/user/count.go b/database/user/count.go index b6b686fba..e8564bef8 100644 --- a/database/user/count.go +++ b/database/user/count.go @@ -5,7 +5,7 @@ package user import ( "context" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) // CountUsers gets the count of all users from the database. diff --git a/database/user/create.go b/database/user/create.go index c778349c4..efa73e0ce 100644 --- a/database/user/create.go +++ b/database/user/create.go @@ -10,8 +10,8 @@ import ( "github.com/sirupsen/logrus" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/types" - "github.com/go-vela/types/constants" ) // CreateUser creates a new user in the database. diff --git a/database/user/delete.go b/database/user/delete.go index 28547c07c..d42d804ad 100644 --- a/database/user/delete.go +++ b/database/user/delete.go @@ -8,8 +8,8 @@ import ( "github.com/sirupsen/logrus" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/types" - "github.com/go-vela/types/constants" ) // DeleteUser deletes an existing user from the database. diff --git a/database/user/get.go b/database/user/get.go index 30901c2ff..2a89f7836 100644 --- a/database/user/get.go +++ b/database/user/get.go @@ -6,8 +6,8 @@ import ( "context" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/types" - "github.com/go-vela/types/constants" ) // GetUser gets a user by ID from the database. diff --git a/database/user/get_name.go b/database/user/get_name.go index fb9a90090..ee472a8d0 100644 --- a/database/user/get_name.go +++ b/database/user/get_name.go @@ -8,8 +8,8 @@ import ( "github.com/sirupsen/logrus" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/types" - "github.com/go-vela/types/constants" ) // GetUserForName gets a user by name from the database. diff --git a/database/user/list.go b/database/user/list.go index 035699489..ae2858686 100644 --- a/database/user/list.go +++ b/database/user/list.go @@ -6,8 +6,8 @@ import ( "context" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/types" - "github.com/go-vela/types/constants" ) // ListUsers gets a list of all users from the database. diff --git a/database/user/list_lite.go b/database/user/list_lite.go index c961fe483..f1719e0d5 100644 --- a/database/user/list_lite.go +++ b/database/user/list_lite.go @@ -6,8 +6,8 @@ import ( "context" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/types" - "github.com/go-vela/types/constants" ) // ListLiteUsers gets a lite (only: id, name) list of users from the database. diff --git a/database/user/table.go b/database/user/table.go index de1f964a7..b39a04060 100644 --- a/database/user/table.go +++ b/database/user/table.go @@ -5,7 +5,7 @@ package user import ( "context" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) const ( diff --git a/database/user/update.go b/database/user/update.go index d860e3293..4a68ebaca 100644 --- a/database/user/update.go +++ b/database/user/update.go @@ -10,8 +10,8 @@ import ( "github.com/sirupsen/logrus" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/types" - "github.com/go-vela/types/constants" ) // UpdateUser updates an existing user in the database. diff --git a/database/user/user.go b/database/user/user.go index ad2e2bae5..552571525 100644 --- a/database/user/user.go +++ b/database/user/user.go @@ -9,7 +9,7 @@ import ( "github.com/sirupsen/logrus" "gorm.io/gorm" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) type ( diff --git a/database/validate.go b/database/validate.go index 8025b325e..c7628f9a5 100644 --- a/database/validate.go +++ b/database/validate.go @@ -8,7 +8,7 @@ import ( "github.com/sirupsen/logrus" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) // Validate verifies the required fields from the provided configuration are populated correctly. diff --git a/database/worker/count.go b/database/worker/count.go index 6c440637c..2fac5cafc 100644 --- a/database/worker/count.go +++ b/database/worker/count.go @@ -5,7 +5,7 @@ package worker import ( "context" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) // CountWorkers gets the count of all workers from the database. diff --git a/database/worker/create.go b/database/worker/create.go index 180ee7ef6..658b69bf0 100644 --- a/database/worker/create.go +++ b/database/worker/create.go @@ -8,8 +8,8 @@ import ( "github.com/sirupsen/logrus" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/types" - "github.com/go-vela/types/constants" ) // CreateWorker creates a new worker in the database. diff --git a/database/worker/delete.go b/database/worker/delete.go index 252dd7831..5dac85391 100644 --- a/database/worker/delete.go +++ b/database/worker/delete.go @@ -8,8 +8,8 @@ import ( "github.com/sirupsen/logrus" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/types" - "github.com/go-vela/types/constants" ) // DeleteWorker deletes an existing worker from the database. diff --git a/database/worker/get.go b/database/worker/get.go index 47be938a1..e4c2f14f3 100644 --- a/database/worker/get.go +++ b/database/worker/get.go @@ -6,8 +6,8 @@ import ( "context" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/types" - "github.com/go-vela/types/constants" ) // GetWorker gets a worker by ID from the database. diff --git a/database/worker/get_hostname.go b/database/worker/get_hostname.go index d1150f80d..39ee2871e 100644 --- a/database/worker/get_hostname.go +++ b/database/worker/get_hostname.go @@ -8,8 +8,8 @@ import ( "github.com/sirupsen/logrus" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/types" - "github.com/go-vela/types/constants" ) // GetWorkerForHostname gets a worker by hostname from the database. diff --git a/database/worker/list.go b/database/worker/list.go index 34fc2ef79..0843abc2d 100644 --- a/database/worker/list.go +++ b/database/worker/list.go @@ -8,8 +8,8 @@ import ( "strconv" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/types" - "github.com/go-vela/types/constants" ) // ListWorkers gets a list of all workers from the database. diff --git a/database/worker/table.go b/database/worker/table.go index 921734f38..a1d871147 100644 --- a/database/worker/table.go +++ b/database/worker/table.go @@ -5,7 +5,7 @@ package worker import ( "context" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) const ( diff --git a/database/worker/update.go b/database/worker/update.go index 49c78e420..10449cba5 100644 --- a/database/worker/update.go +++ b/database/worker/update.go @@ -8,8 +8,8 @@ import ( "github.com/sirupsen/logrus" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database/types" - "github.com/go-vela/types/constants" ) // UpdateWorker updates an existing worker in the database. diff --git a/database/worker/worker.go b/database/worker/worker.go index 655a7dd2f..9869d4cd6 100644 --- a/database/worker/worker.go +++ b/database/worker/worker.go @@ -11,7 +11,7 @@ import ( "gorm.io/gorm" api "github.com/go-vela/server/api/types" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) type ( diff --git a/internal/token/compose.go b/internal/token/compose.go index 8fa0a1c8b..0bd685c11 100644 --- a/internal/token/compose.go +++ b/internal/token/compose.go @@ -9,8 +9,8 @@ import ( "github.com/gin-gonic/gin" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/internal" - "github.com/go-vela/types/constants" ) // Compose generates a refresh and access token pair unique diff --git a/internal/token/compose_test.go b/internal/token/compose_test.go index c6efd58ce..f87952ab3 100644 --- a/internal/token/compose_test.go +++ b/internal/token/compose_test.go @@ -12,8 +12,8 @@ import ( "github.com/golang-jwt/jwt/v5" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/internal" - "github.com/go-vela/types/constants" ) func TestToken_Compose(t *testing.T) { diff --git a/internal/token/parse_test.go b/internal/token/parse_test.go index 600efe35e..0019aba6a 100644 --- a/internal/token/parse_test.go +++ b/internal/token/parse_test.go @@ -11,7 +11,7 @@ import ( jwt "github.com/golang-jwt/jwt/v5" api "github.com/go-vela/server/api/types" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) func TestTokenManager_ParseToken(t *testing.T) { diff --git a/internal/token/refresh.go b/internal/token/refresh.go index 257391230..f95d1b9c5 100644 --- a/internal/token/refresh.go +++ b/internal/token/refresh.go @@ -7,8 +7,8 @@ import ( "github.com/gin-gonic/gin" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database" - "github.com/go-vela/types/constants" ) // Refresh returns a new access token, if the provided refreshToken is valid. diff --git a/internal/token/refresh_test.go b/internal/token/refresh_test.go index 49c809eb6..2478146e7 100644 --- a/internal/token/refresh_test.go +++ b/internal/token/refresh_test.go @@ -12,8 +12,8 @@ import ( "github.com/gin-gonic/gin" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database" - "github.com/go-vela/types/constants" ) func TestTokenManager_Refresh(t *testing.T) { diff --git a/internal/webhook.go b/internal/webhook.go index 3c6889a59..7edb365c2 100644 --- a/internal/webhook.go +++ b/internal/webhook.go @@ -6,7 +6,7 @@ import ( "strings" api "github.com/go-vela/server/api/types" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) var ( diff --git a/internal/webhook_test.go b/internal/webhook_test.go index 4e421854c..e374980d6 100644 --- a/internal/webhook_test.go +++ b/internal/webhook_test.go @@ -6,7 +6,7 @@ import ( "testing" api "github.com/go-vela/server/api/types" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) func TestWebhook_ShouldSkip(t *testing.T) { diff --git a/mock/server/authentication.go b/mock/server/authentication.go index 1d8ed2147..3b4c2b97c 100644 --- a/mock/server/authentication.go +++ b/mock/server/authentication.go @@ -10,8 +10,8 @@ import ( "github.com/lestrrat-go/jwx/v2/jwk" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/types" - "github.com/go-vela/types/constants" "github.com/go-vela/types/library" ) diff --git a/mock/server/service.go b/mock/server/service.go index c42e97dd6..75448a966 100644 --- a/mock/server/service.go +++ b/mock/server/service.go @@ -11,8 +11,8 @@ import ( "github.com/gin-gonic/gin" + api "github.com/go-vela/server/api/types" "github.com/go-vela/types" - "github.com/go-vela/types/library" ) const ( @@ -70,7 +70,7 @@ const ( func getServices(c *gin.Context) { data := []byte(ServicesResp) - var body []library.Service + var body []api.Service _ = json.Unmarshal(data, &body) c.JSON(http.StatusOK, body) @@ -92,7 +92,7 @@ func getService(c *gin.Context) { data := []byte(ServiceResp) - var body library.Service + var body api.Service _ = json.Unmarshal(data, &body) c.JSON(http.StatusOK, body) @@ -102,7 +102,7 @@ func getService(c *gin.Context) { func addService(c *gin.Context) { data := []byte(ServiceResp) - var body library.Service + var body api.Service _ = json.Unmarshal(data, &body) c.JSON(http.StatusCreated, body) @@ -126,7 +126,7 @@ func updateService(c *gin.Context) { data := []byte(ServiceResp) - var body library.Service + var body api.Service _ = json.Unmarshal(data, &body) c.JSON(http.StatusOK, body) diff --git a/mock/server/service_test.go b/mock/server/service_test.go index 799dc64d6..70e1da0af 100644 --- a/mock/server/service_test.go +++ b/mock/server/service_test.go @@ -7,11 +7,11 @@ import ( "reflect" "testing" - "github.com/go-vela/types/library" + api "github.com/go-vela/server/api/types" ) func TestService_ActiveServiceResp(t *testing.T) { - testService := library.Service{} + testService := api.Service{} err := json.Unmarshal([]byte(ServiceResp), &testService) if err != nil { diff --git a/mock/server/step.go b/mock/server/step.go index ff4c32ce8..b0a43da20 100644 --- a/mock/server/step.go +++ b/mock/server/step.go @@ -11,8 +11,8 @@ import ( "github.com/gin-gonic/gin" + api "github.com/go-vela/server/api/types" "github.com/go-vela/types" - "github.com/go-vela/types/library" ) const ( @@ -80,7 +80,7 @@ const ( func getSteps(c *gin.Context) { data := []byte(StepsResp) - var body []library.Step + var body []api.Step _ = json.Unmarshal(data, &body) c.JSON(http.StatusOK, body) @@ -102,7 +102,7 @@ func getStep(c *gin.Context) { data := []byte(StepResp) - var body library.Step + var body api.Step _ = json.Unmarshal(data, &body) c.JSON(http.StatusOK, body) @@ -112,7 +112,7 @@ func getStep(c *gin.Context) { func addStep(c *gin.Context) { data := []byte(StepResp) - var body library.Step + var body api.Step _ = json.Unmarshal(data, &body) c.JSON(http.StatusCreated, body) @@ -136,7 +136,7 @@ func updateStep(c *gin.Context) { data := []byte(StepResp) - var body library.Step + var body api.Step _ = json.Unmarshal(data, &body) c.JSON(http.StatusOK, body) diff --git a/mock/server/step_test.go b/mock/server/step_test.go index 9b4f6ef04..6b1952949 100644 --- a/mock/server/step_test.go +++ b/mock/server/step_test.go @@ -7,11 +7,11 @@ import ( "reflect" "testing" - "github.com/go-vela/types/library" + api "github.com/go-vela/server/api/types" ) func TestStep_ActiveStepResp(t *testing.T) { - testStep := library.Step{} + testStep := api.Step{} err := json.Unmarshal([]byte(StepResp), &testStep) if err != nil { diff --git a/queue/flags.go b/queue/flags.go index 35e5745f5..6277226a8 100644 --- a/queue/flags.go +++ b/queue/flags.go @@ -7,7 +7,7 @@ import ( "github.com/urfave/cli/v2" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) // Flags represents all supported command line diff --git a/queue/queue.go b/queue/queue.go index fdff9b364..c6a48eb54 100644 --- a/queue/queue.go +++ b/queue/queue.go @@ -8,7 +8,7 @@ import ( "github.com/sirupsen/logrus" "github.com/urfave/cli/v2" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) // FromCLIContext helper function to setup the queue from the CLI arguments. diff --git a/queue/redis/driver.go b/queue/redis/driver.go index 5d5410bf9..90ba4b572 100644 --- a/queue/redis/driver.go +++ b/queue/redis/driver.go @@ -2,7 +2,7 @@ package redis -import "github.com/go-vela/types/constants" +import "github.com/go-vela/server/constants" // Driver outputs the configured queue driver. func (c *client) Driver() string { diff --git a/queue/redis/driver_test.go b/queue/redis/driver_test.go index 52894f1ba..f4434820a 100644 --- a/queue/redis/driver_test.go +++ b/queue/redis/driver_test.go @@ -10,7 +10,7 @@ import ( "github.com/alicebob/miniredis/v2" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) func TestRedis_Driver(t *testing.T) { diff --git a/queue/redis/route.go b/queue/redis/route.go index 5ee0d29a6..cca2ad0e4 100644 --- a/queue/redis/route.go +++ b/queue/redis/route.go @@ -8,7 +8,7 @@ import ( "strings" "github.com/go-vela/server/compiler/types/pipeline" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) // Route decides which route a build gets placed within the queue. diff --git a/queue/redis/route_test.go b/queue/redis/route_test.go index 5750e9277..e4f802f0d 100644 --- a/queue/redis/route_test.go +++ b/queue/redis/route_test.go @@ -7,7 +7,7 @@ import ( "testing" "github.com/go-vela/server/compiler/types/pipeline" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) func TestRedis_Client_Route(t *testing.T) { diff --git a/queue/setup.go b/queue/setup.go index c554c9238..8874aba95 100644 --- a/queue/setup.go +++ b/queue/setup.go @@ -9,8 +9,8 @@ import ( "github.com/sirupsen/logrus" + "github.com/go-vela/server/constants" "github.com/go-vela/server/queue/redis" - "github.com/go-vela/types/constants" ) // Setup represents the configuration necessary for diff --git a/router/middleware/auth/auth.go b/router/middleware/auth/auth.go index 53ed6a8eb..3c6189100 100644 --- a/router/middleware/auth/auth.go +++ b/router/middleware/auth/auth.go @@ -8,7 +8,7 @@ import ( "github.com/golang-jwt/jwt/v5/request" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) // RetrieveAccessToken gets the passed in access token from the header in the request. diff --git a/router/middleware/auth/auth_test.go b/router/middleware/auth/auth_test.go index 7a7993a98..f40e04e0f 100644 --- a/router/middleware/auth/auth_test.go +++ b/router/middleware/auth/auth_test.go @@ -9,7 +9,7 @@ import ( "strings" "testing" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) func TestToken_Retrieve_Refresh(t *testing.T) { diff --git a/router/middleware/claims/claims.go b/router/middleware/claims/claims.go index e306f9e7e..4a20db604 100644 --- a/router/middleware/claims/claims.go +++ b/router/middleware/claims/claims.go @@ -9,10 +9,10 @@ import ( "github.com/gin-gonic/gin" "github.com/sirupsen/logrus" + "github.com/go-vela/server/constants" "github.com/go-vela/server/internal/token" "github.com/go-vela/server/router/middleware/auth" "github.com/go-vela/server/util" - "github.com/go-vela/types/constants" ) // Retrieve gets the claims in the given context. diff --git a/router/middleware/claims/claims_test.go b/router/middleware/claims/claims_test.go index 9d065df0f..8980deec1 100644 --- a/router/middleware/claims/claims_test.go +++ b/router/middleware/claims/claims_test.go @@ -17,9 +17,9 @@ import ( "github.com/sirupsen/logrus" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database" "github.com/go-vela/server/internal/token" - "github.com/go-vela/types/constants" ) func TestClaims_Retrieve(t *testing.T) { diff --git a/router/middleware/claims/context_test.go b/router/middleware/claims/context_test.go index b4f91baac..9a395166d 100644 --- a/router/middleware/claims/context_test.go +++ b/router/middleware/claims/context_test.go @@ -9,8 +9,8 @@ import ( "github.com/gin-gonic/gin" "github.com/golang-jwt/jwt/v5" + "github.com/go-vela/server/constants" "github.com/go-vela/server/internal/token" - "github.com/go-vela/types/constants" ) func TestClaims_FromContext(t *testing.T) { diff --git a/router/middleware/default_repo_settings_test.go b/router/middleware/default_repo_settings_test.go index 75cc7a02a..9a620c64c 100644 --- a/router/middleware/default_repo_settings_test.go +++ b/router/middleware/default_repo_settings_test.go @@ -10,7 +10,7 @@ import ( "github.com/gin-gonic/gin" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) func TestMiddleware_DefaultRepoEvents(t *testing.T) { diff --git a/router/middleware/executors/executors.go b/router/middleware/executors/executors.go index 21616d64a..54a930ab1 100644 --- a/router/middleware/executors/executors.go +++ b/router/middleware/executors/executors.go @@ -14,11 +14,11 @@ import ( "github.com/gin-gonic/gin" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database" "github.com/go-vela/server/internal/token" "github.com/go-vela/server/router/middleware/build" "github.com/go-vela/server/util" - "github.com/go-vela/types/constants" ) // Retrieve gets the executors in the given context. diff --git a/router/middleware/logger.go b/router/middleware/logger.go index 5b8be89c9..2e6a518f8 100644 --- a/router/middleware/logger.go +++ b/router/middleware/logger.go @@ -8,6 +8,7 @@ import ( "github.com/gin-gonic/gin" "github.com/sirupsen/logrus" + "github.com/go-vela/server/constants" "github.com/go-vela/server/router/middleware/build" "github.com/go-vela/server/router/middleware/claims" "github.com/go-vela/server/router/middleware/dashboard" @@ -21,7 +22,6 @@ import ( "github.com/go-vela/server/router/middleware/user" "github.com/go-vela/server/router/middleware/worker" "github.com/go-vela/server/util" - "github.com/go-vela/types/constants" ) // This file, in part, reproduces portions of diff --git a/router/middleware/logger_test.go b/router/middleware/logger_test.go index 25e3dad14..bc17ea7bd 100644 --- a/router/middleware/logger_test.go +++ b/router/middleware/logger_test.go @@ -24,7 +24,6 @@ import ( "github.com/go-vela/server/router/middleware/step" "github.com/go-vela/server/router/middleware/user" "github.com/go-vela/server/router/middleware/worker" - "github.com/go-vela/types/library" ) func TestMiddleware_Logger(t *testing.T) { @@ -41,14 +40,14 @@ func TestMiddleware_Logger(t *testing.T) { b.SetRepo(r) b.SetNumber(1) - svc := new(library.Service) + svc := new(api.Service) svc.SetID(1) svc.SetRepoID(1) svc.SetBuildID(1) svc.SetNumber(1) svc.SetName("foo") - s := new(library.Step) + s := new(api.Step) s.SetID(1) s.SetRepoID(1) s.SetBuildID(1) diff --git a/router/middleware/pipeline/pipeline_test.go b/router/middleware/pipeline/pipeline_test.go index bdc7d83f3..a12dd544b 100644 --- a/router/middleware/pipeline/pipeline_test.go +++ b/router/middleware/pipeline/pipeline_test.go @@ -20,6 +20,7 @@ import ( api "github.com/go-vela/server/api/types" "github.com/go-vela/server/compiler" "github.com/go-vela/server/compiler/native" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database" "github.com/go-vela/server/database/testutils" "github.com/go-vela/server/internal" @@ -30,7 +31,6 @@ import ( "github.com/go-vela/server/router/middleware/user" "github.com/go-vela/server/scm" "github.com/go-vela/server/scm/github" - "github.com/go-vela/types/constants" ) func TestPipeline_Retrieve(t *testing.T) { diff --git a/router/middleware/service/context.go b/router/middleware/service/context.go index 7083879ea..4098cdea0 100644 --- a/router/middleware/service/context.go +++ b/router/middleware/service/context.go @@ -5,7 +5,7 @@ package service import ( "context" - "github.com/go-vela/types/library" + api "github.com/go-vela/server/api/types" ) const key = "service" @@ -16,13 +16,13 @@ type Setter interface { } // FromContext returns the Service associated with this context. -func FromContext(c context.Context) *library.Service { +func FromContext(c context.Context) *api.Service { value := c.Value(key) if value == nil { return nil } - s, ok := value.(*library.Service) + s, ok := value.(*api.Service) if !ok { return nil } @@ -32,6 +32,6 @@ func FromContext(c context.Context) *library.Service { // ToContext adds the Service to this context if it supports // the Setter interface. -func ToContext(c Setter, s *library.Service) { +func ToContext(c Setter, s *api.Service) { c.Set(key, s) } diff --git a/router/middleware/service/context_test.go b/router/middleware/service/context_test.go index 8c1cc74f4..41860657e 100644 --- a/router/middleware/service/context_test.go +++ b/router/middleware/service/context_test.go @@ -7,13 +7,13 @@ import ( "github.com/gin-gonic/gin" - "github.com/go-vela/types/library" + api "github.com/go-vela/server/api/types" ) func TestService_FromContext(t *testing.T) { // setup types num := int64(1) - want := &library.Service{ID: &num} + want := &api.Service{ID: &num} // setup context gin.SetMode(gin.TestMode) @@ -72,7 +72,7 @@ func TestService_FromContext_Empty(t *testing.T) { func TestService_ToContext(t *testing.T) { // setup types num := int64(1) - want := &library.Service{ID: &num} + want := &api.Service{ID: &num} // setup context gin.SetMode(gin.TestMode) diff --git a/router/middleware/service/service.go b/router/middleware/service/service.go index 7089e22f7..2f9cabb7c 100644 --- a/router/middleware/service/service.go +++ b/router/middleware/service/service.go @@ -10,16 +10,16 @@ import ( "github.com/gin-gonic/gin" "github.com/sirupsen/logrus" + api "github.com/go-vela/server/api/types" "github.com/go-vela/server/database" "github.com/go-vela/server/router/middleware/build" "github.com/go-vela/server/router/middleware/org" "github.com/go-vela/server/router/middleware/repo" "github.com/go-vela/server/util" - "github.com/go-vela/types/library" ) // Retrieve gets the service in the given context. -func Retrieve(c *gin.Context) *library.Service { +func Retrieve(c *gin.Context) *api.Service { return FromContext(c) } diff --git a/router/middleware/service/service_test.go b/router/middleware/service/service_test.go index 681975c36..f91bee81d 100644 --- a/router/middleware/service/service_test.go +++ b/router/middleware/service/service_test.go @@ -17,12 +17,11 @@ import ( "github.com/go-vela/server/router/middleware/build" "github.com/go-vela/server/router/middleware/org" "github.com/go-vela/server/router/middleware/repo" - "github.com/go-vela/types/library" ) func TestService_Retrieve(t *testing.T) { // setup types - want := new(library.Service) + want := new(api.Service) want.SetID(1) // setup context @@ -57,7 +56,7 @@ func TestService_Establish(t *testing.T) { b.SetRepo(r) b.SetNumber(1) - want := new(library.Service) + want := new(api.Service) want.SetID(1) want.SetRepoID(1) want.SetBuildID(1) @@ -74,7 +73,7 @@ func TestService_Establish(t *testing.T) { want.SetRuntime("") want.SetDistribution("") - got := new(library.Service) + got := new(api.Service) // setup database db, err := database.NewTest() diff --git a/router/middleware/step/context.go b/router/middleware/step/context.go index f8c13740d..ae022c6b6 100644 --- a/router/middleware/step/context.go +++ b/router/middleware/step/context.go @@ -5,7 +5,7 @@ package step import ( "context" - "github.com/go-vela/types/library" + api "github.com/go-vela/server/api/types" ) const key = "step" @@ -16,13 +16,13 @@ type Setter interface { } // FromContext returns the Step associated with this context. -func FromContext(c context.Context) *library.Step { +func FromContext(c context.Context) *api.Step { value := c.Value(key) if value == nil { return nil } - s, ok := value.(*library.Step) + s, ok := value.(*api.Step) if !ok { return nil } @@ -32,6 +32,6 @@ func FromContext(c context.Context) *library.Step { // ToContext adds the Step to this context if it supports // the Setter interface. -func ToContext(c Setter, s *library.Step) { +func ToContext(c Setter, s *api.Step) { c.Set(key, s) } diff --git a/router/middleware/step/context_test.go b/router/middleware/step/context_test.go index c42feb41c..e111cffd2 100644 --- a/router/middleware/step/context_test.go +++ b/router/middleware/step/context_test.go @@ -7,13 +7,13 @@ import ( "github.com/gin-gonic/gin" - "github.com/go-vela/types/library" + api "github.com/go-vela/server/api/types" ) func TestStep_FromContext(t *testing.T) { // setup types num := int64(1) - want := &library.Step{ID: &num} + want := &api.Step{ID: &num} // setup context gin.SetMode(gin.TestMode) @@ -72,7 +72,7 @@ func TestStep_FromContext_Empty(t *testing.T) { func TestStep_ToContext(t *testing.T) { // setup types num := int64(1) - want := &library.Step{ID: &num} + want := &api.Step{ID: &num} // setup context gin.SetMode(gin.TestMode) diff --git a/router/middleware/step/step.go b/router/middleware/step/step.go index c1e31cf43..1e9bb95d3 100644 --- a/router/middleware/step/step.go +++ b/router/middleware/step/step.go @@ -10,16 +10,16 @@ import ( "github.com/gin-gonic/gin" "github.com/sirupsen/logrus" + api "github.com/go-vela/server/api/types" "github.com/go-vela/server/database" "github.com/go-vela/server/router/middleware/build" "github.com/go-vela/server/router/middleware/org" "github.com/go-vela/server/router/middleware/repo" "github.com/go-vela/server/util" - "github.com/go-vela/types/library" ) // Retrieve gets the step in the given context. -func Retrieve(c *gin.Context) *library.Step { +func Retrieve(c *gin.Context) *api.Step { return FromContext(c) } diff --git a/router/middleware/step/step_test.go b/router/middleware/step/step_test.go index 120170d04..77f4701a7 100644 --- a/router/middleware/step/step_test.go +++ b/router/middleware/step/step_test.go @@ -17,12 +17,11 @@ import ( "github.com/go-vela/server/router/middleware/build" "github.com/go-vela/server/router/middleware/org" "github.com/go-vela/server/router/middleware/repo" - "github.com/go-vela/types/library" ) func TestStep_Retrieve(t *testing.T) { // setup types - want := new(library.Step) + want := new(api.Step) want.SetID(1) // setup context @@ -58,7 +57,7 @@ func TestStep_Establish(t *testing.T) { b.SetRepo(r) b.SetNumber(1) - want := new(library.Step) + want := new(api.Step) want.SetID(1) want.SetRepoID(1) want.SetBuildID(1) @@ -77,7 +76,7 @@ func TestStep_Establish(t *testing.T) { want.SetDistribution("") want.SetReportAs("") - got := new(library.Step) + got := new(api.Step) // setup database db, err := database.NewTest() diff --git a/router/middleware/user/user.go b/router/middleware/user/user.go index cc883fd41..a6936f96e 100644 --- a/router/middleware/user/user.go +++ b/router/middleware/user/user.go @@ -10,10 +10,10 @@ import ( "github.com/sirupsen/logrus" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database" "github.com/go-vela/server/router/middleware/claims" "github.com/go-vela/server/util" - "github.com/go-vela/types/constants" ) // Retrieve gets the user in the given context. diff --git a/router/middleware/user/user_test.go b/router/middleware/user/user_test.go index 28d7f7a3d..5246ff701 100644 --- a/router/middleware/user/user_test.go +++ b/router/middleware/user/user_test.go @@ -15,12 +15,12 @@ import ( "github.com/sirupsen/logrus" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database" "github.com/go-vela/server/internal/token" "github.com/go-vela/server/router/middleware/claims" "github.com/go-vela/server/scm" "github.com/go-vela/server/scm/github" - "github.com/go-vela/types/constants" ) func TestUser_Retrieve(t *testing.T) { diff --git a/scm/flags.go b/scm/flags.go index 2a64f7e14..0d95ebcb5 100644 --- a/scm/flags.go +++ b/scm/flags.go @@ -5,7 +5,7 @@ package scm import ( "github.com/urfave/cli/v2" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) // Flags represents all supported command line diff --git a/scm/github/driver.go b/scm/github/driver.go index 1a17f5f0f..f16f85f8a 100644 --- a/scm/github/driver.go +++ b/scm/github/driver.go @@ -2,7 +2,7 @@ package github -import "github.com/go-vela/types/constants" +import "github.com/go-vela/server/constants" // Driver outputs the configured scm driver. func (c *client) Driver() string { diff --git a/scm/github/driver_test.go b/scm/github/driver_test.go index 42b9f8f1e..7ea6656d8 100644 --- a/scm/github/driver_test.go +++ b/scm/github/driver_test.go @@ -6,7 +6,7 @@ import ( "reflect" "testing" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) func TestGitHub_Driver(t *testing.T) { diff --git a/scm/github/repo.go b/scm/github/repo.go index f608b5199..a35c0179e 100644 --- a/scm/github/repo.go +++ b/scm/github/repo.go @@ -14,8 +14,7 @@ import ( "github.com/sirupsen/logrus" api "github.com/go-vela/server/api/types" - "github.com/go-vela/types/constants" - "github.com/go-vela/types/library" + "github.com/go-vela/server/constants" ) // ConfigBackoff is a wrapper for Config that will retry five times if the function @@ -401,7 +400,7 @@ func (c *client) Status(ctx context.Context, u *api.User, b *api.Build, org, nam } // StepStatus sends the commit status for the given SHA to the GitHub repo with the step as the context. -func (c *client) StepStatus(ctx context.Context, u *api.User, b *api.Build, s *library.Step, org, name string) error { +func (c *client) StepStatus(ctx context.Context, u *api.User, b *api.Build, s *api.Step, org, name string) error { c.Logger.WithFields(logrus.Fields{ "build": b.GetNumber(), "org": org, diff --git a/scm/github/repo_test.go b/scm/github/repo_test.go index a1920e73d..502c1cc7c 100644 --- a/scm/github/repo_test.go +++ b/scm/github/repo_test.go @@ -15,8 +15,7 @@ import ( "github.com/gin-gonic/gin" api "github.com/go-vela/server/api/types" - "github.com/go-vela/types/constants" - "github.com/go-vela/types/library" + "github.com/go-vela/server/constants" ) func TestGithub_Config_YML(t *testing.T) { @@ -909,7 +908,7 @@ func TestGithub_Status_Running(t *testing.T) { b.SetStatus(constants.StatusRunning) b.SetCommit("abcd1234") - step := new(library.Step) + step := new(api.Step) step.SetID(1) step.SetNumber(1) step.SetName("test") @@ -973,7 +972,7 @@ func TestGithub_Status_Success(t *testing.T) { b.SetStatus(constants.StatusRunning) b.SetCommit("abcd1234") - step := new(library.Step) + step := new(api.Step) step.SetID(1) step.SetNumber(1) step.SetName("test") @@ -1037,7 +1036,7 @@ func TestGithub_Status_Failure(t *testing.T) { b.SetStatus(constants.StatusRunning) b.SetCommit("abcd1234") - step := new(library.Step) + step := new(api.Step) step.SetID(1) step.SetNumber(1) step.SetName("test") @@ -1101,7 +1100,7 @@ func TestGithub_Status_Killed(t *testing.T) { b.SetStatus(constants.StatusRunning) b.SetCommit("abcd1234") - step := new(library.Step) + step := new(api.Step) step.SetID(1) step.SetNumber(1) step.SetName("test") @@ -1165,7 +1164,7 @@ func TestGithub_Status_Skipped(t *testing.T) { b.SetStatus(constants.StatusSkipped) b.SetCommit("abcd1234") - step := new(library.Step) + step := new(api.Step) step.SetID(1) step.SetNumber(1) step.SetName("test") @@ -1229,7 +1228,7 @@ func TestGithub_Status_Error(t *testing.T) { b.SetStatus(constants.StatusRunning) b.SetCommit("abcd1234") - step := new(library.Step) + step := new(api.Step) step.SetID(1) step.SetNumber(1) step.SetName("test") diff --git a/scm/github/webhook.go b/scm/github/webhook.go index d79deb718..aa51c375f 100644 --- a/scm/github/webhook.go +++ b/scm/github/webhook.go @@ -17,8 +17,8 @@ import ( "github.com/sirupsen/logrus" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" "github.com/go-vela/server/internal" - "github.com/go-vela/types/constants" ) // ProcessWebhook parses the webhook from a repo. diff --git a/scm/github/webhook_test.go b/scm/github/webhook_test.go index 15fdb486d..1ef1685fe 100644 --- a/scm/github/webhook_test.go +++ b/scm/github/webhook_test.go @@ -17,8 +17,8 @@ import ( api "github.com/go-vela/server/api/types" "github.com/go-vela/server/compiler/types/raw" + "github.com/go-vela/server/constants" "github.com/go-vela/server/internal" - "github.com/go-vela/types/constants" ) func TestGithub_ProcessWebhook_Push(t *testing.T) { diff --git a/scm/scm.go b/scm/scm.go index e45b33576..b93bde906 100644 --- a/scm/scm.go +++ b/scm/scm.go @@ -7,7 +7,7 @@ import ( "github.com/sirupsen/logrus" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) // New creates and returns a Vela service capable of diff --git a/scm/service.go b/scm/service.go index ca93ec1d5..bc917ce9a 100644 --- a/scm/service.go +++ b/scm/service.go @@ -8,7 +8,6 @@ import ( api "github.com/go-vela/server/api/types" "github.com/go-vela/server/internal" - "github.com/go-vela/types/library" ) // Service represents the interface for Vela integrating @@ -119,7 +118,7 @@ type Service interface { Status(context.Context, *api.User, *api.Build, string, string) error // StepStatus defines a function that sends the // commit status for the given SHA for a specified step context. - StepStatus(context.Context, *api.User, *api.Build, *library.Step, string, string) error + StepStatus(context.Context, *api.User, *api.Build, *api.Step, string, string) error // ListUserRepos defines a function that retrieves // all repos with admin rights for the user. ListUserRepos(context.Context, *api.User) ([]*api.Repo, error) diff --git a/scm/setup.go b/scm/setup.go index c32a0cf66..dc3a3e698 100644 --- a/scm/setup.go +++ b/scm/setup.go @@ -8,9 +8,9 @@ import ( "github.com/sirupsen/logrus" + "github.com/go-vela/server/constants" "github.com/go-vela/server/scm/github" "github.com/go-vela/server/tracing" - "github.com/go-vela/types/constants" ) // Setup represents the configuration necessary for diff --git a/secret/native/count.go b/secret/native/count.go index 460ee077b..1931e4286 100644 --- a/secret/native/count.go +++ b/secret/native/count.go @@ -9,7 +9,7 @@ import ( "github.com/sirupsen/logrus" api "github.com/go-vela/server/api/types" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) // Count counts a list of secrets. diff --git a/secret/native/create.go b/secret/native/create.go index 78cce0d4c..c374bacbd 100644 --- a/secret/native/create.go +++ b/secret/native/create.go @@ -9,7 +9,7 @@ import ( "github.com/sirupsen/logrus" api "github.com/go-vela/server/api/types" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) // Create creates a new secret. diff --git a/secret/native/delete.go b/secret/native/delete.go index d0fbdc458..a32b669a1 100644 --- a/secret/native/delete.go +++ b/secret/native/delete.go @@ -8,7 +8,7 @@ import ( "github.com/sirupsen/logrus" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) // Delete deletes a secret. diff --git a/secret/native/driver.go b/secret/native/driver.go index 022967d53..26ba4f3dc 100644 --- a/secret/native/driver.go +++ b/secret/native/driver.go @@ -2,7 +2,7 @@ package native -import "github.com/go-vela/types/constants" +import "github.com/go-vela/server/constants" // Driver outputs the configured secret driver. func (c *client) Driver() string { diff --git a/secret/native/driver_test.go b/secret/native/driver_test.go index a18369e86..9f003bf94 100644 --- a/secret/native/driver_test.go +++ b/secret/native/driver_test.go @@ -6,8 +6,8 @@ import ( "reflect" "testing" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database" - "github.com/go-vela/types/constants" ) func TestNative_Driver(t *testing.T) { diff --git a/secret/native/get.go b/secret/native/get.go index d6731be3a..fe9e0ddf4 100644 --- a/secret/native/get.go +++ b/secret/native/get.go @@ -9,7 +9,7 @@ import ( "github.com/sirupsen/logrus" api "github.com/go-vela/server/api/types" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) // Get captures a secret. diff --git a/secret/native/list.go b/secret/native/list.go index 42b3ee172..1f6604f91 100644 --- a/secret/native/list.go +++ b/secret/native/list.go @@ -9,7 +9,7 @@ import ( "github.com/sirupsen/logrus" api "github.com/go-vela/server/api/types" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) // List captures a list of secrets. diff --git a/secret/native/update.go b/secret/native/update.go index df1d5111d..12021d378 100644 --- a/secret/native/update.go +++ b/secret/native/update.go @@ -9,7 +9,7 @@ import ( "github.com/sirupsen/logrus" api "github.com/go-vela/server/api/types" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) // Update updates an existing secret. diff --git a/secret/secret.go b/secret/secret.go index 7dadc4b05..15dc307a8 100644 --- a/secret/secret.go +++ b/secret/secret.go @@ -7,7 +7,7 @@ import ( "github.com/sirupsen/logrus" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) // New creates and returns a Vela service capable of diff --git a/secret/setup.go b/secret/setup.go index 8a9917c0a..1f7c080d2 100644 --- a/secret/setup.go +++ b/secret/setup.go @@ -9,10 +9,10 @@ import ( "github.com/sirupsen/logrus" + "github.com/go-vela/server/constants" "github.com/go-vela/server/database" "github.com/go-vela/server/secret/native" "github.com/go-vela/server/secret/vault" - "github.com/go-vela/types/constants" ) // Setup represents the configuration necessary for diff --git a/secret/vault/count.go b/secret/vault/count.go index 907165cea..927a1da85 100644 --- a/secret/vault/count.go +++ b/secret/vault/count.go @@ -10,7 +10,7 @@ import ( "github.com/hashicorp/vault/api" "github.com/sirupsen/logrus" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) // Count counts a list of secrets. diff --git a/secret/vault/create.go b/secret/vault/create.go index b1ac5b40a..2a3e94a2b 100644 --- a/secret/vault/create.go +++ b/secret/vault/create.go @@ -10,8 +10,8 @@ import ( "github.com/sirupsen/logrus" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" database "github.com/go-vela/server/database/types" - "github.com/go-vela/types/constants" ) // Create creates a new secret. diff --git a/secret/vault/delete.go b/secret/vault/delete.go index ef3521c54..246393764 100644 --- a/secret/vault/delete.go +++ b/secret/vault/delete.go @@ -9,7 +9,7 @@ import ( "github.com/sirupsen/logrus" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) // Delete deletes a secret. diff --git a/secret/vault/driver.go b/secret/vault/driver.go index ad9a4858c..96dd0179d 100644 --- a/secret/vault/driver.go +++ b/secret/vault/driver.go @@ -2,7 +2,7 @@ package vault -import "github.com/go-vela/types/constants" +import "github.com/go-vela/server/constants" // Driver outputs the configured secret driver. func (c *client) Driver() string { diff --git a/secret/vault/driver_test.go b/secret/vault/driver_test.go index 4a0975766..22b3f0a18 100644 --- a/secret/vault/driver_test.go +++ b/secret/vault/driver_test.go @@ -8,7 +8,7 @@ import ( "reflect" "testing" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) func TestVault_Driver(t *testing.T) { diff --git a/secret/vault/get.go b/secret/vault/get.go index 081ecb910..dd3b08591 100644 --- a/secret/vault/get.go +++ b/secret/vault/get.go @@ -11,7 +11,7 @@ import ( "github.com/sirupsen/logrus" velaAPI "github.com/go-vela/server/api/types" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) // Get captures a secret. diff --git a/secret/vault/list.go b/secret/vault/list.go index 2fd6a75cc..b9bbfbfa0 100644 --- a/secret/vault/list.go +++ b/secret/vault/list.go @@ -11,7 +11,7 @@ import ( "github.com/sirupsen/logrus" velaAPI "github.com/go-vela/server/api/types" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) // List captures a list of secrets. diff --git a/secret/vault/update.go b/secret/vault/update.go index a1c0c7b8a..08ad3cda5 100644 --- a/secret/vault/update.go +++ b/secret/vault/update.go @@ -10,8 +10,8 @@ import ( "github.com/sirupsen/logrus" api "github.com/go-vela/server/api/types" + "github.com/go-vela/server/constants" database "github.com/go-vela/server/database/types" - "github.com/go-vela/types/constants" ) // Update updates a secret. diff --git a/secret/vault/vault.go b/secret/vault/vault.go index fc88a167f..9cf2a7161 100644 --- a/secret/vault/vault.go +++ b/secret/vault/vault.go @@ -13,7 +13,7 @@ import ( "github.com/sirupsen/logrus" velaAPI "github.com/go-vela/server/api/types" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) const ( diff --git a/util/compression_test.go b/util/compression_test.go index 4328b61a3..5492a9750 100644 --- a/util/compression_test.go +++ b/util/compression_test.go @@ -6,7 +6,7 @@ import ( "reflect" "testing" - "github.com/go-vela/types/constants" + "github.com/go-vela/server/constants" ) func TestDatabase_compress(t *testing.T) { From afd5d78f59b0aebf6c66f321f9b8a5cda10d3fff Mon Sep 17 00:00:00 2001 From: ecrupper Date: Thu, 17 Oct 2024 20:10:20 -0500 Subject: [PATCH 2/2] gci --- database/secret/count_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/database/secret/count_test.go b/database/secret/count_test.go index 87b1d5662..5ae0944c4 100644 --- a/database/secret/count_test.go +++ b/database/secret/count_test.go @@ -8,6 +8,7 @@ import ( "testing" "github.com/DATA-DOG/go-sqlmock" + "github.com/go-vela/server/database/testutils" )