Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

refactor(repo)!: nested repository with migration from types #1095

Merged
merged 11 commits into from
Apr 10, 2024

fix integration test

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

refactor(repo)!: nested repository with migration from types #1095

fix integration test
f35c68a
Select commit
Loading
Failed to load commit list.
GitHub Actions / golangci failed Mar 27, 2024 in 1s

reviewdog [golangci] report

reported by reviewdog 🐶

Findings (56)

api/webhook/post.go|182 col 32| Non-inherited new context, use function like context.WithXXX instead (contextcheck)
api/webhook/post.go|490 col 38| Non-inherited new context, use function like context.WithXXX instead (contextcheck)
api/webhook/post.go|501 col 40| Non-inherited new context, use function like context.WithXXX instead (contextcheck)
api/webhook/post.go|355 col 4| only one cuddle assignment allowed before if statement (wsl)
database/secret/count_repo.go|14 col 38| unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
database/secret/get_team.go|15 col 35| unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
database/secret/table.go|66 col 36| unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
database/worker/create.go|3| 3-36 lines are duplicate of database/worker/update.go:3-36 (dupl)
database/worker/update.go|3| 3-36 lines are duplicate of database/worker/create.go:3-36 (dupl)
router/middleware/logger.go|42 col 36| unused-parameter: parameter 'timeFormat' seems to be unused, consider removing or renaming it as _ (revive)
router/middleware/header.go|33 col 3| if statements should only be cuddled with assignments (wsl)
router/middleware/header.go|37 col 3| expressions should not be cuddled with blocks (wsl)
compiler/registry/github/github.go|41 col 21| string /api/v3/ has 5 occurrences, make it a constant (goconst)
compiler/native/expand.go|48| Function 'ExpandSteps' has too many statements (71 > 70) (funlen)
compiler/native/compile_test.go|1819 col 46| G601: Implicit memory aliasing in for loop. (gosec)
compiler/native/compile_test.go|3130 col 47| G601: Implicit memory aliasing in for loop. (gosec)
compiler/native/compile_test.go|3478 col 47| G601: Implicit memory aliasing in for loop. (gosec)
compiler/native/parse_test.go|861 col 24| unused-parameter: parameter 'p' seems to be unused, consider removing or renaming it as _ (revive)
compiler/template/starlark/starlark.go|131 col 4| only one cuddle assignment allowed before if statement (wsl)
database/schedule/count.go|6| File is not goimports-ed (goimports)
database/schedule/count_active.go|6| File is not goimports-ed (goimports)
database/schedule/delete.go|6| File is not goimports-ed (goimports)
database/pipeline/create.go|3| 3-53 lines are duplicate of database/pipeline/update.go:3-54 (dupl)
database/pipeline/update.go|3| 3-54 lines are duplicate of database/pipeline/create.go:3-53 (dupl)
cmd/vela-server/server.go|26| Function 'server' is too long (201 > 160) (funlen)
cmd/vela-server/server.go|162 col 4| only one cuddle assignment allowed before if statement (wsl)
cmd/vela-server/server.go|165 col 4| expressions should not be cuddled with blocks (wsl)
cmd/vela-server/server.go|168 col 4| assignments should only be cuddled with other assignments (wsl)
cmd/vela-server/server.go|172 col 4| return statements should not be cuddled if block has more than two lines (wsl)
cmd/vela-server/server.go|193 col 3| for statement without condition should never be cuddled (wsl)
cmd/vela-server/server.go|161 col 4| assignments should only be cuddled with other assignments (wsl)
cmd/vela-server/server.go|181 col 3| assignments should only be cuddled with other assignments (wsl)
mock/server/schedule.go|3| 3-142 lines are duplicate of mock/server/secret.go:4-190 (dupl)
mock/server/authentication.go|41 col 9| string error has 4 occurrences, make it a constant (goconst)
database/deployment/create.go|3| 3-33 lines are duplicate of database/deployment/update.go:3-32 (dupl)
database/deployment/update.go|3| 3-32 lines are duplicate of database/deployment/create.go:3-33 (dupl)
api/build/update.go|170 col 87| unnecessary leading newline (whitespace)
api/pipeline/validate.go|3| 3-107 lines are duplicate of api/pipeline/compile.go:4-108 (dupl)
api/repo/create.go|227 col 3| expressions should not be cuddled with blocks (wsl)
scm/github/authentication.go|58 col 52| unused-parameter: parameter 'w' seems to be unused, consider removing or renaming it as _ (revive)
scm/github/access.go|34 col 28| Function newClientToken should pass the context parameter (contextcheck)
scm/github/access.go|103 col 28| Function newClientToken should pass the context parameter (contextcheck)
scm/github/access.go|153 col 28| Function newClientToken should pass the context parameter (contextcheck)
scm/github/repo.go|451 col 23| SA1019: client.Repositories.List is deprecated: Use RepositoriesService.ListByUser or RepositoriesService.ListByAuthenticatedUser instead. (staticcheck)
secret/vault/refresh_test.go|45 col 74| unused-parameter: parameter 'r' seems to be unused, consider removing or renaming it as _ (revive)
secret/vault/refresh_test.go|71 col 40| unused-parameter: parameter 'in' seems to be unused, consider removing or renaming it as _ (revive)
secret/vault/refresh_test.go|108 col 40| unused-parameter: parameter 'in' seems to be unused, consider removing or renaming it as _ (revive)
secret/vault/refresh_test.go|128 col 40| unused-parameter: parameter 'in' seems to be unused, consider removing or renaming it as _ (revive)
secret/vault/refresh_test.go|201 col 74| unused-parameter: parameter 'r' seems to be unused, consider removing or renaming it as _ (revive)
compiler/native/compile.go|260 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|357 col 1| directive //nolint:dupl,lll // linter thinks the steps and stages workflows are identical is unused for linter "dupl" (nolintlint)
database/schedule/create.go|3 col 1| directive //nolint:dupl // ignore similar code with update.go is unused for linter "dupl" (nolintlint)
api/build/skip.go|12 col 1| directive //nolint:goconst // ignore init and clone constants is unused for linter "goconst" (nolintlint)
secret/vault/count.go|37 col 2| directive //nolint:staticcheck // ignore false positive is unused for linter "staticcheck" (nolintlint)
secret/vault/get.go|40 col 2| directive //nolint:ineffassign,staticcheck // ignore false positive is unused for linter "staticcheck" (nolintlint)
secret/vault/list.go|45 col 2| directive //nolint:staticcheck // ignore false positive is unused for linter "staticcheck" (nolintlint)

