Skip to content

chore(deps): update all non-major dependencies #14389

chore(deps): update all non-major dependencies

chore(deps): update all non-major dependencies #14389

GitHub Actions / golangci failed Sep 19, 2024 in 1s

reviewdog [golangci] report

reported by reviewdog 🐶

Findings (46)

database/deployment/list.go|33| 33-63 lines are duplicate of database/deployment/list_repo.go:46-76 (dupl)
database/deployment/list_repo.go|46| 46-76 lines are duplicate of database/deployment/list.go:33-63 (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/deployment/get.go|32 col 15| SA1019: library.Build is deprecated: use Build from github.com/go-vela/server/api/types instead. (staticcheck)
database/deployment/get_repo.go|40 col 15| SA1019: library.Build is deprecated: use Build from github.com/go-vela/server/api/types instead. (staticcheck)
database/deployment/list.go|37 col 16| SA1019: library.Build is deprecated: use Build from github.com/go-vela/server/api/types instead. (staticcheck)
api/webhook/post.go|193 col 32| Non-inherited new context, use function like context.WithXXX instead (contextcheck)
api/webhook/post.go|662 col 38| Non-inherited new context, use function like context.WithXXX instead (contextcheck)
api/webhook/post.go|673 col 40| Non-inherited new context, use function like context.WithXXX instead (contextcheck)
database/resource.go|29 col 31| unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
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)
router/middleware/logger.go|48 col 36| unused-parameter: parameter 'timeFormat' seems to be unused, consider removing or renaming it as _ (revive)
scm/github/webhook.go|87 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)
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/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)
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/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)
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)
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)
database/types/build.go|375 col 44| G115: integer overflow conversion int -> int32 (gosec)
database/types/build.go|376 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)
compiler/native/compile.go|329 col 26| Function modifyConfig should pass the context parameter (contextcheck)
compiler/native/compile.go|424 col 26| Function modifyConfig should pass the context parameter (contextcheck)
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)
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)
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 33 in database/deployment/list.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] database/deployment/list.go#L33

33-63 lines are duplicate of `database/deployment/list_repo.go:46-76` (dupl)
Raw output
database/deployment/list.go:33: 33-63 lines are duplicate of `database/deployment/list_repo.go:46-76` (dupl)
	for _, deployment := range *d {
		// https://golang.org/doc/faq#closures_and_goroutines
		tmp := deployment

		builds := []*library.Build{}

		for _, a := range tmp.Builds {
			bID, err := strconv.ParseInt(a, 10, 64)
			if err != nil {
				return nil, err
			}
			// variable to store query results
			b := new(database.Build)

			// send query to the database and store result in variable
			err = e.client.
				WithContext(ctx).
				Table(constants.TableBuild).
				Where("id = ?", bID).
				Take(b).
				Error
			if err != nil {
				return nil, err
			}

			builds = append(builds, b.ToLibrary())
		}

		// convert query result to library type
		deployments = append(deployments, tmp.ToLibrary(builds))
	}

Check failure on line 46 in database/deployment/list_repo.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] database/deployment/list_repo.go#L46

46-76 lines are duplicate of `database/deployment/list.go:33-63` (dupl)
Raw output
database/deployment/list_repo.go:46: 46-76 lines are duplicate of `database/deployment/list.go:33-63` (dupl)
	for _, deployment := range *d {
		// https://golang.org/doc/faq#closures_and_goroutines
		tmp := deployment

		builds := []*library.Build{}

		for _, a := range tmp.Builds {
			bID, err := strconv.ParseInt(a, 10, 64)
			if err != nil {
				return nil, err
			}
			// variable to store query results
			b := new(database.Build)

			// send query to the database and store result in variable
			err = e.client.
				WithContext(ctx).
				Table(constants.TableBuild).
				Where("id = ?", bID).
				Take(b).
				Error
			if err != nil {
				return nil, err
			}

			builds = append(builds, b.ToLibrary())
		}

		// convert query result to library type
		deployments = append(deployments, tmp.ToLibrary(builds))
	}

Check failure on line 3 in database/deployment/create.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] database/deployment/create.go#L3

3-37 lines are duplicate of `database/deployment/update.go:3-37` (dupl)
Raw output
database/deployment/create.go:3: 3-37 lines are duplicate of `database/deployment/update.go:3-37` (dupl)
package deployment

import (
	"context"

	"github.com/sirupsen/logrus"

	"github.com/go-vela/types/constants"
	"github.com/go-vela/types/database"
	"github.com/go-vela/types/library"
)

