Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: only convert commands query param when provided #1140

Merged
merged 2 commits into from
Jun 10, 2024

fix: lint

a50c531
Select commit
Loading
Failed to load commit list.
Sign in for the full log view
Merged

fix: only convert commands query param when provided #1140

fix: lint
a50c531
Select commit
Loading
Failed to load commit list.
GitHub Actions / golangci failed Jun 7, 2024 in 1s

reviewdog [golangci] report

reported by reviewdog 🐶

Findings (32)

database/dashboard/delete.go|16 col 34| unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
database/dashboard/table.go|46 col 39| unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
database/dashboard/get.go|14 col 31| unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
compiler/template/starlark/starlark.go|131 col 4| only one cuddle assignment allowed before if statement (wsl)
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)
router/middleware/logger.go|43 col 36| unused-parameter: parameter 'timeFormat' seems to be unused, consider removing or renaming it as _ (revive)
router/middleware/header.go|34 col 3| if statements should only be cuddled with assignments (wsl)
router/middleware/header.go|38 col 3| expressions should not be cuddled with blocks (wsl)
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)
database/resource.go|56 col 24| Non-inherited new context, use function like context.WithXXX instead (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)
compiler/native/expand.go|47| Function 'ExpandSteps' has too many statements (77 > 70) (funlen)
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)
api/pipeline/validate.go|3| 3-118 lines are duplicate of api/pipeline/expand.go:4-120 (dupl)
api/pipeline/validate.go|79| 79-118 lines are duplicate of api/pipeline/compile.go:81-120 (dupl)
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)
scm/github/repo.go|525 col 23| SA1019: client.Repositories.List is deprecated: Use RepositoriesService.ListByUser or RepositoriesService.ListByAuthenticatedUser instead. (staticcheck)
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)
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 16 in database/dashboard/delete.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] database/dashboard/delete.go#L16

unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
Raw output
database/dashboard/delete.go:16:34: unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
func (e *engine) DeleteDashboard(ctx context.Context, d *api.Dashboard) error {
                                 ^

Check failure on line 46 in database/dashboard/table.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] database/dashboard/table.go#L46

unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
Raw output
database/dashboard/table.go:46:39: unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
func (e *engine) CreateDashboardTable(ctx context.Context, driver string) error {
                                      ^

Check failure on line 14 in database/dashboard/get.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] database/dashboard/get.go#L14

unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
Raw output
database/dashboard/get.go:14:31: unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
func (e *engine) GetDashboard(ctx context.Context, id string) (*api.Dashboard, error) {
                              ^

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 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-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 in the database", 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
}

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-38 lines are duplicate of `database/worker/create.go:3-38` (dupl)
Raw output
database/worker/update.go:3: 3-38 lines are duplicate of `database/worker/create.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"
)

// 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 in the database", 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).Save(worker)

	return worker.ToAPI(w.GetRunningBuilds()), result.Error
}

Check failure on line 43 in router/middleware/logger.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] router/middleware/logger.go#L43

unused-parameter: parameter 'timeFormat' seems to be unused, consider removing or renaming it as _ (revive)
Raw output
router/middleware/logger.go:43: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 router/middleware/header.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] router/middleware/header.go#L34

if statements should only be cuddled with assignments (wsl)
Raw output
router/middleware/header.go:34:3: if statements should only be cuddled with assignments (wsl)
		if len(m.Vela.WebAddress) > 0 {
		^

Check failure on line 38 in router/middleware/header.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] router/middleware/header.go#L38

expressions should not be cuddled with blocks (wsl)
Raw output
router/middleware/header.go:38:3: expressions should not be cuddled with blocks (wsl)
		c.Header("Access-Control-Allow-Methods", "GET,POST,PUT,PATCH,DELETE,OPTIONS")
		^

Check failure on line 34 in database/resource.go

See this annotation in the file changed.

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

See this annotation in the file changed.

@github-actions 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 56 in database/resource.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] database/resource.go#L56

Non-inherited new context, use function like `context.WithXXX` instead (contextcheck)
Raw output
database/resource.go:56:24: Non-inherited new context, use function like `context.WithXXX` instead (contextcheck)
		dashboard.WithContext(e.ctx),
		                     ^

Check failure on line 45 in secret/vault/refresh_test.go

See this annotation in the file changed.

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

See this annotation in the file changed.

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

See this annotation in the file changed.

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

See this annotation in the file changed.

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

See this annotation in the file changed.

@github-actions 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 47 in compiler/native/expand.go

See this annotation in the file changed.

@github-actions 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 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-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 in the database", 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

See this annotation in the file changed.

@github-actions 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 in the database", 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 3 in api/pipeline/validate.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] api/pipeline/validate.go#L3

3-118 lines are duplicate of `api/pipeline/expand.go:4-120` (dupl)
Raw output
api/pipeline/validate.go:3: 3-118 lines are duplicate of `api/pipeline/expand.go:4-120` (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/org"
	"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)
	o := org.Retrieve(c)
	p := pipeline.Retrieve(c)
	r := repo.Retrieve(c)
	u := user.Retrieve(c)

	entry := fmt.Sprintf("%s/%s", r.GetFullName(), p.GetCommit())

	// update engine logger with API metadata
	//
	// https://pkg.go.dev/github.com/sirupsen/logrus?tab=doc#Entry.WithFields
	logrus.WithFields(logrus.Fields{
		"org":      o,
		"pipeline": p.GetCommit(),
		"repo":     r.GetName(),
		"user":     u.GetName(),
	}).Infof("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 79 in api/pipeline/validate.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] api/pipeline/validate.go#L79

79-118 lines are duplicate of `api/pipeline/compile.go:81-120` (dupl)
Raw output
api/pipeline/validate.go:79: 79-118 lines are duplicate of `api/pipeline/compile.go:81-120` (dupl)
func ValidatePipeline(c *gin.Context) {
	// capture middleware values
	m := c.MustGet("metadata").(*internal.Metadata)
	o := org.Retrieve(c)
	p := pipeline.Retrieve(c)
	r := repo.Retrieve(c)
	u := user.Retrieve(c)

	entry := fmt.Sprintf("%s/%s", r.GetFullName(), p.GetCommit())

	// update engine logger with API metadata
	//
	// https://pkg.go.dev/github.com/sirupsen/logrus?tab=doc#Entry.WithFields
	logrus.WithFields(logrus.Fields{
		"org":      o,
		"pipeline": p.GetCommit(),
		"repo":     r.GetName(),
		"user":     u.GetName(),
	}).Infof("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 59 in scm/github/authentication.go

See this annotation in the file changed.

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

See this annotation in the file changed.

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

See this annotation in the file changed.

@github-actions 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())
	                          ^