Filtered Findings (0)

Annotations

Check failure on line 182 in api/webhook/post.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] api/webhook/post.go#L182

Non-inherited new context, use function like `context.WithXXX` instead (contextcheck)
Raw output
api/webhook/post.go:182:32: Non-inherited new context, use function like `context.WithXXX` instead (contextcheck)
		_, err = database.FromContext(c).UpdateHook(ctx, h)
		                             ^

Check failure on line 490 in api/webhook/post.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] api/webhook/post.go#L490

Non-inherited new context, use function like `context.WithXXX` instead (contextcheck)
Raw output
api/webhook/post.go:490:38: Non-inherited new context, use function like `context.WithXXX` instead (contextcheck)
		dbRepo, err := database.FromContext(c).GetRepoForOrg(ctx, r.GetOrg(), r.GetName())
		                                   ^

Check failure on line 501 in api/webhook/post.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] api/webhook/post.go#L501

Non-inherited new context, use function like `context.WithXXX` instead (contextcheck)
Raw output
api/webhook/post.go:501:40: Non-inherited new context, use function like `context.WithXXX` instead (contextcheck)
		lastHook, err := database.FromContext(c).LastHookForRepo(ctx, dbRepo)
		                                     ^

Check failure on line 355 in api/webhook/post.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] api/webhook/post.go#L355

only one cuddle assignment allowed before if statement (wsl)
Raw output
api/webhook/post.go:355:4: only one cuddle assignment allowed before if statement (wsl)
			if err != nil {
			^

Check failure on line 14 in database/secret/count_repo.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] database/secret/count_repo.go#L14

unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
Raw output
database/secret/count_repo.go:14:38: unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
func (e *engine) CountSecretsForRepo(ctx context.Context, r *api.Repo, filters map[string]interface{}) (int64, error) {
                                     ^

Check failure on line 15 in database/secret/get_team.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] database/secret/get_team.go#L15

unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
Raw output
database/secret/get_team.go:15:35: unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
func (e *engine) GetSecretForTeam(ctx context.Context, org, team, name string) (*library.Secret, error) {
                                  ^

Check failure on line 66 in database/secret/table.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] database/secret/table.go#L66

unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
Raw output
database/secret/table.go:66:36: unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
func (e *engine) CreateSecretTable(ctx context.Context, driver string) 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-36 lines are duplicate of `database/worker/update.go:3-36` (dupl)
Raw output
database/worker/create.go:3: 3-36 lines are duplicate of `database/worker/update.go:3-36` (dupl)
package worker

