From bcecbbd3986d9b245b7ec83f92da8da8602483b6 Mon Sep 17 00:00:00 2001 From: qwerty287 <80460567+qwerty287@users.noreply.github.com> Date: Wed, 14 Aug 2024 21:37:05 +0200 Subject: [PATCH] Fix lint (#4032) --- pipeline/backend/kubernetes/pod_test.go | 8 ++++---- pipeline/frontend/yaml/linter/linter.go | 2 +- server/grpc/rpc.go | 2 +- server/pipeline/approve.go | 7 ++++--- server/pipeline/create.go | 10 +++++----- server/pipeline/decline.go | 3 ++- server/pipeline/restart.go | 12 ++++++------ 7 files changed, 23 insertions(+), 21 deletions(-) diff --git a/pipeline/backend/kubernetes/pod_test.go b/pipeline/backend/kubernetes/pod_test.go index 4f7732878..4ea4cc687 100644 --- a/pipeline/backend/kubernetes/pod_test.go +++ b/pipeline/backend/kubernetes/pod_test.go @@ -65,7 +65,7 @@ func TestStepLabel(t *testing.T) { } func TestTinyPod(t *testing.T) { - expected := ` + const expected = ` { "metadata": { "name": "wp-01he8bebctabr3kgk0qj36d2me-0", @@ -149,7 +149,7 @@ func TestTinyPod(t *testing.T) { } func TestFullPod(t *testing.T) { - expected := ` + const expected = ` { "metadata": { "name": "wp-01he8bebctabr3kgk0qj36d2me-0", @@ -429,7 +429,7 @@ func TestPodPrivilege(t *testing.T) { } func TestScratchPod(t *testing.T) { - expected := ` + const expected = ` { "metadata": { "name": "wp-01he8bebctabr3kgk0qj36d2me-0", @@ -474,7 +474,7 @@ func TestScratchPod(t *testing.T) { } func TestSecrets(t *testing.T) { - expected := ` + const expected = ` { "metadata": { "name": "wp-3kgk0qj36d2me01he8bebctabr-0", diff --git a/pipeline/frontend/yaml/linter/linter.go b/pipeline/frontend/yaml/linter/linter.go index 8305a9710..3e99f1713 100644 --- a/pipeline/frontend/yaml/linter/linter.go +++ b/pipeline/frontend/yaml/linter/linter.go @@ -172,7 +172,7 @@ func (l *Linter) lintTrusted(config *WorkflowConfig, c *types.Container, area st if len(c.NetworkMode) != 0 { errors = append(errors, "Insufficient privileges to use network_mode") } - if c.Volumes.Volumes != nil && len(c.Volumes.Volumes) != 0 { + if len(c.Volumes.Volumes) != 0 { errors = append(errors, "Insufficient privileges to use volumes") } if len(c.Tmpfs) != 0 { diff --git a/server/grpc/rpc.go b/server/grpc/rpc.go index 83d366c77..ca43ea3d6 100644 --- a/server/grpc/rpc.go +++ b/server/grpc/rpc.go @@ -138,7 +138,7 @@ func (s *RPC) Update(_ context.Context, strWorkflowID string, state rpc.StepStat Int64("stepPipelineID", step.PipelineID). Int64("currentPipelineID", currentPipeline.ID). Msg(msg) - return fmt.Errorf(msg) + return errors.New(msg) } repo, err := s.store.GetRepo(currentPipeline.RepoID) diff --git a/server/pipeline/approve.go b/server/pipeline/approve.go index 374693a2c..d91840c7d 100644 --- a/server/pipeline/approve.go +++ b/server/pipeline/approve.go @@ -16,6 +16,7 @@ package pipeline import ( "context" + "errors" "fmt" "github.com/rs/zerolog/log" @@ -37,7 +38,7 @@ func Approve(ctx context.Context, store store.Store, currentPipeline *model.Pipe if err != nil { msg := fmt.Sprintf("failure to load forge for repo '%s'", repo.FullName) log.Error().Err(err).Str("repo", repo.FullName).Msg(msg) - return nil, fmt.Errorf(msg) + return nil, errors.New(msg) } // fetch the pipeline file from the database @@ -84,7 +85,7 @@ func Approve(ctx context.Context, store store.Store, currentPipeline *model.Pipe if err != nil { msg := fmt.Sprintf("failure to createPipelineItems for %s", repo.FullName) log.Error().Err(err).Msg(msg) - return nil, fmt.Errorf(msg) + return nil, errors.New(msg) } // we have no way to link old workflows and steps in database to new engine generated steps, @@ -100,7 +101,7 @@ func Approve(ctx context.Context, store store.Store, currentPipeline *model.Pipe if err != nil { msg := fmt.Sprintf("failure to start pipeline for %s: %v", repo.FullName, err) log.Error().Err(err).Msg(msg) - return nil, fmt.Errorf(msg) + return nil, errors.New(msg) } return currentPipeline, nil diff --git a/server/pipeline/create.go b/server/pipeline/create.go index 0e2d79e58..0539e8d3c 100644 --- a/server/pipeline/create.go +++ b/server/pipeline/create.go @@ -38,7 +38,7 @@ func Create(ctx context.Context, _store store.Store, repo *model.Repo, pipeline if err != nil { msg := fmt.Sprintf("failure to find repo owner via id '%d'", repo.UserID) log.Error().Err(err).Str("repo", repo.FullName).Msg(msg) - return nil, fmt.Errorf(msg) + return nil, errors.New(msg) } if pipeline.Event == model.EventPush || pipeline.Event == model.EventPull || pipeline.Event == model.EventPullClosed { @@ -57,7 +57,7 @@ func Create(ctx context.Context, _store store.Store, repo *model.Repo, pipeline if err != nil { msg := fmt.Sprintf("failure to load forge for repo '%s'", repo.FullName) log.Error().Err(err).Str("repo", repo.FullName).Msg(msg) - return nil, fmt.Errorf(msg) + return nil, errors.New(msg) } // If the forge has a refresh token, the current access token @@ -117,7 +117,7 @@ func Create(ctx context.Context, _store store.Store, repo *model.Repo, pipeline if err != nil { msg := fmt.Sprintf("failed to find or persist pipeline config for %s", repo.FullName) log.Error().Err(err).Msg(msg) - return nil, fmt.Errorf(msg) + return nil, errors.New(msg) } configs = append(configs, config) } @@ -125,7 +125,7 @@ func Create(ctx context.Context, _store store.Store, repo *model.Repo, pipeline if err := linkPipelineConfigs(_store, configs, pipeline.ID); err != nil { msg := fmt.Sprintf("failed to find or persist pipeline config for %s", repo.FullName) log.Error().Err(err).Msg(msg) - return nil, fmt.Errorf(msg) + return nil, errors.New(msg) } if err := prepareStart(ctx, _forge, _store, pipeline, repoUser, repo); err != nil { @@ -145,7 +145,7 @@ func Create(ctx context.Context, _store store.Store, repo *model.Repo, pipeline if err != nil { msg := fmt.Sprintf("failed to start pipeline for %s", repo.FullName) log.Error().Err(err).Msg(msg) - return nil, fmt.Errorf(msg) + return nil, errors.New(msg) } return pipeline, nil diff --git a/server/pipeline/decline.go b/server/pipeline/decline.go index 1f9611c5c..a4f7e48a3 100644 --- a/server/pipeline/decline.go +++ b/server/pipeline/decline.go @@ -16,6 +16,7 @@ package pipeline import ( "context" + "errors" "fmt" "github.com/rs/zerolog/log" @@ -31,7 +32,7 @@ func Decline(ctx context.Context, store store.Store, pipeline *model.Pipeline, u if err != nil { msg := fmt.Sprintf("failure to load forge for repo '%s'", repo.FullName) log.Error().Err(err).Str("repo", repo.FullName).Msg(msg) - return nil, fmt.Errorf(msg) + return nil, errors.New(msg) } if pipeline.Status != model.StatusBlocked { diff --git a/server/pipeline/restart.go b/server/pipeline/restart.go index e8b841bf1..da0888511 100644 --- a/server/pipeline/restart.go +++ b/server/pipeline/restart.go @@ -33,7 +33,7 @@ func Restart(ctx context.Context, store store.Store, lastPipeline *model.Pipelin if err != nil { msg := fmt.Sprintf("failure to load forge for repo '%s'", repo.FullName) log.Error().Err(err).Str("repo", repo.FullName).Msg(msg) - return nil, fmt.Errorf(msg) + return nil, errors.New(msg) } switch lastPipeline.Status { @@ -70,7 +70,7 @@ func Restart(ctx context.Context, store store.Store, lastPipeline *model.Pipelin if err != nil { msg := fmt.Sprintf("failure to save pipeline for %s", repo.FullName) log.Error().Err(err).Msg(msg) - return nil, fmt.Errorf(msg) + return nil, errors.New(msg) } if len(configs) == 0 { @@ -85,27 +85,27 @@ func Restart(ctx context.Context, store store.Store, lastPipeline *model.Pipelin if err := linkPipelineConfigs(store, configs, newPipeline.ID); err != nil { msg := fmt.Sprintf("failure to persist pipeline config for %s.", repo.FullName) log.Error().Err(err).Msg(msg) - return nil, fmt.Errorf(msg) + return nil, errors.New(msg) } newPipeline, pipelineItems, err := createPipelineItems(ctx, forge, store, newPipeline, user, repo, pipelineFiles, envs) if err != nil { msg := fmt.Sprintf("failure to createPipelineItems for %s", repo.FullName) log.Error().Err(err).Msg(msg) - return nil, fmt.Errorf(msg) + return nil, errors.New(msg) } if err := prepareStart(ctx, forge, store, newPipeline, user, repo); err != nil { msg := fmt.Sprintf("failure to prepare pipeline for %s", repo.FullName) log.Error().Err(err).Msg(msg) - return nil, fmt.Errorf(msg) + return nil, errors.New(msg) } newPipeline, err = start(ctx, forge, store, newPipeline, user, repo, pipelineItems) if err != nil { msg := fmt.Sprintf("failure to start pipeline for %s", repo.FullName) log.Error().Err(err).Msg(msg) - return nil, fmt.Errorf(msg) + return nil, errors.New(msg) } return newPipeline, nil