Skip to content
GitHub Actions / golangci failed Jun 5, 2024 in 1s

reviewdog [golangci] report

reported by reviewdog 🐶

Findings (40)

compiler/template/starlark/starlark.go|131 col 4| only one cuddle assignment allowed before if statement (wsl)
secret/vault/create.go|18 col 25| unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
secret/vault/count.go|17 col 24| 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/delete.go|16 col 25| unused-parameter: parameter 'ctx' 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)
mock/server/schedule.go|3| 3-284 lines are duplicate of mock/server/secret.go:4-181 (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)
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)
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)
api/pipeline/validate.go|3| 3-110 lines are duplicate of api/pipeline/expand.go:4-112 (dupl)
api/pipeline/validate.go|71| 71-110 lines are duplicate of api/pipeline/compile.go:73-112 (dupl)
database/testutils/api_resources.go|303 col 8| Error return value of jk.Set is not checked (errcheck)
database/jwk/list.go|36 col 16| Error return value of keySet.AddKey is not checked (errcheck)
database/jwk/list_test.go|57 col 16| Error return value of wantSet.AddKey is not checked (errcheck)
database/jwk/list_test.go|58 col 16| Error return value of wantSet.AddKey is not checked (errcheck)
database/integration_test.go|2579 col 15| Error return value of jwkSet.AddKey is not checked (errcheck)
database/integration_test.go|2580 col 15| Error return value of jwkSet.AddKey is not checked (errcheck)
internal/token/generate_rsa.go|42 col 8| Error return value of jk.Set is not checked (errcheck)
compiler/native/expand.go|47| Function 'ExpandSteps' has too many statements (77 > 70) (funlen)
mock/server/authentication.go|81 col 9| string error has 4 occurrences, make it a constant (goconst)
scm/github/authentication.go|59 col 52| unused-parameter: parameter 'w' seems to be unused, consider removing or renaming it as _ (revive)
router/middleware/logger.go|43 col 36| unused-parameter: parameter 'timeFormat' seems to be unused, consider removing or renaming it as _ (revive)
api/webhook/post.go|192 col 32| Non-inherited new context, use function like context.WithXXX instead (contextcheck)
api/webhook/post.go|534 col 38| Non-inherited new context, use function like context.WithXXX instead (contextcheck)
api/webhook/post.go|545 col 40| Non-inherited new context, use function like context.WithXXX instead (contextcheck)
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)
internal/token/generate_rsa.go|33 col 3| error is not nil (line 30) but it returns nil (nilerr)
scm/github/repo.go|525 col 23| SA1019: client.Repositories.List is deprecated: Use RepositoriesService.ListByUser or RepositoriesService.ListByAuthenticatedUser instead. (staticcheck)
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)
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 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 18 in secret/vault/create.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] secret/vault/create.go#L18

unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
Raw output
secret/vault/create.go:18:25: unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
func (c *client) Create(ctx context.Context, sType, org, name string, s *library.Secret) (*library.Secret, error) {
                        ^

Check failure on line 17 in secret/vault/count.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] secret/vault/count.go#L17

unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
Raw output
secret/vault/count.go:17:24: unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
func (c *client) Count(ctx context.Context, sType, org, name string, _ []string) (i int64, err error) {
                       ^

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 16 in secret/vault/delete.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] secret/vault/delete.go#L16

unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
Raw output
secret/vault/delete.go:16:25: unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
func (c *client) Delete(ctx context.Context, sType, org, name, path string) error {
                        ^

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 3 in mock/server/schedule.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] mock/server/schedule.go#L3

3-284 lines are duplicate of `mock/server/secret.go:4-181` (dupl)
Raw output
mock/server/schedule.go:3: 3-284 lines are duplicate of `mock/server/secret.go:4-181` (dupl)
package server

