Merge branch 'main' into fix/dashboards #13898
reviewdog [golangci] report
reported by reviewdog 🐶
Findings (29)
database/log/count.go|12 col 28| unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
database/log/index.go|19 col 35| unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
database/log/get_step.go|15 col 32| unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
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/deployment/create.go|3| 3-34 lines are duplicate of database/deployment/update.go:3-34
(dupl)
database/deployment/update.go|3| 3-34 lines are duplicate of database/deployment/create.go:3-34
(dupl)
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/resource.go|34 col 23| Non-inherited new context, use function like context.WithXXX
instead (contextcheck)
database/resource.go|45 col 20| Non-inherited new context, use function like context.WithXXX
instead (contextcheck)
scm/github/authentication.go|59 col 52| unused-parameter: parameter 'w' seems to be unused, consider removing or renaming it as _ (revive)
scm/github/access.go|34 col 28| Function newClientToken
should pass the context parameter (contextcheck)
scm/github/access.go|103 col 28| Function newClientToken
should pass the context parameter (contextcheck)
scm/github/access.go|153 col 28| Function newClientToken
should pass the context parameter (contextcheck)
compiler/native/expand.go|47| Function 'ExpandSteps' has too many statements (77 > 70) (funlen)
compiler/template/starlark/starlark.go|131 col 4| only one cuddle assignment allowed before if statement (wsl)
api/pipeline/validate.go|78| 78-109 lines are duplicate of api/pipeline/compile.go:80-111
(dupl)
api/pipeline/validate.go|3| 3-109 lines are duplicate of api/pipeline/expand.go:4-111
(dupl)
database/pipeline/create.go|3| 3-54 lines are duplicate of database/pipeline/update.go:3-55
(dupl)
database/pipeline/update.go|3| 3-55 lines are duplicate of database/pipeline/create.go:3-54
(dupl)
database/worker/create.go|3| 3-38 lines are duplicate of database/worker/update.go:3-38
(dupl)
database/worker/update.go|3| 3-38 lines are duplicate of database/worker/create.go:3-38
(dupl)
mock/server/schedule.go|3| 3-284 lines are duplicate of mock/server/secret.go:4-181
(dupl)
mock/server/authentication.go|81 col 9| string error
has 4 occurrences, make it a constant (goconst)
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 12 in database/log/count.go
github-actions / golangci
[golangci] database/log/count.go#L12
unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
Raw output
database/log/count.go:12:28: unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
func (e *engine) CountLogs(ctx context.Context) (int64, error) {
^
Check failure on line 19 in database/log/index.go
github-actions / golangci
[golangci] database/log/index.go#L19
unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
Raw output
database/log/index.go:19:35: unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
func (e *engine) CreateLogIndexes(ctx context.Context) error {
^
Check failure on line 15 in database/log/get_step.go
github-actions / golangci
[golangci] database/log/get_step.go#L15
unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
Raw output
database/log/get_step.go:15:32: unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
func (e *engine) GetLogForStep(ctx context.Context, s *library.Step) (*library.Log, 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/deployment/create.go
github-actions / golangci
[golangci] database/deployment/create.go#L3
3-34 lines are duplicate of `database/deployment/update.go:3-34` (dupl)
Raw output
database/deployment/create.go:3: 3-34 lines are duplicate of `database/deployment/update.go:3-34` (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.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
github-actions / golangci
[golangci] database/deployment/update.go#L3
3-34 lines are duplicate of `database/deployment/create.go:3-34` (dupl)
Raw output
database/deployment/update.go:3: 3-34 lines are duplicate of `database/deployment/create.go:3-34` (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.Table(constants.TableDeployment).Save(deployment)
// send query to the database
return deployment.ToLibrary(d.Builds), result.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 34 in database/resource.go
github-actions / golangci
[golangci] database/resource.go#L34
Non-inherited new context, use function like `context.WithXXX` instead (contextcheck)
Raw output
database/resource.go:34:23: Non-inherited new context, use function like `context.WithXXX` instead (contextcheck)
settings.WithContext(e.ctx),
^
Check failure on line 45 in database/resource.go
github-actions / golangci
[golangci] database/resource.go#L45
Non-inherited new context, use function like `context.WithXXX` instead (contextcheck)
Raw output
database/resource.go:45:20: Non-inherited new context, use function like `context.WithXXX` instead (contextcheck)
build.WithContext(e.ctx),
^
Check failure on line 59 in scm/github/authentication.go
github-actions / golangci
[golangci] scm/github/authentication.go#L59
unused-parameter: parameter 'w' seems to be unused, consider removing or renaming it as _ (revive)
Raw output
scm/github/authentication.go:59:52: unused-parameter: parameter 'w' seems to be unused, consider removing or renaming it as _ (revive)
func (c *client) Authenticate(ctx context.Context, w http.ResponseWriter, r *http.Request, oAuthState string) (*api.User, error) {
^
Check failure on line 34 in scm/github/access.go
github-actions / golangci
[golangci] scm/github/access.go#L34
Function `newClientToken` should pass the context parameter (contextcheck)
Raw output
scm/github/access.go:34:28: Function `newClientToken` should pass the context parameter (contextcheck)
client := c.newClientToken(*u.Token)
^
Check failure on line 103 in scm/github/access.go
github-actions / golangci
[golangci] scm/github/access.go#L103
Function `newClientToken` should pass the context parameter (contextcheck)
Raw output
scm/github/access.go:103:28: Function `newClientToken` should pass the context parameter (contextcheck)
client := c.newClientToken(u.GetToken())
^
Check failure on line 153 in scm/github/access.go
github-actions / golangci
[golangci] scm/github/access.go#L153
Function `newClientToken` should pass the context parameter (contextcheck)
Raw output
scm/github/access.go:153:28: Function `newClientToken` should pass the context parameter (contextcheck)
client := c.newClientToken(u.GetToken())
^
Check failure on line 47 in compiler/native/expand.go
github-actions / golangci
[golangci] compiler/native/expand.go#L47
Function 'ExpandSteps' has too many statements (77 > 70) (funlen)
Raw output
compiler/native/expand.go:47: Function 'ExpandSteps' has too many statements (77 > 70) (funlen)
func (c *client) ExpandSteps(s *yaml.Build, tmpls map[string]*yaml.Template, r *pipeline.RuleData, depth int) (*yaml.Build, error) {
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 78 in api/pipeline/validate.go
github-actions / golangci
[golangci] api/pipeline/validate.go#L78
78-109 lines are duplicate of `api/pipeline/compile.go:80-111` (dupl)
Raw output
api/pipeline/validate.go:78: 78-109 lines are duplicate of `api/pipeline/compile.go:80-111` (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)
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(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-109 lines are duplicate of `api/pipeline/expand.go:4-111` (dupl)
Raw output
api/pipeline/validate.go:3: 3-109 lines are duplicate of `api/pipeline/expand.go:4-111` (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)
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(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/pipeline/create.go
github-actions / golangci
[golangci] database/pipeline/create.go#L3
3-54 lines are duplicate of `database/pipeline/update.go:3-55` (dupl)
Raw output
database/pipeline/create.go:3: 3-54 lines are duplicate of `database/pipeline/update.go:3-55` (dupl)
package pipeline
import (
"context"
"github.com/sirupsen/logrus"
"github.com/go-vela/types/constants"
"github.com/go-vela/types/database"
"github.com/go-vela/types/library"
)
// CreatePipeline creates a new pipeline in the database.
func (e *engine) CreatePipeline(ctx context.Context, p *library.Pipeline) (*library.Pipeline, error) {
e.logger.WithFields(logrus.Fields{
"pipeline": p.GetCommit(),
}).Tracef("creating pipeline %s in the database", p.GetCommit())
// cast the library type to database type
//
// https://pkg.go.dev/github.com/go-vela/types/database#PipelineFromLibrary
pipeline := database.PipelineFromLibrary(p)
// validate the necessary fields are populated
//
// https://pkg.go.dev/github.com/go-vela/types/database#Pipeline.Validate
err := pipeline.Validate()
if err != nil {
return nil, err
}
// compress data for the pipeline
//
// https://pkg.go.dev/github.com/go-vela/types/database#Pipeline.Compress
err = pipeline.Compress(e.config.CompressionLevel)
if err != nil {
return nil, err
}
// send query to the database
err = e.client.Table(constants.TablePipeline).Create(pipeline).Error
if err != nil {
return nil, err
}
err = pipeline.Decompress()
if err != nil {
return nil, err
}
return pipeline.ToLibrary(), nil
}
Check failure on line 3 in database/pipeline/update.go
github-actions / golangci
[golangci] database/pipeline/update.go#L3
3-55 lines are duplicate of `database/pipeline/create.go:3-54` (dupl)
Raw output
database/pipeline/update.go:3: 3-55 lines are duplicate of `database/pipeline/create.go:3-54` (dupl)
package pipeline
import (
"context"
"github.com/sirupsen/logrus"
"github.com/go-vela/types/constants"
"github.com/go-vela/types/database"
"github.com/go-vela/types/library"
)
// UpdatePipeline updates an existing pipeline in the database.
func (e *engine) UpdatePipeline(ctx context.Context, p *library.Pipeline) (*library.Pipeline, error) {
e.logger.WithFields(logrus.Fields{
"pipeline": p.GetCommit(),
}).Tracef("updating pipeline %s in the database", p.GetCommit())
// cast the library type to database type
//
// https://pkg.go.dev/github.com/go-vela/types/database#PipelineFromLibrary
pipeline := database.PipelineFromLibrary(p)
// validate the necessary fields are populated
//
// https://pkg.go.dev/github.com/go-vela/types/database#Pipeline.Validate
err := pipeline.Validate()
if err != nil {
return nil, err
}
// compress data for the pipeline
//
// https://pkg.go.dev/github.com/go-vela/types/database#Pipeline.Compress
err = pipeline.Compress(e.config.CompressionLevel)
if err != nil {
return nil, err
}
// send query to the database
err = e.client.Table(constants.TablePipeline).Save(pipeline).Error
if err != nil {
return nil, err
}
// decompress pipeline to return
err = pipeline.Decompress()
if err != nil {
return nil, err
}
return pipeline.ToLibrary(), nil
}
Check failure on line 3 in database/worker/create.go
github-actions / golangci
[golangci] database/worker/create.go#L3
3-38 lines are duplicate of `database/worker/update.go:3-38` (dupl)
Raw output
database/worker/create.go:3: 3-38 lines are duplicate of `database/worker/update.go:3-38` (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.Table(constants.TableWorker).Create(worker)
return worker.ToAPI(w.GetRunningBuilds()), result.Error
}