From 90e079f5c76eb841c8aa363f6a059baa29cab67a Mon Sep 17 00:00:00 2001 From: karamaru-alpha Date: Thu, 19 Oct 2023 12:45:32 +0900 Subject: [PATCH 1/5] Fix lint/go errors (goimport) Signed-off-by: karamaru-alpha --- pkg/app/piped/controller/controllermetrics/metrics.go | 3 ++- pkg/app/server/grpcapi/grpcapi_test.go | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/pkg/app/piped/controller/controllermetrics/metrics.go b/pkg/app/piped/controller/controllermetrics/metrics.go index d2f8c0e001..d42cb7feac 100644 --- a/pkg/app/piped/controller/controllermetrics/metrics.go +++ b/pkg/app/piped/controller/controllermetrics/metrics.go @@ -15,8 +15,9 @@ package controllermetrics import ( - "github.com/pipe-cd/pipecd/pkg/model" "github.com/prometheus/client_golang/prometheus" + + "github.com/pipe-cd/pipecd/pkg/model" ) const ( diff --git a/pkg/app/server/grpcapi/grpcapi_test.go b/pkg/app/server/grpcapi/grpcapi_test.go index 58def4f62b..19159b3617 100644 --- a/pkg/app/server/grpcapi/grpcapi_test.go +++ b/pkg/app/server/grpcapi/grpcapi_test.go @@ -19,11 +19,12 @@ import ( "fmt" "testing" - "github.com/pipe-cd/pipecd/pkg/datastore" - "github.com/pipe-cd/pipecd/pkg/filestore" "github.com/stretchr/testify/assert" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" + + "github.com/pipe-cd/pipecd/pkg/datastore" + "github.com/pipe-cd/pipecd/pkg/filestore" ) func TestGRPCStoreError(t *testing.T) { From dbc28192412dec411ddaed51ea24acd5600a2002 Mon Sep 17 00:00:00 2001 From: karamaru-alpha Date: Thu, 19 Oct 2023 12:51:56 +0900 Subject: [PATCH 2/5] Fix lint/go errors (staticcheck) Signed-off-by: karamaru-alpha --- pkg/model/project.go | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/pkg/model/project.go b/pkg/model/project.go index f21bc48827..ac177db764 100644 --- a/pkg/model/project.go +++ b/pkg/model/project.go @@ -209,11 +209,10 @@ func (p *ProjectStaticUser) Auth(username, password string) error { // RedactSensitiveData redacts sensitive data. func (p *ProjectSSOConfig) RedactSensitiveData() { - if p.Github != nil { - p.Github.RedactSensitiveData() - } - if p.Google != nil { + if p.Github == nil { + return } + p.Github.RedactSensitiveData() } // Update updates ProjectSSOConfig with given data. @@ -234,24 +233,22 @@ func (p *ProjectSSOConfig) Update(sso *ProjectSSOConfig) error { // Encrypt encrypts sensitive data in ProjectSSOConfig. func (p *ProjectSSOConfig) Encrypt(encrypter encrypter) error { - if p.Github != nil { - if err := p.Github.Encrypt(encrypter); err != nil { - return err - } + if p.Github == nil { + return nil } - if p.Google != nil { + if err := p.Github.Encrypt(encrypter); err != nil { + return err } return nil } // Decrypt decrypts encrypted data in ProjectSSOConfig. func (p *ProjectSSOConfig) Decrypt(decrypter decrypter) error { - if p.Github != nil { - if err := p.Github.Decrypt(decrypter); err != nil { - return err - } + if p.Github == nil { + return nil } - if p.Google != nil { + if err := p.Github.Decrypt(decrypter); err != nil { + return err } return nil } From 735182923845a69e4f822eb7f9dee108cd0a64fc Mon Sep 17 00:00:00 2001 From: karamaru-alpha Date: Thu, 19 Oct 2023 13:20:14 +0900 Subject: [PATCH 3/5] Fix lint/go errors (gosimple) Signed-off-by: karamaru-alpha --- pkg/app/piped/driftdetector/cloudrun/detector.go | 2 +- .../platformprovider/terraform/terraform.go | 16 ++++------------ pkg/model/application_live_state.go | 1 - 3 files changed, 5 insertions(+), 14 deletions(-) diff --git a/pkg/app/piped/driftdetector/cloudrun/detector.go b/pkg/app/piped/driftdetector/cloudrun/detector.go index a3fb460a3e..d707570f40 100644 --- a/pkg/app/piped/driftdetector/cloudrun/detector.go +++ b/pkg/app/piped/driftdetector/cloudrun/detector.go @@ -315,7 +315,7 @@ func makeSyncState(r *provider.DiffResult, commit string) model.ApplicationSyncS } } - shortReason := fmt.Sprintf("The service manifest doesn't be synced") + shortReason := "The service manifest doesn't be synced" if len(commit) >= 7 { commit = commit[:7] } diff --git a/pkg/app/piped/platformprovider/terraform/terraform.go b/pkg/app/piped/platformprovider/terraform/terraform.go index 2b9679f38f..8a497d916b 100644 --- a/pkg/app/piped/platformprovider/terraform/terraform.go +++ b/pkg/app/piped/platformprovider/terraform/terraform.go @@ -120,9 +120,7 @@ func (t *Terraform) Init(ctx context.Context, w io.Writer) error { "init", } args = append(args, t.makeCommonCommandArgs()...) - for _, f := range t.options.initFlags { - args = append(args, f) - } + args = append(args, t.options.initFlags...) cmd := exec.CommandContext(ctx, t.execPath, args...) cmd.Dir = t.dir @@ -278,9 +276,7 @@ func (t *Terraform) Plan(ctx context.Context, w io.Writer) (PlanResult, error) { "-detailed-exitcode", } args = append(args, t.makeCommonCommandArgs()...) - for _, f := range t.options.planFlags { - args = append(args, f) - } + args = append(args, t.options.planFlags...) var buf bytes.Buffer stdout := io.MultiWriter(w, &buf) @@ -316,9 +312,7 @@ func (t *Terraform) makeCommonCommandArgs() (args []string) { for _, f := range t.options.varFiles { args = append(args, fmt.Sprintf("-var-file=%s", f)) } - for _, f := range t.options.sharedFlags { - args = append(args, f) - } + args = append(args, t.options.sharedFlags...) return } @@ -398,9 +392,7 @@ func (t *Terraform) Apply(ctx context.Context, w io.Writer) error { "-input=false", } args = append(args, t.makeCommonCommandArgs()...) - for _, f := range t.options.applyFlags { - args = append(args, f) - } + args = append(args, t.options.applyFlags...) cmd := exec.CommandContext(ctx, t.execPath, args...) cmd.Dir = t.dir diff --git a/pkg/model/application_live_state.go b/pkg/model/application_live_state.go index 933797b2d1..077bbea2d3 100644 --- a/pkg/model/application_live_state.go +++ b/pkg/model/application_live_state.go @@ -68,7 +68,6 @@ func (s *ApplicationLiveStateSnapshot) DetermineAppHealthStatus() { case ApplicationKind_CLOUDRUN: s.determineCloudRunAppHealthStatus() } - return } func (s *ApplicationLiveStateSnapshot) determineKubernetesAppHealthStatus() { From a576384fbd92ed1f484f6f35c47f53e9c019cf01 Mon Sep 17 00:00:00 2001 From: karamaru-alpha Date: Thu, 19 Oct 2023 14:09:10 +0900 Subject: [PATCH 4/5] Fix lint/go errors (gosimple) Signed-off-by: karamaru-alpha --- pkg/model/project.go | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/pkg/model/project.go b/pkg/model/project.go index ac177db764..1a3753f9ca 100644 --- a/pkg/model/project.go +++ b/pkg/model/project.go @@ -218,17 +218,14 @@ func (p *ProjectSSOConfig) RedactSensitiveData() { // Update updates ProjectSSOConfig with given data. func (p *ProjectSSOConfig) Update(sso *ProjectSSOConfig) error { p.Provider = sso.Provider - if sso.Github != nil { - if p.Github == nil { - p.Github = &ProjectSSOConfig_GitHub{} - } - if err := p.Github.Update(sso.Github); err != nil { - return err - } + if sso.Github == nil { + return nil } - if sso.Google != nil { + + if p.Github == nil { + p.Github = &ProjectSSOConfig_GitHub{} } - return nil + return p.Github.Update(sso.Github) } // Encrypt encrypts sensitive data in ProjectSSOConfig. From d3086a077043b56e571c06b565ca99b6b8e63f75 Mon Sep 17 00:00:00 2001 From: karamaru-alpha Date: Thu, 19 Oct 2023 14:10:17 +0900 Subject: [PATCH 5/5] Fix return error by function Signed-off-by: karamaru-alpha --- pkg/model/project.go | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/pkg/model/project.go b/pkg/model/project.go index 1a3753f9ca..d7752bbb3d 100644 --- a/pkg/model/project.go +++ b/pkg/model/project.go @@ -233,10 +233,7 @@ func (p *ProjectSSOConfig) Encrypt(encrypter encrypter) error { if p.Github == nil { return nil } - if err := p.Github.Encrypt(encrypter); err != nil { - return err - } - return nil + return p.Github.Encrypt(encrypter) } // Decrypt decrypts encrypted data in ProjectSSOConfig. @@ -244,10 +241,7 @@ func (p *ProjectSSOConfig) Decrypt(decrypter decrypter) error { if p.Github == nil { return nil } - if err := p.Github.Decrypt(decrypter); err != nil { - return err - } - return nil + return p.Github.Decrypt(decrypter) } // GenerateAuthCodeURL generates an auth URL for the specified configuration.