// CreateDeployment creates a new deployment in the database.
func (e *engine) CreateDeployment(ctx context.Context, d *library.Deployment) (*library.Deployment, error) {
	e.logger.WithFields(logrus.Fields{
		"deployment": d.GetID(),
	}).Tracef("creating deployment %d", d.GetID())

	// cast the library type to database type
	deployment := database.DeploymentFromLibrary(d)

	// validate the necessary fields are populated
	err := deployment.Validate()
	if err != nil {
		return nil, err
	}

	result := e.client.
		WithContext(ctx).
		Table(constants.TableDeployment).
		Create(deployment)

	// send query to the database
	return deployment.ToLibrary(d.Builds), result.Error
}

Check failure on line 3 in database/deployment/update.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] database/deployment/update.go#L3

3-37 lines are duplicate of `database/deployment/create.go:3-37` (dupl)
Raw output
database/deployment/update.go:3: 3-37 lines are duplicate of `database/deployment/create.go:3-37` (dupl)
package deployment

import (
	"context"

	"github.com/sirupsen/logrus"

	"github.com/go-vela/types/constants"
	"github.com/go-vela/types/database"
	"github.com/go-vela/types/library"
)

// UpdateDeployment updates an existing deployment in the database.
func (e *engine) UpdateDeployment(ctx context.Context, d *library.Deployment) (*library.Deployment, error) {
	e.logger.WithFields(logrus.Fields{
		"deployment": d.GetID(),
	}).Tracef("updating deployment %d", d.GetID())

	// cast the library type to database type
	deployment := database.DeploymentFromLibrary(d)

	// validate the necessary fields are populated
	err := deployment.Validate()
	if err != nil {
		return nil, err
	}

	result := e.client.
		WithContext(ctx).
		Table(constants.TableDeployment).
		Save(deployment)

	// send query to the database
	return deployment.ToLibrary(d.Builds), result.Error
}

Check failure on line 32 in database/deployment/get.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] database/deployment/get.go#L32

SA1019: library.Build is deprecated: use Build from github.com/go-vela/server/api/types instead. (staticcheck)
Raw output
database/deployment/get.go:32:15: SA1019: library.Build is deprecated: use Build from github.com/go-vela/server/api/types instead. (staticcheck)
	builds := []*library.Build{}
	             ^

Check failure on line 40 in database/deployment/get_repo.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] database/deployment/get_repo.go#L40

SA1019: library.Build is deprecated: use Build from github.com/go-vela/server/api/types instead. (staticcheck)
Raw output
database/deployment/get_repo.go:40:15: SA1019: library.Build is deprecated: use Build from github.com/go-vela/server/api/types instead. (staticcheck)
	builds := []*library.Build{}
	             ^

Check failure on line 37 in database/deployment/list.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] database/deployment/list.go#L37

SA1019: library.Build is deprecated: use Build from github.com/go-vela/server/api/types instead. (staticcheck)
Raw output
database/deployment/list.go:37:16: SA1019: library.Build is deprecated: use Build from github.com/go-vela/server/api/types instead. (staticcheck)
		builds := []*library.Build{}
		             ^

Check failure on line 193 in api/webhook/post.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] api/webhook/post.go#L193

Non-inherited new context, use function like `context.WithXXX` instead (contextcheck)
Raw output
api/webhook/post.go:193:32: Non-inherited new context, use function like `context.WithXXX` instead (contextcheck)
		_, err = database.FromContext(c).UpdateHook(ctx, h)
		                             ^

Check failure on line 662 in api/webhook/post.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] api/webhook/post.go#L662

Non-inherited new context, use function like `context.WithXXX` instead (contextcheck)
Raw output
api/webhook/post.go:662:38: Non-inherited new context, use function like `context.WithXXX` instead (contextcheck)
		dbRepo, err := database.FromContext(c).GetRepoForOrg(ctx, r.GetOrg(), r.GetName())
		                                   ^

Check failure on line 673 in api/webhook/post.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] api/webhook/post.go#L673

Non-inherited new context, use function like `context.WithXXX` instead (contextcheck)
Raw output
api/webhook/post.go:673:40: Non-inherited new context, use function like `context.WithXXX` instead (contextcheck)
		lastHook, err := database.FromContext(c).LastHookForRepo(ctx, dbRepo)
		                                     ^

Check failure on line 29 in database/resource.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] database/resource.go#L29

unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
Raw output
database/resource.go:29:31: unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
func (e *engine) NewResources(ctx context.Context) error {
                              ^

Check failure on line 44 in compiler/template/starlark/render.go

See this annotation in the file changed.

@github-actions 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

See this annotation in the file changed.

@github-actions 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

See this annotation in the file changed.

@github-actions 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 48 in router/middleware/logger.go

See this annotation in the file changed.

@github-actions 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 87 in scm/github/webhook.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] scm/github/webhook.go#L87

unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
Raw output
scm/github/webhook.go:87: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

See this annotation in the file changed.

@github-actions 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 3 in database/step/create.go

See this annotation in the file changed.

@github-actions 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

See this annotation in the file changed.

@github-actions 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
}

Check failure on line 3 in database/worker/create.go

See this annotation in the file changed.

@github-actions 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

