Skip to content
GitHub Actions / golangci failed Oct 29, 2024 in 2s

reviewdog [golangci] report

reported by reviewdog 🐶

Findings (68)

api/types/queue_build.go|3| 3-134 lines are duplicate of api/types/template.go:4-137 (dupl)
mock/server/schedule.go|3| 3-283 lines are duplicate of mock/server/secret.go:4-180 (dupl)
database/deployment/create.go|3| 3-37 lines are duplicate of database/deployment/update.go:3-37 (dupl)
database/deployment/update.go|3| 3-37 lines are duplicate of database/deployment/create.go:3-37 (dupl)
database/worker/create.go|3| 3-37 lines are duplicate of database/worker/update.go:3-37 (dupl)
database/worker/update.go|3| 3-37 lines are duplicate of database/worker/create.go:3-37 (dupl)
database/service/create.go|3| 3-35 lines are duplicate of database/service/update.go:3-35 (dupl)
database/service/update.go|3| 3-35 lines are duplicate of database/service/create.go:3-35 (dupl)
database/step/create.go|3| 3-35 lines are duplicate of database/step/update.go:3-35 (dupl)
database/step/update.go|3| 3-35 lines are duplicate of database/step/create.go:3-35 (dupl)
database/pipeline/create.go|3| 3-51 lines are duplicate of database/pipeline/update.go:3-52 (dupl)
database/pipeline/update.go|3| 3-52 lines are duplicate of database/pipeline/create.go:3-51 (dupl)
database/hook/get.go|3| 3-40 lines are duplicate of database/hook/get_webhook.go:3-40 (dupl)
database/hook/get_webhook.go|3| 3-40 lines are duplicate of database/hook/get.go:3-40 (dupl)
database/hook/create.go|3| 3-39 lines are duplicate of database/hook/update.go:3-39 (dupl)
database/hook/update.go|3| 3-39 lines are duplicate of database/hook/create.go:3-39 (dupl)
api/pipeline/validate.go|78| 78-110 lines are duplicate of api/pipeline/compile.go:80-112 (dupl)
api/pipeline/validate.go|3| 3-110 lines are duplicate of api/pipeline/expand.go:4-112 (dupl)
api/repo/repair.go|65| Function 'RepairRepo' has too many statements (75 > 70) (funlen)
api/types/build.go|60 col 10| string ... has 3 occurrences, make it a constant (goconst)
mock/server/authentication.go|82 col 9| string error has 4 occurrences, make it a constant (goconst)
scm/github/app_client.go|57 col 60| string write has 3 occurrences, make it a constant (goconst)
compiler/types/pipeline/ruleset.go|137 col 1| cyclomatic complexity 34 of func (*Rules).Match is high (> 30) (gocyclo)
scm/github/app_transport.go|99 col 68| Comment should end in a period (godot)
database/types/build.go|384 col 44| G115: integer overflow conversion int -> int32 (gosec)
database/types/build.go|385 col 44| G115: integer overflow conversion int -> int32 (gosec)
database/types/repo.go|338 col 43| G115: integer overflow conversion int -> int32 (gosec)
database/types/settings.go|134 col 35| G115: integer overflow conversion int64 -> uint64 (gosec)
database/types/settings.go|205 col 49| G115: integer overflow conversion uint64 -> int64 (gosec)
secret/vault/create.go|18 col 25| unused-parameter: parameter 'ctx' 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/get.go|18 col 22| 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)
scm/github/app_client.go|21 col 53| var-naming: func parameter baseUrl should be baseURL (revive)
scm/github/app_install.go|23 col 59| unused-parameter: parameter 'request' seems to be unused, consider removing or renaming it as _ (revive)
scm/github/app_install.go|142 col 58| unused-parameter: parameter 'request' seems to be unused, consider removing or renaming it as _ (revive)
api/step/plan.go|53 col 98| 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)
compiler/types/pipeline/git.go|17 col 33| tag is not aligned, should be: json:"permissions,omitempty" yaml:"permissions,omitempty" (tagalign)
compiler/types/yaml/build.go|21 col 33| tag is not aligned, should be: yaml:"git,omitempty" json:"git,omitempty" jsonschema:"description=Provide the git access specifications.\nReference: https://go-vela.github.io/docs/reference/yaml/git/" (tagalign)
compiler/types/yaml/git.go|16 col 33| tag is not aligned, should be: yaml:"permissions,omitempty" json:"permissions,omitempty" jsonschema:"description=Provide a list of repository permissions to apply to the git token.\nReference: https://go-vela.github.io/docs/reference/yaml/git/#permissions" (tagalign)
scm/github/app_transport.go|90 col 2| field appID is unused (unused)
api/webhook/post.go|207 col 32| Non-inherited new context, use function like context.WithXXX instead (contextcheck)
api/webhook/post.go|676 col 38| Non-inherited new context, use function like context.WithXXX instead (contextcheck)
api/webhook/post.go|687 col 40| Non-inherited new context, use function like context.WithXXX instead (contextcheck)
compiler/native/compile.go|358 col 26| Function modifyConfig should pass the context parameter (contextcheck)
compiler/native/compile.go|453 col 26| Function modifyConfig should pass the context parameter (contextcheck)
scm/github/app_transport.go|69 col 52| non-wrapping format verb for fmt.Errorf. Use %w to format errors (errorlint)
scm/github/app_transport.go|182 col 86| non-wrapping format verb for fmt.Errorf. Use %w to format errors (errorlint)
scm/github/app_transport.go|188 col 53| non-wrapping format verb for fmt.Errorf. Use %w to format errors (errorlint)
scm/github/webhook.go|562 col 3| S1023: redundant break statement (gosimple)
compiler/template/starlark/render.go|44 col 18| SA1019: starlark.ExecFile is deprecated: use [ExecFileOptions] with [syntax.FileOptions] instead, because this function relies on legacy global variables. (staticcheck)
compiler/template/starlark/render.go|152 col 18| SA1019: starlark.ExecFile is deprecated: use [ExecFileOptions] with [syntax.FileOptions] instead, because this function relies on legacy global variables. (staticcheck)
compiler/template/starlark/starlark.go|131 col 4| only one cuddle assignment allowed before if statement (wsl)
compiler/types/yaml/stage.go|91 col 5| return statements should not be cuddled if block has more than two lines (wsl)
compiler/types/yaml/stage.go|97 col 2| return statements should not be cuddled if block has more than two lines (wsl)
scm/github/app_transport.go|175 col 2| return statements should not be cuddled if block has more than two lines (wsl)
scm/github/app_transport.go|118 col 2| if statements should only be cuddled with assignments used in the if statement itself (wsl)
scm/github/app_transport.go|158 col 2| if statements should only be cuddled with assignments (wsl)
scm/github/app_transport.go|226 col 3| only one cuddle assignment allowed before if statement (wsl)
scm/github/app_transport.go|187 col 2| only one cuddle assignment allowed before if statement (wsl)
scm/github/repo.go|774 col 2| ranges should only be cuddled with assignments used in the iteration (wsl)
scm/github/repo.go|785 col 2| if statements should only be cuddled with assignments used in the if statement itself (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 3 in api/types/queue_build.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] api/types/queue_build.go#L3

