Merge branch 'main' into refactor/nested-api/deployment #14482
reviewdog [golangci] report
reported by reviewdog 🐶
Findings (43)
internal/token/generate_rsa.go|19 col 32| unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
internal/token/generate_rsa.go|45 col 21| Non-inherited new context, use function like context.WithXXX
instead (contextcheck)
router/middleware/logger.go|48 col 36| unused-parameter: parameter 'timeFormat' seems to be unused, consider removing or renaming it as _ (revive)
database/executable/clean_test.go|130 col 19| SA1019: library.Build is deprecated: use Build from github.com/go-vela/server/api/types instead. (staticcheck)
database/executable/clean_test.go|131 col 10| SA1019: library.Build is deprecated: use Build from github.com/go-vela/server/api/types instead. (staticcheck)
router/middleware/perm/perm_test.go|447 col 20| Non-inherited new context, use function like context.WithXXX
instead (contextcheck)
router/middleware/perm/perm_test.go|540 col 20| Non-inherited new context, use function like context.WithXXX
instead (contextcheck)
scm/github/webhook.go|86 col 32| unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
scm/github/authentication.go|36 col 24| unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
compiler/native/compile.go|335 col 26| Function modifyConfig
should pass the context parameter (contextcheck)
compiler/native/compile.go|430 col 26| Function modifyConfig
should pass the context parameter (contextcheck)
compiler/template/starlark/render.go|44 col 18| SA1019: starlark.ExecFile is deprecated: use [ExecFileOptions] with [syntax.FileOptions] instead, because this function relies on legacy global variables. (staticcheck)
compiler/template/starlark/render.go|152 col 18| SA1019: starlark.ExecFile is deprecated: use [ExecFileOptions] with [syntax.FileOptions] instead, because this function relies on legacy global variables. (staticcheck)
compiler/template/starlark/starlark.go|131 col 4| only one cuddle assignment allowed before if statement (wsl)
database/worker/create.go|3| 3-41 lines are duplicate of database/worker/update.go:3-41
(dupl)
database/worker/update.go|3| 3-41 lines are duplicate of database/worker/create.go:3-41
(dupl)
mock/server/schedule.go|3| 3-284 lines are duplicate of mock/server/secret.go:4-181
(dupl)
mock/server/authentication.go|84 col 9| string error
has 4 occurrences, make it a constant (goconst)
secret/vault/refresh_test.go|45 col 74| unused-parameter: parameter 'r' seems to be unused, consider removing or renaming it as _ (revive)
secret/vault/refresh_test.go|71 col 40| unused-parameter: parameter 'in' seems to be unused, consider removing or renaming it as _ (revive)
secret/vault/refresh_test.go|108 col 40| unused-parameter: parameter 'in' seems to be unused, consider removing or renaming it as _ (revive)
secret/vault/refresh_test.go|128 col 40| unused-parameter: parameter 'in' seems to be unused, consider removing or renaming it as _ (revive)
secret/vault/refresh_test.go|201 col 74| unused-parameter: parameter 'r' seems to be unused, consider removing or renaming it as _ (revive)
database/step/create.go|3| 3-41 lines are duplicate of database/step/update.go:3-41
(dupl)
database/step/update.go|3| 3-41 lines are duplicate of database/step/create.go:3-41
(dupl)
database/pipeline/create.go|3| 3-57 lines are duplicate of database/pipeline/update.go:3-58
(dupl)
database/pipeline/update.go|3| 3-58 lines are duplicate of database/pipeline/create.go:3-57
(dupl)
database/deployment/create.go|3| 3-37 lines are duplicate of database/deployment/update.go:3-37
(dupl)
database/deployment/update.go|3| 3-37 lines are duplicate of database/deployment/create.go:3-37
(dupl)
database/hook/get.go|3| 3-40 lines are duplicate of database/hook/get_webhook.go:3-40
(dupl)
database/hook/get_webhook.go|3| 3-40 lines are duplicate of database/hook/get.go:3-40
(dupl)
database/hook/create.go|3| 3-39 lines are duplicate of database/hook/update.go:3-42
(dupl)
database/hook/update.go|3| 3-42 lines are duplicate of database/hook/create.go:3-39
(dupl)
database/service/create.go|3| 3-41 lines are duplicate of database/service/update.go:3-41
(dupl)
database/service/update.go|3| 3-41 lines are duplicate of database/service/create.go:3-41
(dupl)
api/pipeline/validate.go|78| 78-110 lines are duplicate of api/pipeline/compile.go:80-112
(dupl)
api/pipeline/validate.go|3| 3-110 lines are duplicate of api/pipeline/expand.go:4-112
(dupl)
database/types/build.go|384 col 44| G115: integer overflow conversion int -> int32 (gosec)
database/types/build.go|385 col 44| G115: integer overflow conversion int -> int32 (gosec)
database/types/repo.go|336 col 43| G115: integer overflow conversion int -> int32 (gosec)
database/types/settings.go|134 col 35| G115: integer overflow conversion int64 -> uint64 (gosec)
database/types/settings.go|205 col 49| G115: integer overflow conversion uint64 -> int64 (gosec)
secret/vault/get.go|40 col 2| directive //nolint:ineffassign,staticcheck // ignore false positive
is unused for linter "staticcheck" (nolintlint)
Filtered Findings (0)
Annotations
Check failure on line 19 in internal/token/generate_rsa.go
github-actions / golangci
[golangci] internal/token/generate_rsa.go#L19
unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
Raw output
internal/token/generate_rsa.go:19:32: unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
func (tm *Manager) GenerateRSA(ctx context.Context, db database.Interface) error {
^
Check failure on line 45 in internal/token/generate_rsa.go
github-actions / golangci
[golangci] internal/token/generate_rsa.go#L45
Non-inherited new context, use function like `context.WithXXX` instead (contextcheck)
Raw output
internal/token/generate_rsa.go:45:21: Non-inherited new context, use function like `context.WithXXX` instead (contextcheck)
err = db.CreateJWK(context.TODO(), j)
^
Check failure on line 48 in router/middleware/logger.go
github-actions / golangci
[golangci] router/middleware/logger.go#L48
unused-parameter: parameter 'timeFormat' seems to be unused, consider removing or renaming it as _ (revive)
Raw output
router/middleware/logger.go:48:36: unused-parameter: parameter 'timeFormat' seems to be unused, consider removing or renaming it as _ (revive)
func Logger(logger *logrus.Logger, timeFormat string) gin.HandlerFunc {
^
Check failure on line 130 in database/executable/clean_test.go
github-actions / golangci
[golangci] database/executable/clean_test.go#L130
SA1019: library.Build is deprecated: use Build from github.com/go-vela/server/api/types instead. (staticcheck)
Raw output
database/executable/clean_test.go:130:19: SA1019: library.Build is deprecated: use Build from github.com/go-vela/server/api/types instead. (staticcheck)
func testBuild() *library.Build {
^
Check failure on line 131 in database/executable/clean_test.go
github-actions / golangci
[golangci] database/executable/clean_test.go#L131
SA1019: library.Build is deprecated: use Build from github.com/go-vela/server/api/types instead. (staticcheck)
Raw output
database/executable/clean_test.go:131:10: SA1019: library.Build is deprecated: use Build from github.com/go-vela/server/api/types instead. (staticcheck)
return &library.Build{
^
Check failure on line 447 in router/middleware/perm/perm_test.go
github-actions / golangci
[golangci] router/middleware/perm/perm_test.go#L447
Non-inherited new context, use function like `context.WithXXX` instead (contextcheck)
Raw output
router/middleware/perm/perm_test.go:447:20: Non-inherited new context, use function like `context.WithXXX` instead (contextcheck)
_ = db.DeleteRepo(_context.TODO(), r)
^
Check failure on line 540 in router/middleware/perm/perm_test.go
github-actions / golangci
[golangci] router/middleware/perm/perm_test.go#L540
Non-inherited new context, use function like `context.WithXXX` instead (contextcheck)
Raw output
router/middleware/perm/perm_test.go:540:20: Non-inherited new context, use function like `context.WithXXX` instead (contextcheck)
_ = db.DeleteRepo(_context.TODO(), r)
^
Check failure on line 86 in scm/github/webhook.go
github-actions / golangci
[golangci] scm/github/webhook.go#L86
unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
Raw output
scm/github/webhook.go:86:32: unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
func (c *client) VerifyWebhook(ctx context.Context, request *http.Request, r *api.Repo) error {
^
Check failure on line 36 in scm/github/authentication.go
github-actions / golangci
[golangci] scm/github/authentication.go#L36
unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
Raw output
scm/github/authentication.go:36:24: unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
func (c *client) Login(ctx context.Context, w http.ResponseWriter, r *http.Request) (string, error) {
^
Check failure on line 335 in compiler/native/compile.go
github-actions / golangci
[golangci] compiler/native/compile.go#L335
Function `modifyConfig` should pass the context parameter (contextcheck)
Raw output
compiler/native/compile.go:335:26: Function `modifyConfig` should pass the context parameter (contextcheck)
p, err = c.modifyConfig(p, c.build, c.repo)
^
Check failure on line 430 in compiler/native/compile.go
github-actions / golangci
[golangci] compiler/native/compile.go#L430
Function `modifyConfig` should pass the context parameter (contextcheck)
Raw output
compiler/native/compile.go:430:26: Function `modifyConfig` should pass the context parameter (contextcheck)
p, err = c.modifyConfig(p, c.build, c.repo)
^
Check failure on line 44 in compiler/template/starlark/render.go
github-actions / golangci
[golangci] compiler/template/starlark/render.go#L44
SA1019: starlark.ExecFile is deprecated: use [ExecFileOptions] with [syntax.FileOptions] instead, because this function relies on legacy global variables. (staticcheck)
Raw output
compiler/template/starlark/render.go:44:18: SA1019: starlark.ExecFile is deprecated: use [ExecFileOptions] with [syntax.FileOptions] instead, because this function relies on legacy global variables. (staticcheck)
globals, err := starlark.ExecFile(thread, tName, tmpl, predeclared)
^
Check failure on line 152 in compiler/template/starlark/render.go
github-actions / golangci
[golangci] compiler/template/starlark/render.go#L152
SA1019: starlark.ExecFile is deprecated: use [ExecFileOptions] with [syntax.FileOptions] instead, because this function relies on legacy global variables. (staticcheck)
Raw output
compiler/template/starlark/render.go:152:18: SA1019: starlark.ExecFile is deprecated: use [ExecFileOptions] with [syntax.FileOptions] instead, because this function relies on legacy global variables. (staticcheck)
globals, err := starlark.ExecFile(thread, "templated-base", b, predeclared)
^
Check failure on line 131 in compiler/template/starlark/starlark.go
github-actions / golangci
[golangci] compiler/template/starlark/starlark.go#L131
only one cuddle assignment allowed before if statement (wsl)
Raw output
compiler/template/starlark/starlark.go:131:4: only one cuddle assignment allowed before if statement (wsl)
if err != nil {
^
Check failure on line 3 in database/worker/create.go
github-actions / golangci
[golangci] database/worker/create.go#L3
3-41 lines are duplicate of `database/worker/update.go:3-41` (dupl)
Raw output
database/worker/create.go:3: 3-41 lines are duplicate of `database/worker/update.go:3-41` (dupl)
package worker
import (
"context"
"github.com/sirupsen/logrus"
api "github.com/go-vela/server/api/types"
"github.com/go-vela/server/database/types"
"github.com/go-vela/types/constants"
)
// CreateWorker creates a new worker in the database.
func (e *engine) CreateWorker(ctx context.Context, w *api.Worker) (*api.Worker, error) {
e.logger.WithFields(logrus.Fields{
"worker": w.GetHostname(),
}).Tracef("creating worker %s", w.GetHostname())
// cast the library type to database type
//
// https://pkg.go.dev/github.com/go-vela/types/database#WorkerFromLibrary
worker := types.WorkerFromAPI(w)
// validate the necessary fields are populated
//
// https://pkg.go.dev/github.com/go-vela/types/database#Worker.Validate
err := worker.Validate()
if err != nil {
return nil, err
}
// send query to the database
result := e.client.
WithContext(ctx).
Table(constants.TableWorker).
Create(worker)
return worker.ToAPI(w.GetRunningBuilds()), result.Error
}
Check failure on line 3 in database/worker/update.go
github-actions / golangci
[golangci] database/worker/update.go#L3
3-41 lines are duplicate of `database/worker/create.go:3-41` (dupl)
Raw output
database/worker/update.go:3: 3-41 lines are duplicate of `database/worker/create.go:3-41` (dupl)
package worker
import (
"context"
"github.com/sirupsen/logrus"
api "github.com/go-vela/server/api/types"
"github.com/go-vela/server/database/types"
"github.com/go-vela/types/constants"
)
// UpdateWorker updates an existing worker in the database.
func (e *engine) UpdateWorker(ctx context.Context, w *api.Worker) (*api.Worker, error) {
e.logger.WithFields(logrus.Fields{
"worker": w.GetHostname(),
}).Tracef("updating worker %s", w.GetHostname())
// cast the library type to database type
//
// https://pkg.go.dev/github.com/go-vela/types/database#WorkerFromLibrary
worker := types.WorkerFromAPI(w)
// validate the necessary fields are populated
//
// https://pkg.go.dev/github.com/go-vela/types/database#Worker.Validate
err := worker.Validate()
if err != nil {
return nil, err
}
// send query to the database
result := e.client.
WithContext(ctx).
Table(constants.TableWorker).
Save(worker)
return worker.ToAPI(w.GetRunningBuilds()), result.Error
}
Check failure on line 3 in mock/server/schedule.go
github-actions / golangci
[golangci] mock/server/schedule.go#L3
3-284 lines are duplicate of `mock/server/secret.go:4-181` (dupl)
Raw output
mock/server/schedule.go:3: 3-284 lines are duplicate of `mock/server/secret.go:4-181` (dupl)
package server
import (
"encoding/json"
"fmt"
"net/http"
"strings"
"github.com/gin-gonic/gin"
api "github.com/go-vela/server/api/types"
"github.com/go-vela/types"
)
const (
// ScheduleResp represents a JSON return for a single schedule.
ScheduleResp = `{
"id": 2,
"repo": {
"id": 1,
"owner": {
"id": 1,
"name": "octocat",
"favorites": [],
"active": true,
"admin": false
},
"org": "github",
"counter": 10,
"name": "octocat",
"full_name": "github/octocat",
"link": "https://github.com/github/octocat",
"clone": "https://github.com/github/octocat",
"branch": "main",
"build_limit": 10,
"timeout": 60,
"visibility": "public",
"private": false,
"trusted": true,
"pipeline_type": "yaml",
"topics": [],
"active": true,
"allow_events": {
"push": {
"branch": true,
"tag": true
},
"pull_request": {
"opened": true,
"synchronize": true,
"reopened": true,
"edited": false
},
"deployment": {
"created": true
},
"comment": {
"created": false,
"edited": false
}
},
"approve_build": "fork-always",
"previous_name": ""
},
"active": true,
"name": "foo",
"entry": "@weekly",
"created_at": 1683154980,
"created_by": "octocat",
"updated_at": 1683154980,
"updated_by": "octocat",
"scheduled_at": 0,
"branch": "main",
"error": "error message",
"next_run": 0
}`
SchedulesResp = `[
{
"id": 2,
"repo": {
"id": 1,
"owner": {
"id": 1,
"name": "octocat",
"favorites": [],
"active": true,
"admin": false
},
"org": "github",
"counter": 10,
"name": "octocat",
"full_name": "github/octocat",
"link": "https://github.com/github/octocat",
"clone": "https://github.com/github/octocat",
"branch": "main",
"build_limit": 10,
"timeout": 60,
"visibility": "public",
"private": false,
"trusted": true,
"pipeline_type": "yaml",
"topics": [],
"active": true,
"allow_events": {
"push": {
"branch": true,
"tag": true
},
"pull_request": {
"opened": true,
"synchronize": true,
"reopened": true,
"edited": false
},
"deployment": {
"created": true
},
"comment": {
"created": false,
"edited": false
}
},
"approve_build": "fork-always",
"previous_name": ""
},
"active": true,
"name": "foo",
"entry": "@weekly",
"created_at": 1683154980,
"created_by": "octocat",
"updated_at": 1683154980,
"updated_by": "octocat",
"scheduled_at": 0,
"branch": "main",
"error": "error message",
"next_run": 0
},
{
"id": 1,
"repo": {
"id": 1,
"owner": {
"id": 1,
"name": "octocat",
"favorites": [],
"active": true,
"admin": false
},
"org": "github",
"counter": 10,
"name": "octocat",
"full_name": "github/octocat",
"link": "https://github.com/github/octocat",
"clone": "https://github.com/github/octocat",
"branch": "main",
"build_limit": 10,
"timeout": 60,
"visibility": "public",
"private": false,
"trusted": true,
"pipeline_type": "yaml",
"topics": [],
"active": true,
"allow_events": {
"push": {
"branch": true,
"tag": true
},
"pull_request": {
"opened": true,
"synchronize": true,
"reopened": true,
"edited": false
},
"deployment": {
"created": true
},
"comment": {
"created": false,
"edited": false
}
},
"approve_build": "fork-always",
"previous_name": ""
},
"active": true,
"name": "bar",
"entry": "@weekly",
"created_at": 1683154974,
"created_by": "octocat",
"updated_at": 1683154974,
"updated_by": "octocat",
"scheduled_at": 0,
"repo_id": 1,
"branch": "main",
"error": "error message",
"next_run": 0
}]`
)
// getSchedules returns mock JSON for a http GET.
func getSchedules(c *gin.Context) {
data := []byte(SchedulesResp)
var body []api.Schedule
_ = json.Unmarshal(data, &body)
c.JSON(http.StatusOK, body)
}
// getSchedule has a param :schedule returns mock JSON for a http GET.
//
// Pass "not-found" to :schedule to test receiving a http 404 response.
func getSchedule(c *gin.Context) {
s := c.Param("schedule")
if strings.Contains(s, "not-found") {
msg := fmt.Sprintf("Schedule %s does not exist", s)
c.AbortWithStatusJSON(http.StatusNotFound, types.Error{Message: &msg})
return
}
data := []byte(ScheduleResp)
var body api.Schedule
_ = json.Unmarshal(data, &body)
c.JSON(http.StatusOK, body)
}
// addSchedule returns mock JSON for a http POST.
func addSchedule(c *gin.Context) {
data := []byte(ScheduleResp)
var body api.Schedule
_ = json.Unmarshal(data, &body)
c.JSON(http.StatusCreated, body)
}
// updateSchedule has a param :schedule returns mock JSON for a http PUT.
//
// Pass "not-found" to :schedule to test receiving a http 404 response.
func updateSchedule(c *gin.Context) {
if !strings.Contains(c.FullPath(), "admin") {
s := c.Param("schedule")
if strings.Contains(s, "not-found") {
msg := fmt.Sprintf("Schedule %s does not exist", s)
c.AbortWithStatusJSON(http.StatusNotFound, types.Error{Message: &msg})
return
}
}
data := []byte(ScheduleResp)
var body api.Schedule
_ = json.Unmarshal(data, &body)
c.JSON(http.StatusOK, body)
}
// removeSchedule has a param :schedule returns mock JSON for a http DELETE.
//
// Pass "not-found" to :schedule to test receiving a http 404 response.
func removeSchedule(c *gin.Context) {
s := c.Param("schedule")
if strings.Contains(s, "not-found") {
msg := fmt.Sprintf("Schedule %s does not exist", s)
c.AbortWithStatusJSON(http.StatusNotFound, types.Error{Message: &msg})
return
}
c.JSON(http.StatusOK, fmt.Sprintf("schedule %s deleted", s))
}
Check failure on line 84 in mock/server/authentication.go
github-actions / golangci
[golangci] mock/server/authentication.go#L84
string `error` has 4 occurrences, make it a constant (goconst)
Raw output
mock/server/authentication.go:84:9: string `error` has 4 occurrences, make it a constant (goconst)
err := "error"
^
Check failure on line 45 in secret/vault/refresh_test.go
github-actions / golangci
[golangci] secret/vault/refresh_test.go#L45
unused-parameter: parameter 'r' seems to be unused, consider removing or renaming it as _ (revive)
Raw output
secret/vault/refresh_test.go:45:74: unused-parameter: parameter 'r' seems to be unused, consider removing or renaming it as _ (revive)
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
^
Check failure on line 71 in secret/vault/refresh_test.go
github-actions / golangci
[golangci] secret/vault/refresh_test.go#L71
unused-parameter: parameter 'in' seems to be unused, consider removing or renaming it as _ (revive)
Raw output
secret/vault/refresh_test.go:71:40: unused-parameter: parameter 'in' seems to be unused, consider removing or renaming it as _ (revive)
mockGetCallerIdentityRequest: func(in *sts.GetCallerIdentityInput) (*request.Request, *sts.GetCallerIdentityOutput) {
^
Check failure on line 108 in secret/vault/refresh_test.go
github-actions / golangci
[golangci] secret/vault/refresh_test.go#L108
unused-parameter: parameter 'in' seems to be unused, consider removing or renaming it as _ (revive)
Raw output
secret/vault/refresh_test.go:108:40: unused-parameter: parameter 'in' seems to be unused, consider removing or renaming it as _ (revive)
mockGetCallerIdentityRequest: func(in *sts.GetCallerIdentityInput) (*request.Request, *sts.GetCallerIdentityOutput) {
^
Check failure on line 128 in secret/vault/refresh_test.go
github-actions / golangci
[golangci] secret/vault/refresh_test.go#L128
unused-parameter: parameter 'in' seems to be unused, consider removing or renaming it as _ (revive)
Raw output
secret/vault/refresh_test.go:128:40: unused-parameter: parameter 'in' seems to be unused, consider removing or renaming it as _ (revive)
mockGetCallerIdentityRequest: func(in *sts.GetCallerIdentityInput) (*request.Request, *sts.GetCallerIdentityOutput) {
^
Check failure on line 201 in secret/vault/refresh_test.go
github-actions / golangci
[golangci] secret/vault/refresh_test.go#L201
unused-parameter: parameter 'r' seems to be unused, consider removing or renaming it as _ (revive)
Raw output
secret/vault/refresh_test.go:201:74: unused-parameter: parameter 'r' seems to be unused, consider removing or renaming it as _ (revive)
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
^
Check failure on line 3 in database/step/create.go
github-actions / golangci
[golangci] database/step/create.go#L3
3-41 lines are duplicate of `database/step/update.go:3-41` (dupl)
Raw output
database/step/create.go:3: 3-41 lines are duplicate of `database/step/update.go:3-41` (dupl)
package step
import (
"context"
"github.com/sirupsen/logrus"
"github.com/go-vela/types/constants"
"github.com/go-vela/types/database"
"github.com/go-vela/types/library"
)
// CreateStep creates a new step in the database.
func (e *engine) CreateStep(ctx context.Context, s *library.Step) (*library.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)
// 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
}
// send query to the database
result := e.client.
WithContext(ctx).
Table(constants.TableStep).
Create(step)
return step.ToLibrary(), result.Error
}
Check failure on line 3 in database/step/update.go
github-actions / golangci
[golangci] database/step/update.go#L3
3-41 lines are duplicate of `database/step/create.go:3-41` (dupl)
Raw output
database/step/update.go:3: 3-41 lines are duplicate of `database/step/create.go:3-41` (dupl)
package step
import (
"context"
"github.com/sirupsen/logrus"
"github.com/go-vela/types/constants"
"github.com/go-vela/types/database"
"github.com/go-vela/types/library"
)
// UpdateStep updates an existing step in the database.
func (e *engine) UpdateStep(ctx context.Context, s *library.Step) (*library.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)
// 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
}
// send query to the database
result := e.client.
WithContext(ctx).
Table(constants.TableStep).
Save(step)
return step.ToLibrary(), result.Error
}