gci #14495
reviewdog [golangci] report
reported by reviewdog 🐶
Findings (46)
compiler/registry/github/template.go|39 col 52| Non-inherited new context, use function like context.WithXXX
instead (contextcheck)
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)
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)
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/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)
scm/github/authentication.go|36 col 24| unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
scm/github/authentication.go|133 col 37| unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
scm/github/webhook.go|86 col 32| 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)
compiler/types/pipeline/ruleset.go|134 col 1| cyclomatic complexity 31 of func (*Rules).Match
is high (> 30) (gocyclo)
compiler/types/yaml/stage.go|91 col 5| return statements should not be cuddled if block has more than two lines (wsl)
compiler/types/yaml/stage.go|97 col 2| return statements should not be cuddled if block has more than two lines (wsl)
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)
router/middleware/logger.go|48 col 36| unused-parameter: parameter 'timeFormat' seems to be unused, consider removing or renaming it as _ (revive)
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/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)
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/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)
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/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)
compiler/native/compile.go|334 col 26| Function modifyConfig
should pass the context parameter (contextcheck)
compiler/native/compile.go|429 col 26| Function modifyConfig
should pass the context parameter (contextcheck)
database/pipeline/create.go|3| 3-51 lines are duplicate of database/pipeline/update.go:3-52
(dupl)
database/pipeline/update.go|3| 3-52 lines are duplicate of database/pipeline/create.go:3-51
(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 39 in compiler/registry/github/template.go
github-actions / golangci
[golangci] compiler/registry/github/template.go#L39
Non-inherited new context, use function like `context.WithXXX` instead (contextcheck)
Raw output
compiler/registry/github/template.go:39:52: Non-inherited new context, use function like `context.WithXXX` instead (contextcheck)
data, _, resp, err := cli.Repositories.GetContents(context.Background(), s.Org, s.Repo, s.Name, opts)
^
Check failure on line 384 in database/types/build.go
github-actions / golangci
[golangci] database/types/build.go#L384
G115: integer overflow conversion int -> int32 (gosec)
Raw output
database/types/build.go:384:44: G115: integer overflow conversion int -> int32 (gosec)
Number: sql.NullInt32{Int32: int32(b.GetNumber()), Valid: true},
^
Check failure on line 385 in database/types/build.go
github-actions / golangci
[golangci] database/types/build.go#L385
G115: integer overflow conversion int -> int32 (gosec)
Raw output
database/types/build.go:385:44: G115: integer overflow conversion int -> int32 (gosec)
Parent: sql.NullInt32{Int32: int32(b.GetParent()), Valid: true},
^
Check failure on line 336 in database/types/repo.go
github-actions / golangci
[golangci] database/types/repo.go#L336
G115: integer overflow conversion int -> int32 (gosec)
Raw output
database/types/repo.go:336:43: G115: integer overflow conversion int -> int32 (gosec)
Counter: sql.NullInt32{Int32: int32(r.GetCounter()), Valid: true},
^
Check failure on line 134 in database/types/settings.go
github-actions / golangci
[golangci] database/types/settings.go#L134
G115: integer overflow conversion int64 -> uint64 (gosec)
Raw output
database/types/settings.go:134:35: G115: integer overflow conversion int64 -> uint64 (gosec)
psAPI.SetStarlarkExecLimit(uint64(ps.StarlarkExecLimit.Int64))
^
Check failure on line 205 in database/types/settings.go
github-actions / golangci
[golangci] database/types/settings.go#L205
G115: integer overflow conversion uint64 -> int64 (gosec)
Raw output
database/types/settings.go:205:49: G115: integer overflow conversion uint64 -> int64 (gosec)
StarlarkExecLimit: sql.NullInt64{Int64: int64(s.GetStarlarkExecLimit()), Valid: true},
^
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 78 in api/pipeline/validate.go
github-actions / golangci
[golangci] api/pipeline/validate.go#L78
78-110 lines are duplicate of `api/pipeline/compile.go:80-112` (dupl)
Raw output
api/pipeline/validate.go:78: 78-110 lines are duplicate of `api/pipeline/compile.go:80-112` (dupl)
func ValidatePipeline(c *gin.Context) {
// capture middleware values
m := c.MustGet("metadata").(*internal.Metadata)
l := c.MustGet("logger").(*logrus.Entry)
p := pipeline.Retrieve(c)
r := repo.Retrieve(c)
u := user.Retrieve(c)
ctx := c.Request.Context()
entry := fmt.Sprintf("%s/%s", r.GetFullName(), p.GetCommit())
l.Debugf("validating pipeline %s", entry)
// ensure we use the expected pipeline type when compiling
r.SetPipelineType(p.GetType())
// create the compiler object
compiler := compiler.FromContext(c).Duplicate().WithCommit(p.GetCommit()).WithMetadata(m).WithRepo(r).WithUser(u)
ruleData := prepareRuleData(c)
// validate the pipeline
pipeline, _, err := compiler.CompileLite(ctx, p.GetData(), ruleData, false)
if err != nil {
retErr := fmt.Errorf("unable to validate pipeline %s: %w", entry, err)
util.HandleError(c, http.StatusBadRequest, retErr)
return
}
writeOutput(c, pipeline)
}
Check failure on line 3 in api/pipeline/validate.go
github-actions / golangci
[golangci] api/pipeline/validate.go#L3
3-110 lines are duplicate of `api/pipeline/expand.go:4-112` (dupl)
Raw output
api/pipeline/validate.go:3: 3-110 lines are duplicate of `api/pipeline/expand.go:4-112` (dupl)
package pipeline
import (
"fmt"
"net/http"
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
"github.com/go-vela/server/compiler"
"github.com/go-vela/server/internal"
"github.com/go-vela/server/router/middleware/pipeline"
"github.com/go-vela/server/router/middleware/repo"
"github.com/go-vela/server/router/middleware/user"
"github.com/go-vela/server/util"
)
// swagger:operation POST /api/v1/pipelines/{org}/{repo}/{pipeline}/validate pipelines ValidatePipeline
//
// Get, expand and validate a pipeline
//
// ---
// produces:
// - application/yaml
// - application/json
// parameters:
// - in: path
// name: org
// description: Name of the organization
// required: true
// type: string
// - in: path
// name: repo
// description: Name of the repository
// required: true
// type: string
// - in: path
// name: pipeline
// description: Commit SHA for pipeline to retrieve
// required: true
// type: string
// - in: query
// name: output
// description: Output string for specifying output format
// type: string
// default: yaml
// enum:
// - json
// - yaml
// security:
// - ApiKeyAuth: []
// responses:
// '200':
// description: Successfully retrieved, expanded and validated the pipeline
// schema:
// type: string
// '400':
// description: Invalid request payload or path
// schema:
// "$ref": "#/definitions/Error"
// '401':
// description: Unauthorized
// schema:
// "$ref": "#/definitions/Error"
// '404':
// description: Not found
// schema:
// "$ref": "#/definitions/Error"
// '500':
// description: Unexpected server error
// schema:
// "$ref": "#/definitions/Error"
// ValidatePipeline represents the API handler to capture,
// expand and validate a pipeline configuration.
func ValidatePipeline(c *gin.Context) {
// capture middleware values
m := c.MustGet("metadata").(*internal.Metadata)
l := c.MustGet("logger").(*logrus.Entry)
p := pipeline.Retrieve(c)
r := repo.Retrieve(c)
u := user.Retrieve(c)
ctx := c.Request.Context()
entry := fmt.Sprintf("%s/%s", r.GetFullName(), p.GetCommit())
l.Debugf("validating pipeline %s", entry)
// ensure we use the expected pipeline type when compiling
r.SetPipelineType(p.GetType())
// create the compiler object
compiler := compiler.FromContext(c).Duplicate().WithCommit(p.GetCommit()).WithMetadata(m).WithRepo(r).WithUser(u)
ruleData := prepareRuleData(c)
// validate the pipeline
pipeline, _, err := compiler.CompileLite(ctx, p.GetData(), ruleData, false)
if err != nil {
retErr := fmt.Errorf("unable to validate pipeline %s: %w", entry, err)
util.HandleError(c, http.StatusBadRequest, retErr)
return
}
writeOutput(c, pipeline)
}
Check failure on line 3 in database/deployment/create.go
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"
api "github.com/go-vela/server/api/types"
"github.com/go-vela/server/database/types"
"github.com/go-vela/types/constants"
)
// CreateDeployment creates a new deployment in the database.
func (e *engine) CreateDeployment(ctx context.Context, d *api.Deployment) (*api.Deployment, error) {
e.logger.WithFields(logrus.Fields{
"deployment": d.GetID(),
}).Tracef("creating deployment %d", d.GetID())
// cast the library type to database type
deployment := types.DeploymentFromAPI(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.ToAPI(d.Builds), result.Error
}
Check failure on line 3 in database/deployment/update.go
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"
api "github.com/go-vela/server/api/types"
"github.com/go-vela/server/database/types"
"github.com/go-vela/types/constants"
)
// UpdateDeployment updates an existing deployment in the database.
func (e *engine) UpdateDeployment(ctx context.Context, d *api.Deployment) (*api.Deployment, error) {
e.logger.WithFields(logrus.Fields{
"deployment": d.GetID(),
}).Tracef("updating deployment %d", d.GetID())
// cast the library type to database type
deployment := types.DeploymentFromAPI(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.ToAPI(d.Builds), result.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 133 in scm/github/authentication.go
github-actions / golangci
[golangci] scm/github/authentication.go#L133
unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
Raw output
scm/github/authentication.go:133:37: unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
func (c *client) ValidateOAuthToken(ctx context.Context, token string) (bool, error) {
^
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 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 134 in compiler/types/pipeline/ruleset.go
github-actions / golangci
[golangci] compiler/types/pipeline/ruleset.go#L134
cyclomatic complexity 31 of func `(*Rules).Match` is high (> 30) (gocyclo)
Raw output
compiler/types/pipeline/ruleset.go:134:1: cyclomatic complexity 31 of func `(*Rules).Match` is high (> 30) (gocyclo)
func (r *Rules) Match(from *RuleData, matcher, op string) (bool, error) {
^
Check failure on line 91 in compiler/types/yaml/stage.go
github-actions / golangci
[golangci] compiler/types/yaml/stage.go#L91
return statements should not be cuddled if block has more than two lines (wsl)
Raw output
compiler/types/yaml/stage.go:91:5: return statements should not be cuddled if block has more than two lines (wsl)
return append(needs, "clone")
^
Check failure on line 97 in compiler/types/yaml/stage.go
github-actions / golangci
[golangci] compiler/types/yaml/stage.go#L97
return statements should not be cuddled if block has more than two lines (wsl)
Raw output
compiler/types/yaml/stage.go:97:2: return statements should not be cuddled if block has more than two lines (wsl)
return nil
^
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
}
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 3 in database/service/create.go
github-actions / golangci
[golangci] database/service/create.go#L3
3-41 lines are duplicate of `database/service/update.go:3-41` (dupl)
Raw output
database/service/create.go:3: 3-41 lines are duplicate of `database/service/update.go:3-41` (dupl)
package service
import (
"context"
"github.com/sirupsen/logrus"
"github.com/go-vela/types/constants"
"github.com/go-vela/types/database"
"github.com/go-vela/types/library"
)
// CreateService creates a new service in the database.
func (e *engine) CreateService(ctx context.Context, s *library.Service) (*library.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)
// 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
}
// send query to the database
result := e.client.
WithContext(ctx).
Table(constants.TableService).
Create(service)
return service.ToLibrary(), result.Error
}