feat(queuing)!: build executable server-side implementation #927
reviewdog [golangci] report
reported by reviewdog 🐶
Findings (60)
queue/redis/redis_test.go|95 col 2| _steps
is unused (deadcode)
database/pipeline/create.go|5| 5-55 lines are duplicate of database/pipeline/update.go:5-56
(dupl)
database/pipeline/update.go|5| 5-56 lines are duplicate of database/pipeline/create.go:5-55
(dupl)
mock/server/schedule.go|5| 5-213 lines are duplicate of mock/server/secret.go:6-169
(dupl)
secret/native/count_test.go|37 col 18| Error return value of db.DeleteSecret
is not checked (errcheck)
secret/native/create_test.go|40 col 18| Error return value of db.DeleteSecret
is not checked (errcheck)
secret/native/create_test.go|87 col 18| Error return value of db.DeleteSecret
is not checked (errcheck)
internal/token/refresh_test.go|54 col 16| Error return value of db.DeleteUser
is not checked (errcheck)
internal/token/refresh_test.go|113 col 16| Error return value of db.DeleteUser
is not checked (errcheck)
router/middleware/worker/worker_test.go|61 col 18| Error return value of db.DeleteWorker
is not checked (errcheck)
router/middleware/claims/claims_test.go|277 col 16| Error return value of db.DeleteUser
is not checked (errcheck)
router/middleware/org/org_test.go|69 col 16| Error return value of db.DeleteRepo
is not checked (errcheck)
router/middleware/repo/repo_test.go|76 col 16| Error return value of db.DeleteRepo
is not checked (errcheck)
router/middleware/build/build_test.go|93 col 17| Error return value of db.DeleteBuild
is not checked (errcheck)
router/middleware/build/build_test.go|94 col 16| Error return value of db.DeleteRepo
is not checked (errcheck)
router/middleware/pipeline/pipeline_test.go|106 col 20| Error return value of db.DeletePipeline
is not checked (errcheck)
router/middleware/service/service_test.go|82 col 17| Error return value of db.DeleteBuild
is not checked (errcheck)
router/middleware/service/service_test.go|84 col 19| Error return value of db.DeleteService
is not checked (errcheck)
router/middleware/service/service_test.go|224 col 17| Error return value of db.DeleteBuild
is not checked (errcheck)
router/middleware/step/step_test.go|86 col 16| Error return value of db.DeleteStep
is not checked (errcheck)
cmd/vela-server/server.go|28| Function 'server' is too long (184 > 160) (funlen)
mock/server/authentication.go|43 col 9| string error
has 3 occurrences, make it a constant (goconst)
database/database.go|84 col 13| Comment should end in a period (godot)
random/random.go|1 col 18| Expected:2023, Actual: 2022 Target Brands, Inc. All rights reserved. (goheader)
version/version.go|1 col 18| Expected:2023, Actual: 2022 Target Brands, Inc. All rights reserved. (goheader)
compiler/registry/doc.go|1 col 18| Expected:2023, Actual: 2022 Target Brands, Inc. All rights reserved. (goheader)
database/resource.go|1 col 40| Actual: e. All rights reserved.
database/validate.go|1 col 40| Actual: e. All rights reserved.
database/validate_test.go|1 col 40| Actual: e. All rights reserved.
compiler/template/starlark/render.go|10| File is not goimports
-ed (goimports)
database/schedule/count.go|8| File is not goimports
-ed (goimports)
database/schedule/count_active.go|8| File is not goimports
-ed (goimports)
queue/redis/route_test.go|64 col 28| G601: Implicit memory aliasing in for loop. (gosec)
compiler/native/compile_test.go|1795 col 50| G601: Implicit memory aliasing in for loop. (gosec)
compiler/native/compile_test.go|3092 col 51| G601: Implicit memory aliasing in for loop. (gosec)
cmd/vela-server/schedule.go|107 col 35| occurence
is a misspelling of occurrence
(misspell)
database/user/user_test.go|198 col 28| unused-parameter: parameter 'v' seems to be unused, consider removing or renaming it as _ (revive)
database/schedule/table.go|53 col 38| unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
database/schedule/delete.go|16 col 33| unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
database/schedule/count.go|13 col 33| unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
database/log/log_test.go|179 col 28| unused-parameter: parameter 'v' seems to be unused, consider removing or renaming it as _ (revive)
database/build/build_test.go|273 col 28| unused-parameter: parameter 'v' seems to be unused, consider removing or renaming it as _ (revive)
scm/github/authentication.go|60 col 31| unused-parameter: parameter 'w' seems to be unused, consider removing or renaming it as _ (revive)
compiler/native/parse_test.go|849 col 24| unused-parameter: parameter 'p' seems to be unused, consider removing or renaming it as _ (revive)
router/middleware/logger.go|30 col 36| unused-parameter: parameter 'timeFormat' seems to be unused, consider removing or renaming it as _ (revive)
api/metrics.go|446| unnecessary leading newline (whitespace)
router/router.go|139| unnecessary trailing newline (whitespace)
cmd/vela-server/schedule.go|276 col 3| expressions should not be cuddled with blocks (wsl)
api/webhook/post.go|720 col 38| Non-inherited new context, use function like context.WithXXX
instead (contextcheck)
api/webhook/post.go|731 col 40| Non-inherited new context, use function like context.WithXXX
instead (contextcheck)
api/webhook/post.go|764 col 37| Non-inherited new context, use function like context.WithXXX
instead (contextcheck)
database/schedule/create.go|5 col 1| directive //nolint:dupl // ignore similar code with update.go
is unused for linter "dupl" (nolintlint)
compiler/native/compile.go|266 col 1| directive //nolint:dupl,lll // linter thinks the steps and stages workflows are identical
is unused for linter "dupl" (nolintlint)
compiler/native/compile.go|363 col 1| directive //nolint:dupl,lll // linter thinks the steps and stages workflows are identical
is unused for linter "dupl" (nolintlint)
secret/vault/count.go|38 col 2| directive //nolint:staticcheck // ignore false positive
is unused for linter "staticcheck" (nolintlint)
secret/vault/get.go|41 col 2| directive //nolint:ineffassign,staticcheck // ignore false positive
is unused for linter "staticcheck" (nolintlint)
secret/vault/list.go|46 col 2| directive //nolint:staticcheck // ignore false positive
is unused for linter "staticcheck" (nolintlint)
api/secret/create.go|81 col 1| directive //nolint:funlen // suppress long function error
is unused for linter "funlen" (nolintlint)
api/build/create.go|304 col 2| directive //nolint:dupl // ignore duplicate code
is unused for linter "dupl" (nolintlint)
api/build/restart.go|295 col 2| directive //nolint:dupl // ignore duplicate code
is unused for linter "dupl" (nolintlint)
Filtered Findings (0)
Annotations
Check failure on line 95 in queue/redis/redis_test.go
github-actions / golangci
[golangci] queue/redis/redis_test.go#L95
`_steps` is unused (deadcode)
Raw output
queue/redis/redis_test.go:95:2: `_steps` is unused (deadcode)
_steps = &pipeline.Build{
^
Check failure on line 5 in database/pipeline/create.go
github-actions / golangci
[golangci] database/pipeline/create.go#L5
5-55 lines are duplicate of `database/pipeline/update.go:5-56` (dupl)
Raw output
database/pipeline/create.go:5: 5-55 lines are duplicate of `database/pipeline/update.go:5-56` (dupl)
package pipeline
import (
"context"
"github.com/go-vela/types/constants"
"github.com/go-vela/types/database"
"github.com/go-vela/types/library"
"github.com/sirupsen/logrus"
)
// 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 5 in database/pipeline/update.go
github-actions / golangci
[golangci] database/pipeline/update.go#L5
5-56 lines are duplicate of `database/pipeline/create.go:5-55` (dupl)
Raw output
database/pipeline/update.go:5: 5-56 lines are duplicate of `database/pipeline/create.go:5-55` (dupl)
package pipeline
import (
"context"
"github.com/go-vela/types/constants"
"github.com/go-vela/types/database"
"github.com/go-vela/types/library"
"github.com/sirupsen/logrus"
)
// 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 5 in mock/server/schedule.go
github-actions / golangci
[golangci] mock/server/schedule.go#L5
5-213 lines are duplicate of `mock/server/secret.go:6-169` (dupl)
Raw output
mock/server/schedule.go:5: 5-213 lines are duplicate of `mock/server/secret.go:6-169` (dupl)
package server
import (
"encoding/json"
"fmt"
"net/http"
"strings"
"github.com/gin-gonic/gin"
"github.com/go-vela/types"
"github.com/go-vela/types/library"
)
const (
// ScheduleResp represents a JSON return for a single schedule.
ScheduleResp = `{
"id": 2,
"active": true,
"name": "foo",
"entry": "@weekly",
"created_at": 1683154980,
"created_by": "octocat",
"updated_at": 1683154980,
"updated_by": "octocat",
"scheduled_at": 0,
"repo": {
"id": 1,
"user_id": 1,
"org": "github",
"name": "octocat",
"full_name": "github/octocat",
"link": "https://github.com/github/octocat",
"clone": "https://github.com/github/octocat.git",
"branch": "main",
"topics": [],
"build_limit": 10,
"timeout": 30,
"counter": 0,
"visibility": "public",
"private": false,
"trusted": false,
"active": true,
"allow_pull": false,
"allow_push": true,
"allow_deploy": false,
"allow_tag": false,
"allow_comment": false,
"pipeline_type": "yaml",
"previous_name": ""
}
}`
SchedulesResp = `[
{
"id": 2,
"active": true,
"name": "foo",
"entry": "@weekly",
"created_at": 1683154980,
"created_by": "octocat",
"updated_at": 1683154980,
"updated_by": "octocat",
"scheduled_at": 0,
"repo": {
"id": 1,
"user_id": 1,
"org": "github",
"name": "octokitty",
"full_name": "github/octokitty",
"link": "https://github.com/github/octokitty",
"clone": "https://github.com/github/octokitty.git",
"branch": "main",
"topics": [],
"build_limit": 10,
"timeout": 30,
"counter": 0,
"visibility": "public",
"private": false,
"trusted": false,
"active": true,
"allow_pull": false,
"allow_push": true,
"allow_deploy": false,
"allow_tag": false,
"allow_comment": false,
"pipeline_type": "yaml",
"previous_name": ""
}
},
{
"id": 1,
"active": true,
"name": "bar",
"entry": "@weekly",
"created_at": 1683154974,
"created_by": "octocat",
"updated_at": 1683154974,
"updated_by": "octocat",
"scheduled_at": 0,
"repo": {
"id": 1,
"user_id": 1,
"org": "github",
"name": "octokitty",
"full_name": "github/octokitty",
"link": "https://github.com/github/octokitty",
"clone": "https://github.com/github/octokitty.git",
"branch": "main",
"topics": [],
"build_limit": 10,
"timeout": 30,
"counter": 0,
"visibility": "public",
"private": false,
"trusted": false,
"active": true,
"allow_pull": false,
"allow_push": true,
"allow_deploy": false,
"allow_tag": false,
"allow_comment": false,
"pipeline_type": "yaml",
"previous_name": ""
}
}
]`
)
// getSchedules returns mock JSON for a http GET.
func getSchedules(c *gin.Context) {
data := []byte(SchedulesResp)
var body []library.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 library.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 library.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 library.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 37 in secret/native/count_test.go
github-actions / golangci
[golangci] secret/native/count_test.go#L37
Error return value of `db.DeleteSecret` is not checked (errcheck)
Raw output
secret/native/count_test.go:37:18: Error return value of `db.DeleteSecret` is not checked (errcheck)
db.DeleteSecret(sec)
^
Check failure on line 40 in secret/native/create_test.go
github-actions / golangci
[golangci] secret/native/create_test.go#L40
Error return value of `db.DeleteSecret` is not checked (errcheck)
Raw output
secret/native/create_test.go:40:18: Error return value of `db.DeleteSecret` is not checked (errcheck)
db.DeleteSecret(want)
^
Check failure on line 87 in secret/native/create_test.go
github-actions / golangci
[golangci] secret/native/create_test.go#L87
Error return value of `db.DeleteSecret` is not checked (errcheck)
Raw output
secret/native/create_test.go:87:18: Error return value of `db.DeleteSecret` is not checked (errcheck)
db.DeleteSecret(want)
^
Check failure on line 54 in internal/token/refresh_test.go
github-actions / golangci
[golangci] internal/token/refresh_test.go#L54
Error return value of `db.DeleteUser` is not checked (errcheck)
Raw output
internal/token/refresh_test.go:54:16: Error return value of `db.DeleteUser` is not checked (errcheck)
db.DeleteUser(u)
^
Check failure on line 113 in internal/token/refresh_test.go
github-actions / golangci
[golangci] internal/token/refresh_test.go#L113
Error return value of `db.DeleteUser` is not checked (errcheck)
Raw output
internal/token/refresh_test.go:113:16: Error return value of `db.DeleteUser` is not checked (errcheck)
db.DeleteUser(u)
^
Check failure on line 61 in router/middleware/worker/worker_test.go
github-actions / golangci
[golangci] router/middleware/worker/worker_test.go#L61
Error return value of `db.DeleteWorker` is not checked (errcheck)
Raw output
router/middleware/worker/worker_test.go:61:18: Error return value of `db.DeleteWorker` is not checked (errcheck)
db.DeleteWorker(want)
^
Check failure on line 277 in router/middleware/claims/claims_test.go
github-actions / golangci
[golangci] router/middleware/claims/claims_test.go#L277
Error return value of `db.DeleteUser` is not checked (errcheck)
Raw output
router/middleware/claims/claims_test.go:277:16: Error return value of `db.DeleteUser` is not checked (errcheck)
db.DeleteUser(u)
^
Check failure on line 69 in router/middleware/org/org_test.go
github-actions / golangci
[golangci] router/middleware/org/org_test.go#L69
Error return value of `db.DeleteRepo` is not checked (errcheck)
Raw output
router/middleware/org/org_test.go:69:16: Error return value of `db.DeleteRepo` is not checked (errcheck)
db.DeleteRepo(context.TODO(), r)
^
Check failure on line 76 in router/middleware/repo/repo_test.go
github-actions / golangci
[golangci] router/middleware/repo/repo_test.go#L76
Error return value of `db.DeleteRepo` is not checked (errcheck)
Raw output
router/middleware/repo/repo_test.go:76:16: Error return value of `db.DeleteRepo` is not checked (errcheck)
db.DeleteRepo(context.TODO(), want)
^
Check failure on line 93 in router/middleware/build/build_test.go
github-actions / golangci
[golangci] router/middleware/build/build_test.go#L93
Error return value of `db.DeleteBuild` is not checked (errcheck)
Raw output
router/middleware/build/build_test.go:93:17: Error return value of `db.DeleteBuild` is not checked (errcheck)
db.DeleteBuild(context.TODO(), want)
^
Check failure on line 94 in router/middleware/build/build_test.go
github-actions / golangci
[golangci] router/middleware/build/build_test.go#L94
Error return value of `db.DeleteRepo` is not checked (errcheck)
Raw output
router/middleware/build/build_test.go:94:16: Error return value of `db.DeleteRepo` is not checked (errcheck)
db.DeleteRepo(context.TODO(), r)
^
Check failure on line 106 in router/middleware/pipeline/pipeline_test.go
github-actions / golangci
[golangci] router/middleware/pipeline/pipeline_test.go#L106
Error return value of `db.DeletePipeline` is not checked (errcheck)
Raw output
router/middleware/pipeline/pipeline_test.go:106:20: Error return value of `db.DeletePipeline` is not checked (errcheck)
db.DeletePipeline(context.TODO(), want)
^
Check failure on line 82 in router/middleware/service/service_test.go
github-actions / golangci
[golangci] router/middleware/service/service_test.go#L82
Error return value of `db.DeleteBuild` is not checked (errcheck)
Raw output
router/middleware/service/service_test.go:82:17: Error return value of `db.DeleteBuild` is not checked (errcheck)
db.DeleteBuild(context.TODO(), b)
^
Check failure on line 84 in router/middleware/service/service_test.go
github-actions / golangci
[golangci] router/middleware/service/service_test.go#L84
Error return value of `db.DeleteService` is not checked (errcheck)
Raw output
router/middleware/service/service_test.go:84:19: Error return value of `db.DeleteService` is not checked (errcheck)
db.DeleteService(want)
^
Check failure on line 224 in router/middleware/service/service_test.go
github-actions / golangci
[golangci] router/middleware/service/service_test.go#L224
Error return value of `db.DeleteBuild` is not checked (errcheck)
Raw output
router/middleware/service/service_test.go:224:17: Error return value of `db.DeleteBuild` is not checked (errcheck)
db.DeleteBuild(context.TODO(), b)
^
Check failure on line 86 in router/middleware/step/step_test.go
github-actions / golangci
[golangci] router/middleware/step/step_test.go#L86
Error return value of `db.DeleteStep` is not checked (errcheck)
Raw output
router/middleware/step/step_test.go:86:16: Error return value of `db.DeleteStep` is not checked (errcheck)
db.DeleteStep(want)
^
Check failure on line 28 in cmd/vela-server/server.go
github-actions / golangci
[golangci] cmd/vela-server/server.go#L28
Function 'server' is too long (184 > 160) (funlen)
Raw output
cmd/vela-server/server.go:28: Function 'server' is too long (184 > 160) (funlen)
func server(c *cli.Context) error {
Check failure on line 43 in mock/server/authentication.go
github-actions / golangci
[golangci] mock/server/authentication.go#L43
string `error` has 3 occurrences, make it a constant (goconst)
Raw output
mock/server/authentication.go:43:9: string `error` has 3 occurrences, make it a constant (goconst)
err := "error"
^
Check failure on line 84 in database/database.go
github-actions / golangci
[golangci] database/database.go#L84
Comment should end in a period (godot)
Raw output
database/database.go:84:13: Comment should end in a period (godot)
// * sqlite3
^
Check failure on line 1 in random/random.go
github-actions / golangci
[golangci] random/random.go#L1
Expected:2023, Actual: 2022 Target Brands, Inc. All rights reserved. (goheader)
Raw output
random/random.go:1:18: Expected:2023, Actual: 2022 Target Brands, Inc. All rights reserved. (goheader)
// Copyright (c) 2022 Target Brands, Inc. All rights reserved.
^
Check failure on line 1 in version/version.go
github-actions / golangci
[golangci] version/version.go#L1
Expected:2023, Actual: 2022 Target Brands, Inc. All rights reserved. (goheader)
Raw output
version/version.go:1:18: Expected:2023, Actual: 2022 Target Brands, Inc. All rights reserved. (goheader)
// Copyright (c) 2022 Target Brands, Inc. All rights reserved.
^