Skip to content

couple more

couple more #13886

GitHub Actions / golangci failed Jul 18, 2024 in 0s

reviewdog [golangci] report

reported by reviewdog 🐶

Findings (29)

database/build/list_pending_running.go|14 col 46| unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
database/build/clean.go|17 col 30| unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
database/build/create.go|17 col 30| unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
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/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)
router/middleware/logger.go|48 col 36| unused-parameter: parameter 'timeFormat' seems to be unused, consider removing or renaming it as _ (revive)
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/authentication.go|81 col 32| Non-inherited new context, use function like context.WithXXX instead (contextcheck)
scm/github/authentication.go|158 col 45| Non-inherited new context, use function like context.WithXXX instead (contextcheck)
compiler/template/starlark/starlark.go|131 col 4| only one cuddle assignment allowed before if statement (wsl)
database/resource.go|34 col 23| Non-inherited new context, use function like context.WithXXX instead (contextcheck)
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/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)
compiler/native/expand.go|47| Function 'ExpandSteps' has too many statements (77 > 70) (funlen)
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 14 in database/build/list_pending_running.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] database/build/list_pending_running.go#L14

unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
Raw output
database/build/list_pending_running.go:14:46: unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
func (e *engine) ListPendingAndRunningBuilds(ctx context.Context, after string) ([]*api.QueueBuild, error) {
                                             ^

Check failure on line 17 in database/build/clean.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] database/build/clean.go#L17

unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
Raw output
database/build/clean.go:17:30: unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
func (e *engine) CleanBuilds(ctx context.Context, msg string, before int64) (int64, error) {
                             ^

Check failure on line 17 in database/build/create.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] database/build/create.go#L17

unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
Raw output
database/build/create.go:17:30: unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
func (e *engine) CreateBuild(ctx context.Context, b *api.Build) (*api.Build, error) {
                             ^

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

See this annotation in the file changed.

@github-actions github-actions / golangci

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

3-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
}

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", 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 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 81 in mock/server/authentication.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] mock/server/authentication.go#L81

string `error` has 4 occurrences, make it a constant (goconst)
Raw output
mock/server/authentication.go:81:9: string `error` has 4 occurrences, make it a constant (goconst)
	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 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 48 in router/middleware/logger.go

See this annotation in the file changed.

@github-actions github-actions / golangci

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

unused-parameter: parameter 'timeFormat' seems to be unused, consider removing or renaming it as _ (revive)
Raw output
router/middleware/logger.go:48:36: unused-parameter: parameter 'timeFormat' seems to be unused, consider removing or renaming it as _ (revive)
func Logger(logger *logrus.Logger, timeFormat string) gin.HandlerFunc {
                                   ^

Check failure on line 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())
	                          ^

Check failure on line 153 in scm/github/access.go

See this annotation in the file changed.

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

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] scm/github/authentication.go#L81

Non-inherited new context, use function like `context.WithXXX` instead (contextcheck)
Raw output
scm/github/authentication.go:81:32: Non-inherited new context, use function like `context.WithXXX` instead (contextcheck)
	token, err := c.OAuth.Exchange(context.Background(), code)
	                              ^

Check failure on line 158 in scm/github/authentication.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] scm/github/authentication.go#L158

Non-inherited new context, use function like `context.WithXXX` instead (contextcheck)
Raw output
scm/github/authentication.go:158:45: Non-inherited new context, use function like `context.WithXXX` instead (contextcheck)
	_, resp, err := client.Authorizations.Check(context.Background(), c.config.ClientID, token)
	                                           ^

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 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 78 in api/pipeline/validate.go

See this annotation in the file changed.

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

See this annotation in the file changed.

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