import (
	"encoding/json"
	"fmt"
	"net/http"
	"strings"

	"github.com/gin-gonic/gin"

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

const (
	// ScheduleResp represents a JSON return for a single schedule.
	ScheduleResp = `{
		"id": 2,
		"repo": {
			"id": 1,
			"owner": {
				"id": 1,
				"name": "octocat",
				"favorites": [],
				"active": true,
				"admin": false
			},
			"org": "github",
			"counter": 10,
			"name": "octocat",
			"full_name": "github/octocat",
			"link": "https://github.com/github/octocat",
			"clone": "https://github.com/github/octocat",
			"branch": "main",
			"build_limit": 10,
			"timeout": 60,
			"visibility": "public",
			"private": false,
			"trusted": true,
			"pipeline_type": "yaml",
			"topics": [],
			"active": true,
			"allow_events": {
				"push": {
					"branch": true,
					"tag": true
				},
				"pull_request": {
					"opened": true,
					"synchronize": true,
					"reopened": true,
					"edited": false
				},
				"deployment": {
					"created": true
				},
				"comment": {
					"created": false,
					"edited": false
				}
			},
			"approve_build": "fork-always",
			"previous_name": ""
		},
		"active": true,
		"name": "foo",
		"entry": "@weekly",
		"created_at": 1683154980,
		"created_by": "octocat",
		"updated_at": 1683154980,
		"updated_by": "octocat",
		"scheduled_at": 0,
		"branch": "main",
		"error": "error message",
		"next_run": 0
	}`
	SchedulesResp = `[
	{
		"id": 2,
		"repo": {
			"id": 1,
			"owner": {
				"id": 1,
				"name": "octocat",
				"favorites": [],
				"active": true,
				"admin": false
			},
			"org": "github",
			"counter": 10,
			"name": "octocat",
			"full_name": "github/octocat",
			"link": "https://github.com/github/octocat",
			"clone": "https://github.com/github/octocat",
			"branch": "main",
			"build_limit": 10,
			"timeout": 60,
			"visibility": "public",
			"private": false,
			"trusted": true,
			"pipeline_type": "yaml",
			"topics": [],
			"active": true,
			"allow_events": {
				"push": {
					"branch": true,
					"tag": true
				},
				"pull_request": {
					"opened": true,
					"synchronize": true,
					"reopened": true,
					"edited": false
				},
				"deployment": {
					"created": true
				},
				"comment": {
					"created": false,
					"edited": false
				}
			},
			"approve_build": "fork-always",
			"previous_name": ""
		},
		"active": true,
		"name": "foo",
		"entry": "@weekly",
		"created_at": 1683154980,
		"created_by": "octocat",
		"updated_at": 1683154980,
		"updated_by": "octocat",
		"scheduled_at": 0,
		"branch": "main",
		"error": "error message",
		"next_run": 0
	},
	{
		"id": 1,
		"repo": {
			"id": 1,
			"owner": {
				"id": 1,
				"name": "octocat",
				"favorites": [],
				"active": true,
				"admin": false
			},
			"org": "github",
			"counter": 10,
			"name": "octocat",
			"full_name": "github/octocat",
			"link": "https://github.com/github/octocat",
			"clone": "https://github.com/github/octocat",
			"branch": "main",
			"build_limit": 10,
			"timeout": 60,
			"visibility": "public",
			"private": false,
			"trusted": true,
			"pipeline_type": "yaml",
			"topics": [],
			"active": true,
			"allow_events": {
				"push": {
					"branch": true,
					"tag": true
				},
				"pull_request": {
					"opened": true,
					"synchronize": true,
					"reopened": true,
					"edited": false
				},
				"deployment": {
					"created": true
				},
				"comment": {
					"created": false,
					"edited": false
				}
			},
			"approve_build": "fork-always",
			"previous_name": ""
		},
		"active": true,
		"name": "bar",
		"entry": "@weekly",
		"created_at": 1683154974,
		"created_by": "octocat",
		"updated_at": 1683154974,
		"updated_by": "octocat",
		"scheduled_at": 0,
		"repo_id": 1,
		"branch": "main",
		"error": "error message",
		"next_run": 0
	}]`
)

// getSchedules returns mock JSON for a http GET.
func getSchedules(c *gin.Context) {
	data := []byte(SchedulesResp)

	var body []api.Schedule
	_ = json.Unmarshal(data, &body)

	c.JSON(http.StatusOK, body)
}

// getSchedule has a param :schedule returns mock JSON for a http GET.
//
// Pass "not-found" to :schedule to test receiving a http 404 response.
func getSchedule(c *gin.Context) {
	s := c.Param("schedule")

	if strings.Contains(s, "not-found") {
		msg := fmt.Sprintf("Schedule %s does not exist", s)

		c.AbortWithStatusJSON(http.StatusNotFound, types.Error{Message: &msg})

		return
	}

	data := []byte(ScheduleResp)

	var body api.Schedule
	_ = json.Unmarshal(data, &body)

	c.JSON(http.StatusOK, body)
}

// addSchedule returns mock JSON for a http POST.
func addSchedule(c *gin.Context) {
	data := []byte(ScheduleResp)

	var body api.Schedule
	_ = json.Unmarshal(data, &body)

	c.JSON(http.StatusCreated, body)
}

// updateSchedule has a param :schedule returns mock JSON for a http PUT.
//
// Pass "not-found" to :schedule to test receiving a http 404 response.
func updateSchedule(c *gin.Context) {
	if !strings.Contains(c.FullPath(), "admin") {
		s := c.Param("schedule")

		if strings.Contains(s, "not-found") {
			msg := fmt.Sprintf("Schedule %s does not exist", s)

			c.AbortWithStatusJSON(http.StatusNotFound, types.Error{Message: &msg})

			return
		}
	}

	data := []byte(ScheduleResp)

	var body api.Schedule
	_ = json.Unmarshal(data, &body)

	c.JSON(http.StatusOK, body)
}

// removeSchedule has a param :schedule returns mock JSON for a http DELETE.
//
// Pass "not-found" to :schedule to test receiving a http 404 response.
func removeSchedule(c *gin.Context) {
	s := c.Param("schedule")

	if strings.Contains(s, "not-found") {
		msg := fmt.Sprintf("Schedule %s does not exist", s)

		c.AbortWithStatusJSON(http.StatusNotFound, types.Error{Message: &msg})

		return
	}

	c.JSON(http.StatusOK, fmt.Sprintf("schedule %s deleted", s))
}

Check failure on line 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 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 database/pipeline/create.go

See this annotation in the file changed.

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

See this annotation in the file changed.

@github-actions 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 api/pipeline/validate.go

See this annotation in the file changed.

@github-actions 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/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 from the configured backend
//
// ---
// produces:
// - application/x-yaml
// - application/json
// parameters:
// - in: path
//   name: repo
//   description: Name of the repo
//   required: true
//   type: string
// - in: path
//   name: org
//   description: Name of the org
//   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: Unable to validate the pipeline configuration
//     schema:
//       "$ref": "#/definitions/Error"
//   '404':
//     description: Unable to retrieve the pipeline configuration
//     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 71 in api/pipeline/validate.go

See this annotation in the file changed.

@github-actions github-actions / golangci

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

71-110 lines are duplicate of `api/pipeline/compile.go:73-112` (dupl)
Raw output
api/pipeline/validate.go:71: 71-110 lines are duplicate of `api/pipeline/compile.go:73-112` (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 303 in database/testutils/api_resources.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] database/testutils/api_resources.go#L303

Error return value of `jk.Set` is not checked (errcheck)
Raw output
database/testutils/api_resources.go:303:8: Error return value of `jk.Set` is not checked (errcheck)
	jk.Set(jwk.KeyIDKey, kid.String())
	      ^

Check failure on line 36 in database/jwk/list.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] database/jwk/list.go#L36