import (
	"context"

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

// CreateWorker creates a new worker in the database.
func (e *engine) CreateWorker(ctx context.Context, w *api.Worker) (*api.Worker, error) {
	e.logger.WithFields(logrus.Fields{
		"worker": w.GetHostname(),
	}).Tracef("creating worker %s in the database", w.GetHostname())

	// cast the library type to database type
	//
	// https://pkg.go.dev/github.com/go-vela/types/database#WorkerFromLibrary
	worker := FromAPI(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-36 lines are duplicate of `database/worker/create.go:3-36` (dupl)
Raw output
database/worker/update.go:3: 3-36 lines are duplicate of `database/worker/create.go:3-36` (dupl)
package worker

import (
	"context"

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

// UpdateWorker updates an existing worker in the database.
func (e *engine) UpdateWorker(ctx context.Context, w *api.Worker) (*api.Worker, error) {
	e.logger.WithFields(logrus.Fields{
		"worker": w.GetHostname(),
	}).Tracef("updating worker %s in the database", w.GetHostname())

	// cast the library type to database type
	//
	// https://pkg.go.dev/github.com/go-vela/types/database#WorkerFromLibrary
	worker := FromAPI(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 42 in router/middleware/logger.go

See this annotation in the file changed.

@github-actions github-actions / golangci

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

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

See this annotation in the file changed.

@github-actions github-actions / golangci

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

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

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

See this annotation in the file changed.

@github-actions github-actions / golangci

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

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

Check failure on line 41 in compiler/registry/github/github.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] compiler/registry/github/github.go#L41

string `/api/v3/` has 5 occurrences, make it a constant (goconst)
Raw output
compiler/registry/github/github.go:41:21: string `/api/v3/` has 5 occurrences, make it a constant (goconst)
				c.API = c.URL + "/api/v3/"
				                ^

Check failure on line 48 in compiler/native/expand.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] compiler/native/expand.go#L48

Function 'ExpandSteps' has too many statements (71 > 70) (funlen)
Raw output
compiler/native/expand.go:48: Function 'ExpandSteps' has too many statements (71 > 70) (funlen)
func (c *client) ExpandSteps(s *yaml.Build, tmpls map[string]*yaml.Template, r *pipeline.RuleData, depth int) (*yaml.Build, error) {

Check failure on line 1819 in compiler/native/compile_test.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] compiler/native/compile_test.go#L1819

G601: Implicit memory aliasing in for loop. (gosec)
Raw output
compiler/native/compile_test.go:1819:46: G601: Implicit memory aliasing in for loop. (gosec)
			compiler.WithRepo(&api.Repo{PipelineType: &tt.args.pipelineType})
			                                          ^

Check failure on line 3130 in compiler/native/compile_test.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] compiler/native/compile_test.go#L3130

G601: Implicit memory aliasing in for loop. (gosec)
Raw output
compiler/native/compile_test.go:3130:47: G601: Implicit memory aliasing in for loop. (gosec)
				compiler.WithRepo(&api.Repo{PipelineType: &tt.args.pipelineType})
				                                          ^

Check failure on line 3478 in compiler/native/compile_test.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] compiler/native/compile_test.go#L3478

G601: Implicit memory aliasing in for loop. (gosec)
Raw output
compiler/native/compile_test.go:3478:47: G601: Implicit memory aliasing in for loop. (gosec)
				compiler.WithRepo(&api.Repo{PipelineType: &tt.args.pipelineType})
				                                          ^

Check failure on line 861 in compiler/native/parse_test.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] compiler/native/parse_test.go#L861

unused-parameter: parameter 'p' seems to be unused, consider removing or renaming it as _ (revive)
Raw output
compiler/native/parse_test.go:861:24: unused-parameter: parameter 'p' seems to be unused, consider removing or renaming it as _ (revive)
func (FailReader) Read(p []byte) (n int, err error) {
                       ^

Check failure on line 131 in compiler/template/starlark/starlark.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] compiler/template/starlark/starlark.go#L131

only one cuddle assignment allowed before if statement (wsl)
Raw output
compiler/template/starlark/starlark.go:131:4: only one cuddle assignment allowed before if statement (wsl)
			if err != nil {
			^

Check failure on line 6 in database/schedule/count.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] database/schedule/count.go#L6

File is not `goimports`-ed (goimports)
Raw output
database/schedule/count.go:6: File is not `goimports`-ed (goimports)
	"context"

Check failure on line 6 in database/schedule/count_active.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] database/schedule/count_active.go#L6

File is not `goimports`-ed (goimports)
Raw output
database/schedule/count_active.go:6: File is not `goimports`-ed (goimports)
	"context"

Check failure on line 6 in database/schedule/delete.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] database/schedule/delete.go#L6

File is not `goimports`-ed (goimports)
Raw output
database/schedule/delete.go:6: File is not `goimports`-ed (goimports)
	"context"

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-53 lines are duplicate of `database/pipeline/update.go:3-54` (dupl)
Raw output
database/pipeline/create.go:3: 3-53 lines are duplicate of `database/pipeline/update.go:3-54` (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 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-54 lines are duplicate of `database/pipeline/create.go:3-53` (dupl)
Raw output
database/pipeline/update.go:3: 3-54 lines are duplicate of `database/pipeline/create.go:3-53` (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 26 in cmd/vela-server/server.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] cmd/vela-server/server.go#L26

Function 'server' is too long (201 > 160) (funlen)
Raw output
cmd/vela-server/server.go:26: Function 'server' is too long (201 > 160) (funlen)
func server(c *cli.Context) error {