3-134 lines are duplicate of `api/types/template.go:4-137` (dupl)
Raw output
api/types/queue_build.go:3: 3-134 lines are duplicate of `api/types/template.go:4-137` (dupl)
package types

import "fmt"

// QueueBuild is the API representation of the builds in the queue.
//
// swagger:model QueueBuild
type QueueBuild struct {
	Status   *string `json:"status,omitempty"`
	Number   *int32  `json:"number,omitempty"`
	Created  *int64  `json:"created,omitempty"`
	FullName *string `json:"full_name,omitempty"`
}

// GetStatus returns the Status field.
//
// When the provided QueueBuild type is nil, or the field within
// the type is nil, it returns the zero value for the field.
func (b *QueueBuild) GetStatus() string {
	// return zero value if QueueBuild type or Status field is nil
	if b == nil || b.Status == nil {
		return ""
	}

	return *b.Status
}

// GetNumber returns the Number field.
//
// When the provided QueueBuild type is nil, or the field within
// the type is nil, it returns the zero value for the field.
func (b *QueueBuild) GetNumber() int32 {
	// return zero value if QueueBuild type or Number field is nil
	if b == nil || b.Number == nil {
		return 0
	}

	return *b.Number
}

// GetCreated returns the Created field.
//
// When the provided QueueBuild type is nil, or the field within
// the type is nil, it returns the zero value for the field.
func (b *QueueBuild) GetCreated() int64 {
	// return zero value if QueueBuild type or Created field is nil
	if b == nil || b.Created == nil {
		return 0
	}

	return *b.Created
}