See this annotation in the file changed.

@github-actions 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 database/hook/get.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] database/hook/get.go#L3

3-40 lines are duplicate of `database/hook/get_webhook.go:3-40` (dupl)
Raw output
database/hook/get.go:3: 3-40 lines are duplicate of `database/hook/get_webhook.go:3-40` (dupl)
package hook

import (
	"context"

	api "github.com/go-vela/server/api/types"
	"github.com/go-vela/server/constants"
	"github.com/go-vela/server/database/types"
)

// GetHook gets a hook by ID from the database.
func (e *engine) GetHook(ctx context.Context, id int64) (*api.Hook, error) {
	e.logger.Tracef("getting hook %d", id)

	// variable to store query results
	h := new(types.Hook)

	// send query to the database and store result in variable
	err := e.client.
		WithContext(ctx).
		Table(constants.TableHook).
		Preload("Repo").
		Preload("Repo.Owner").
		Preload("Build").
		Where("id = ?", id).
		Take(h).
		Error
	if err != nil {
		return nil, err
	}

	err = h.Repo.Decrypt(e.config.EncryptionKey)
	if err != nil {
		e.logger.Errorf("unable to decrypt repo for hook %d: %v", h.ID.Int64, err)
	}

	return h.ToAPI(), nil
}

Check failure on line 3 in database/hook/get_webhook.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] database/hook/get_webhook.go#L3

3-40 lines are duplicate of `database/hook/get.go:3-40` (dupl)
Raw output
database/hook/get_webhook.go:3: 3-40 lines are duplicate of `database/hook/get.go:3-40` (dupl)
package hook

import (
	"context"

	api "github.com/go-vela/server/api/types"
	"github.com/go-vela/server/constants"
	"github.com/go-vela/server/database/types"
)

// GetHookByWebhookID gets a single hook with a matching webhook id in the database.
func (e *engine) GetHookByWebhookID(ctx context.Context, webhookID int64) (*api.Hook, error) {
	e.logger.Tracef("getting a hook with webhook id %d", webhookID)

	// variable to store query results
	h := new(types.Hook)

	// send query to the database and store result in variable
	err := e.client.
		WithContext(ctx).
		Table(constants.TableHook).
		Preload("Repo").
		Preload("Repo.Owner").
		Preload("Build").
		Where("webhook_id = ?", webhookID).
		Take(h).
		Error
	if err != nil {
		return nil, err
	}

	err = h.Repo.Decrypt(e.config.EncryptionKey)
	if err != nil {
		e.logger.Errorf("unable to decrypt repo for hook %d: %v", h.ID.Int64, err)
	}

	return h.ToAPI(), nil
}

Check failure on line 3 in database/hook/create.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] database/hook/create.go#L3

3-39 lines are duplicate of `database/hook/update.go:3-42` (dupl)
Raw output
database/hook/create.go:3: 3-39 lines are duplicate of `database/hook/update.go:3-42` (dupl)
package hook

import (
	"context"

	"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"
)

// CreateHook creates a new hook in the database.
func (e *engine) CreateHook(ctx context.Context, h *api.Hook) (*api.Hook, error) {
	e.logger.WithFields(logrus.Fields{
		"hook": h.GetNumber(),
	}).Tracef("creating hook %d", h.GetNumber())

	hook := types.HookFromAPI(h)

	err := hook.Validate()
	if err != nil {
		return nil, err
	}

	// send query to the database
	err = e.client.WithContext(ctx).Table(constants.TableHook).Create(hook).Error
	if err != nil {
		return nil, err
	}

	result := hook.ToAPI()
	result.SetRepo(h.GetRepo())
	result.SetBuild(h.GetBuild())

	return result, nil
}

Check failure on line 3 in database/hook/update.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] database/hook/update.go#L3

3-42 lines are duplicate of `database/hook/create.go:3-39` (dupl)
Raw output
database/hook/update.go:3: 3-42 lines are duplicate of `database/hook/create.go:3-39` (dupl)
package hook

import (
	"context"

	"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"
)

// UpdateHook updates an existing hook in the database.
func (e *engine) UpdateHook(ctx context.Context, h *api.Hook) (*api.Hook, error) {
	e.logger.WithFields(logrus.Fields{
		"hook": h.GetNumber(),
	}).Tracef("updating hook %d", h.GetNumber())

	hook := types.HookFromAPI(h)

	// validate the necessary fields are populated
	//
	// https://pkg.go.dev/github.com/go-vela/types/database#Hook.Validate
	err := hook.Validate()
	if err != nil {
		return nil, err
	}

	// send query to the database
	err = e.client.WithContext(ctx).Table(constants.TableHook).Save(hook).Error
	if err != nil {
		return nil, err
	}

	result := hook.ToAPI()
	result.SetRepo(h.GetRepo())
	result.SetBuild(h.GetBuild())

	return result, nil
}