Error return value of `keySet.AddKey` is not checked (errcheck)
Raw output
database/jwk/list.go:36:16: Error return value of `keySet.AddKey` is not checked (errcheck)
		keySet.AddKey(tmp.ToAPI())
		             ^

Check failure on line 57 in database/jwk/list_test.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] database/jwk/list_test.go#L57

Error return value of `wantSet.AddKey` is not checked (errcheck)
Raw output
database/jwk/list_test.go:57:16: Error return value of `wantSet.AddKey` is not checked (errcheck)
	wantSet.AddKey(_jwkOne)
	              ^

Check failure on line 58 in database/jwk/list_test.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] database/jwk/list_test.go#L58

Error return value of `wantSet.AddKey` is not checked (errcheck)
Raw output
database/jwk/list_test.go:58:16: Error return value of `wantSet.AddKey` is not checked (errcheck)
	wantSet.AddKey(_jwkTwo)
	              ^

Check failure on line 2579 in database/integration_test.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] database/integration_test.go#L2579

Error return value of `jwkSet.AddKey` is not checked (errcheck)
Raw output
database/integration_test.go:2579:15: Error return value of `jwkSet.AddKey` is not checked (errcheck)
	jwkSet.AddKey(jwkOne)
	             ^

Check failure on line 2580 in database/integration_test.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] database/integration_test.go#L2580

Error return value of `jwkSet.AddKey` is not checked (errcheck)
Raw output
database/integration_test.go:2580:15: Error return value of `jwkSet.AddKey` is not checked (errcheck)
	jwkSet.AddKey(jwkTwo)
	             ^

Check failure on line 42 in internal/token/generate_rsa.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] internal/token/generate_rsa.go#L42

Error return value of `jk.Set` is not checked (errcheck)
Raw output
internal/token/generate_rsa.go:42:8: Error return value of `jk.Set` is not checked (errcheck)
	jk.Set(jwk.KeyIDKey, kid.String())
	      ^