// GetFullName returns the FullName field.
//
// When the provided QueueBuild type is nil, or the field within
// the type is nil, it returns the zero value for the field.
func (b *QueueBuild) GetFullName() string {
	// return zero value if QueueBuild type or FullName field is nil
	if b == nil || b.FullName == nil {
		return ""
	}

	return *b.FullName
}

// SetStatus sets the Status field.
//
// When the provided QueueBuild type is nil, it
// will set nothing and immediately return.
func (b *QueueBuild) SetStatus(v string) {
	// return if QueueBuild type is nil
	if b == nil {
		return
	}

	b.Status = &v
}

// SetNumber sets the Number field.
//
// When the provided QueueBuild type is nil, it
// will set nothing and immediately return.
func (b *QueueBuild) SetNumber(v int32) {
	// return if QueueBuild type is nil
	if b == nil {
		return
	}

	b.Number = &v
}

// SetCreated sets the Created field.
//
// When the provided QueueBuild type is nil, it
// will set nothing and immediately return.
func (b *QueueBuild) SetCreated(v int64) {
	// return if QueueBuild type is nil
	if b == nil {
		return
	}

	b.Created = &v
}

// SetFullName sets the FullName field.
//
// When the provided QueueBuild type is nil, it
// will set nothing and immediately return.
func (b *QueueBuild) SetFullName(v string) {
	// return if QueueBuild type is nil
	if b == nil {
		return
	}

	b.FullName = &v
}

// String implements the Stringer interface for the QueueBuild type.
func (b *QueueBuild) String() string {
	return fmt.Sprintf(`{
  Created: %d,
  FullName: %s,
  Number: %d,
  Status: %s,
}`,
		b.GetCreated(),
		b.GetFullName(),
		b.GetNumber(),
		b.GetStatus(),
	)
}

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-283 lines are duplicate of `mock/server/secret.go:4-180` (dupl)
Raw output
mock/server/schedule.go:3: 3-283 lines are duplicate of `mock/server/secret.go:4-180` (dupl)
package server

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

	"github.com/gin-gonic/gin"

	api "github.com/go-vela/server/api/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, api.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, api.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, api.Error{Message: &msg})

		return
	}

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

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

import (
	"context"

	"github.com/sirupsen/logrus"

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

// CreateDeployment creates a new deployment in the database.
func (e *engine) CreateDeployment(ctx context.Context, d *api.Deployment) (*api.Deployment, error) {
	e.logger.WithFields(logrus.Fields{
		"deployment": d.GetID(),
	}).Tracef("creating deployment %d", d.GetID())

	// cast the API type to database type
	deployment := types.DeploymentFromAPI(d)

	// validate the necessary fields are populated
	err := deployment.Validate()
	if err != nil {
		return nil, err
	}

	result := e.client.
		WithContext(ctx).
		Table(constants.TableDeployment).
		Create(deployment)

	// send query to the database
	return deployment.ToAPI(d.Builds), result.Error
}

Check failure on line 3 in database/deployment/update.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] database/deployment/update.go#L3

3-37 lines are duplicate of `database/deployment/create.go:3-37` (dupl)
Raw output
database/deployment/update.go:3: 3-37 lines are duplicate of `database/deployment/create.go:3-37` (dupl)
package deployment

import (
	"context"

	"github.com/sirupsen/logrus"

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

// UpdateDeployment updates an existing deployment in the database.
func (e *engine) UpdateDeployment(ctx context.Context, d *api.Deployment) (*api.Deployment, error) {
	e.logger.WithFields(logrus.Fields{
		"deployment": d.GetID(),
	}).Tracef("updating deployment %d", d.GetID())

	// cast the API type to database type
	deployment := types.DeploymentFromAPI(d)

	// validate the necessary fields are populated
	err := deployment.Validate()
	if err != nil {
		return nil, err
	}

	result := e.client.
		WithContext(ctx).
		Table(constants.TableDeployment).
		Save(deployment)

	// send query to the database
	return deployment.ToAPI(d.Builds), result.Error
}

Check failure on line 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-37 lines are duplicate of `database/worker/update.go:3-37` (dupl)
Raw output
database/worker/create.go:3: 3-37 lines are duplicate of `database/worker/update.go:3-37` (dupl)
package worker

import (
	"context"

	"github.com/sirupsen/logrus"

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

// 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 API type to database type
	worker := types.WorkerFromAPI(w)

	// validate the necessary fields are populated
	err := worker.Validate()
	if err != nil {
		return nil, err
	}

	// send query to the database
	result := e.client.
		WithContext(ctx).
		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-37 lines are duplicate of `database/worker/create.go:3-37` (dupl)
Raw output
database/worker/update.go:3: 3-37 lines are duplicate of `database/worker/create.go:3-37` (dupl)
package worker

import (
	"context"

	"github.com/sirupsen/logrus"

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

// 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 API type to database type
	worker := types.WorkerFromAPI(w)

	// validate the necessary fields are populated
	err := worker.Validate()
	if err != nil {
		return nil, err
	}

	// send query to the database
	result := e.client.
		WithContext(ctx).
		Table(constants.TableWorker).
		Save(worker)

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

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

See this annotation in the file changed.

@github-actions github-actions / golangci

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

3-35 lines are duplicate of `database/service/update.go:3-35` (dupl)
Raw output
database/service/create.go:3: 3-35 lines are duplicate of `database/service/update.go:3-35` (dupl)
package service

import (
	"context"

	"github.com/sirupsen/logrus"

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

// CreateService creates a new service in the database.
func (e *engine) CreateService(ctx context.Context, s *api.Service) (*api.Service, error) {
	e.logger.WithFields(logrus.Fields{
		"service": s.GetNumber(),
	}).Tracef("creating service %s in the database", s.GetName())

	service := types.ServiceFromAPI(s)

	err := service.Validate()
	if err != nil {
		return nil, err
	}

	// send query to the database
	result := e.client.
		WithContext(ctx).
		Table(constants.TableService).
		Create(service)

	return service.ToAPI(), result.Error
}

Check failure on line 3 in database/service/update.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] database/service/update.go#L3

3-35 lines are duplicate of `database/service/create.go:3-35` (dupl)
Raw output
database/service/update.go:3: 3-35 lines are duplicate of `database/service/create.go:3-35` (dupl)
package service

import (
	"context"

	"github.com/sirupsen/logrus"

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

// UpdateService updates an existing service in the database.
func (e *engine) UpdateService(ctx context.Context, s *api.Service) (*api.Service, error) {
	e.logger.WithFields(logrus.Fields{
		"service": s.GetNumber(),
	}).Tracef("updating service %s", s.GetName())

	service := types.ServiceFromAPI(s)

	err := service.Validate()
	if err != nil {
		return nil, err
	}

	// send query to the database
	result := e.client.
		WithContext(ctx).
		Table(constants.TableService).
		Save(service)

	return service.ToAPI(), result.Error
}

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

See this annotation in the file changed.

@github-actions github-actions / golangci

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

3-35 lines are duplicate of `database/step/update.go:3-35` (dupl)
Raw output
database/step/create.go:3: 3-35 lines are duplicate of `database/step/update.go:3-35` (dupl)
package step

import (
	"context"

	"github.com/sirupsen/logrus"

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

// CreateStep creates a new step in the database.
func (e *engine) CreateStep(ctx context.Context, s *api.Step) (*api.Step, error) {
	e.logger.WithFields(logrus.Fields{
		"step": s.GetNumber(),
	}).Tracef("creating step %s in the database", s.GetName())

	step := types.StepFromAPI(s)

	err := step.Validate()
	if err != nil {
		return nil, err
	}

	// send query to the database
	result := e.client.
		WithContext(ctx).
		Table(constants.TableStep).
		Create(step)

	return step.ToAPI(), result.Error
}

Check failure on line 3 in database/step/update.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] database/step/update.go#L3

3-35 lines are duplicate of `database/step/create.go:3-35` (dupl)
Raw output
database/step/update.go:3: 3-35 lines are duplicate of `database/step/create.go:3-35` (dupl)
package step

import (
	"context"

	"github.com/sirupsen/logrus"

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

// UpdateStep updates an existing step in the database.
func (e *engine) UpdateStep(ctx context.Context, s *api.Step) (*api.Step, error) {
	e.logger.WithFields(logrus.Fields{
		"step": s.GetNumber(),
	}).Tracef("updating step %s in the database", s.GetName())

	step := types.StepFromAPI(s)

	err := step.Validate()
	if err != nil {
		return nil, err
	}

	// send query to the database
	result := e.client.
		WithContext(ctx).
		Table(constants.TableStep).
		Save(step)

	return step.ToAPI(), 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-51 lines are duplicate of `database/pipeline/update.go:3-52` (dupl)
Raw output
database/pipeline/create.go:3: 3-51 lines are duplicate of `database/pipeline/update.go:3-52` (dupl)
package pipeline

import (
	"context"

	"github.com/sirupsen/logrus"

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

// CreatePipeline creates a new pipeline in the database.
func (e *engine) CreatePipeline(ctx context.Context, p *api.Pipeline) (*api.Pipeline, error) {
	e.logger.WithFields(logrus.Fields{
		"pipeline": p.GetCommit(),
	}).Tracef("creating pipeline %s in the database", p.GetCommit())

	pipeline := types.PipelineFromAPI(p)

	err := pipeline.Validate()
	if err != nil {
		return nil, err
	}

	err = pipeline.Compress(e.config.CompressionLevel)
	if err != nil {
		return nil, err
	}

	// send query to the database
	err = e.client.
		WithContext(ctx).
		Table(constants.TablePipeline).
		Create(pipeline).Error
	if err != nil {
		return nil, err
	}

	err = pipeline.Decompress()
	if err != nil {
		return nil, err
	}

	result := pipeline.ToAPI()
	result.SetRepo(p.GetRepo())

	return result, 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-52 lines are duplicate of `database/pipeline/create.go:3-51` (dupl)
Raw output
database/pipeline/update.go:3: 3-52 lines are duplicate of `database/pipeline/create.go:3-51` (dupl)
package pipeline

import (
	"context"

	"github.com/sirupsen/logrus"

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

// UpdatePipeline updates an existing pipeline in the database.
func (e *engine) UpdatePipeline(ctx context.Context, p *api.Pipeline) (*api.Pipeline, error) {
	e.logger.WithFields(logrus.Fields{
		"pipeline": p.GetCommit(),
	}).Tracef("updating pipeline %s in the database", p.GetCommit())

	pipeline := types.PipelineFromAPI(p)

	err := pipeline.Validate()
	if err != nil {
		return nil, err
	}

	err = pipeline.Compress(e.config.CompressionLevel)
	if err != nil {
		return nil, err
	}

	// send query to the database
	err = e.client.
		WithContext(ctx).
		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
	}

	result := pipeline.ToAPI()
	result.SetRepo(p.GetRepo())

	return result, nil
}

Check failure on line 3 in database/hook/get.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] database/hook/get.go#L3

3-40 lines are duplicate of `database/hook/get_webhook.go:3-40` (dupl)
Raw output
database/hook/get.go:3: 3-40 lines are duplicate of `database/hook/get_webhook.go:3-40` (dupl)
package hook

import (
	"context"

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

// GetHook gets a hook by ID from the database.
func (e *engine) GetHook(ctx context.Context, id int64) (*api.Hook, error) {
	e.logger.Tracef("getting hook %d", id)

	// variable to store query results
	h := new(types.Hook)

	// send query to the database and store result in variable
	err := e.client.
		WithContext(ctx).
		Table(constants.TableHook).
		Preload("Repo").
		Preload("Repo.Owner").
		Preload("Build").
		Where("id = ?", id).
		Take(h).
		Error
	if err != nil {
		return nil, err
	}

	err = h.Repo.Decrypt(e.config.EncryptionKey)
	if err != nil {
		e.logger.Errorf("unable to decrypt repo for hook %d: %v", h.ID.Int64, err)
	}

	return h.ToAPI(), nil
}

Check failure on line 3 in database/hook/get_webhook.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] database/hook/get_webhook.go#L3

3-40 lines are duplicate of `database/hook/get.go:3-40` (dupl)
Raw output
database/hook/get_webhook.go:3: 3-40 lines are duplicate of `database/hook/get.go:3-40` (dupl)
package hook

import (
	"context"

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

// GetHookByWebhookID gets a single hook with a matching webhook id in the database.
func (e *engine) GetHookByWebhookID(ctx context.Context, webhookID int64) (*api.Hook, error) {
	e.logger.Tracef("getting a hook with webhook id %d", webhookID)

	// variable to store query results
	h := new(types.Hook)

	// send query to the database and store result in variable
	err := e.client.
		WithContext(ctx).
		Table(constants.TableHook).
		Preload("Repo").
		Preload("Repo.Owner").
		Preload("Build").
		Where("webhook_id = ?", webhookID).
		Take(h).
		Error
	if err != nil {
		return nil, err
	}

	err = h.Repo.Decrypt(e.config.EncryptionKey)
	if err != nil {
		e.logger.Errorf("unable to decrypt repo for hook %d: %v", h.ID.Int64, err)
	}

	return h.ToAPI(), nil
}

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

See this annotation in the file changed.

@github-actions github-actions / golangci

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

3-39 lines are duplicate of `database/hook/update.go:3-39` (dupl)
Raw output
database/hook/create.go:3: 3-39 lines are duplicate of `database/hook/update.go:3-39` (dupl)
package hook

import (
	"context"

	"github.com/sirupsen/logrus"

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

// CreateHook creates a new hook in the database.
func (e *engine) CreateHook(ctx context.Context, h *api.Hook) (*api.Hook, error) {
	e.logger.WithFields(logrus.Fields{
		"hook": h.GetNumber(),
	}).Tracef("creating hook %d", h.GetNumber())

	hook := types.HookFromAPI(h)

	err := hook.Validate()
	if err != nil {
		return nil, err
	}

	// send query to the database
	err = e.client.WithContext(ctx).Table(constants.TableHook).Create(hook).Error
	if err != nil {
		return nil, err
	}

	result := hook.ToAPI()
	result.SetRepo(h.GetRepo())
	result.SetBuild(h.GetBuild())

	return result, nil
}

Check failure on line 3 in database/hook/update.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] database/hook/update.go#L3

3-39 lines are duplicate of `database/hook/create.go:3-39` (dupl)
Raw output
database/hook/update.go:3: 3-39 lines are duplicate of `database/hook/create.go:3-39` (dupl)
package hook

import (
	"context"

	"github.com/sirupsen/logrus"

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

// UpdateHook updates an existing hook in the database.
func (e *engine) UpdateHook(ctx context.Context, h *api.Hook) (*api.Hook, error) {
	e.logger.WithFields(logrus.Fields{
		"hook": h.GetNumber(),
	}).Tracef("updating hook %d", h.GetNumber())

	hook := types.HookFromAPI(h)

	err := hook.Validate()
	if err != nil {
		return nil, err
	}

	// send query to the database
	err = e.client.WithContext(ctx).Table(constants.TableHook).Save(hook).Error
	if err != nil {
		return nil, err
	}

	result := hook.ToAPI()
	result.SetRepo(h.GetRepo())
	result.SetBuild(h.GetBuild())

	return result, nil
}

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-110 lines are duplicate of `api/pipeline/compile.go:80-112` (dupl)
Raw output
api/pipeline/validate.go:78: 78-110 lines are duplicate of `api/pipeline/compile.go:80-112` (dupl)
func ValidatePipeline(c *gin.Context) {
	// capture middleware values
	m := c.MustGet("metadata").(*internal.Metadata)
	l := c.MustGet("logger").(*logrus.Entry)
	p := pipeline.Retrieve(c)
	r := repo.Retrieve(c)
	u := user.Retrieve(c)
	ctx := c.Request.Context()

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

	l.Debugf("validating pipeline %s", entry)

	// ensure we use the expected pipeline type when compiling
	r.SetPipelineType(p.GetType())

	// create the compiler object
	compiler := compiler.FromContext(c).Duplicate().WithCommit(p.GetCommit()).WithMetadata(m).WithRepo(r).WithUser(u)

	ruleData := prepareRuleData(c)

	// validate the pipeline
	pipeline, _, err := compiler.CompileLite(ctx, p.GetData(), ruleData, false)
	if err != nil {
		retErr := fmt.Errorf("unable to validate pipeline %s: %w", entry, err)

		util.HandleError(c, http.StatusBadRequest, retErr)

		return
	}

	writeOutput(c, pipeline)
}

Check failure on line 3 in api/pipeline/validate.go

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/pipeline"
	"github.com/go-vela/server/router/middleware/repo"
	"github.com/go-vela/server/router/middleware/user"
	"github.com/go-vela/server/util"
)

// swagger:operation POST /api/v1/pipelines/{org}/{repo}/{pipeline}/validate pipelines ValidatePipeline
//
// Get, expand and validate a pipeline
//
// ---
// produces:
// - application/yaml
// - application/json
// parameters:
// - in: path
//   name: org
//   description: Name of the organization
//   required: true
//   type: string
// - in: path
//   name: repo
//   description: Name of the repository
//   required: true
//   type: string
// - in: path
//   name: pipeline
//   description: Commit SHA for pipeline to retrieve
//   required: true
//   type: string
// - in: query
//   name: output
//   description: Output string for specifying output format
//   type: string
//   default: yaml
//   enum:
//   - json
//   - yaml
// security:
//   - ApiKeyAuth: []
// responses:
//   '200':
//     description: Successfully retrieved, expanded and validated the pipeline
//     schema:
//       type: string
//   '400':
//     description: Invalid request payload or path
//     schema:
//       "$ref": "#/definitions/Error"
//   '401':
//     description: Unauthorized
//     schema:
//       "$ref": "#/definitions/Error"
//   '404':
//     description: Not found
//     schema:
//       "$ref": "#/definitions/Error"
//   '500':
//     description: Unexpected server error
//     schema:
//       "$ref": "#/definitions/Error"

// ValidatePipeline represents the API handler to capture,
// expand and validate a pipeline configuration.
func ValidatePipeline(c *gin.Context) {
	// capture middleware values
	m := c.MustGet("metadata").(*internal.Metadata)
	l := c.MustGet("logger").(*logrus.Entry)
	p := pipeline.Retrieve(c)
	r := repo.Retrieve(c)
	u := user.Retrieve(c)
	ctx := c.Request.Context()

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

	l.Debugf("validating pipeline %s", entry)

	// ensure we use the expected pipeline type when compiling
	r.SetPipelineType(p.GetType())

	// create the compiler object
	compiler := compiler.FromContext(c).Duplicate().WithCommit(p.GetCommit()).WithMetadata(m).WithRepo(r).WithUser(u)

	ruleData := prepareRuleData(c)

	// validate the pipeline
	pipeline, _, err := compiler.CompileLite(ctx, p.GetData(), ruleData, false)
	if err != nil {
		retErr := fmt.Errorf("unable to validate pipeline %s: %w", entry, err)

		util.HandleError(c, http.StatusBadRequest, retErr)

		return
	}

	writeOutput(c, pipeline)
}

Check failure on line 65 in api/repo/repair.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] api/repo/repair.go#L65

Function 'RepairRepo' has too many statements (75 > 70) (funlen)
Raw output
api/repo/repair.go:65: Function 'RepairRepo' has too many statements (75 > 70) (funlen)
func RepairRepo(c *gin.Context) {

Check failure on line 60 in api/types/build.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] api/types/build.go#L60

string `...` has 3 occurrences, make it a constant (goconst)
Raw output
api/types/build.go:60:10: string `...` has 3 occurrences, make it a constant (goconst)
		return "..."
		       ^

Check failure on line 82 in mock/server/authentication.go

See this annotation in the file changed.

@github-actions github-actions / golangci

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

string `error` has 4 occurrences, make it a constant (goconst)
Raw output
mock/server/authentication.go:82:9: string `error` has 4 occurrences, make it a constant (goconst)
	err := "error"
	       ^

Check failure on line 57 in scm/github/app_client.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] scm/github/app_client.go#L57

string `write` has 3 occurrences, make it a constant (goconst)
Raw output
scm/github/app_client.go:57:60: string `write` has 3 occurrences, make it a constant (goconst)
		(perms.GetContents() != "read" && perms.GetContents() != "write") {
		                                                         ^

Check failure on line 137 in compiler/types/pipeline/ruleset.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] compiler/types/pipeline/ruleset.go#L137

cyclomatic complexity 34 of func `(*Rules).Match` is high (> 30) (gocyclo)
Raw output
compiler/types/pipeline/ruleset.go:137:1: cyclomatic complexity 34 of func `(*Rules).Match` is high (> 30) (gocyclo)
func (r *Rules) Match(from *RuleData, matcher, op string) (bool, error) {
^

Check failure on line 99 in scm/github/app_transport.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] scm/github/app_transport.go#L99

Comment should end in a period (godot)
Raw output
scm/github/app_transport.go:99:68: Comment should end in a period (godot)
// accessToken is an installation access token response from GitHub
                                                                   ^

Check failure on line 384 in database/types/build.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] database/types/build.go#L384

G115: integer overflow conversion int -> int32 (gosec)
Raw output
database/types/build.go:384:44: G115: integer overflow conversion int -> int32 (gosec)
		Number:        sql.NullInt32{Int32: int32(b.GetNumber()), Valid: true},
		                                         ^