diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 186a3d12a..c94c4a065 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -11,10 +11,10 @@ jobs: steps: - uses: actions/setup-go@v3 with: - go-version: 1.24 + go-version: 1.25 - uses: actions/checkout@v3 - name: Run golangci-lint - uses: golangci/golangci-lint-action@v3.2.0 + uses: golangci/golangci-lint-action@v8.0.0 with: - args: --timeout 3m --verbose --disable revive - version: v1.64.5 + args: --timeout 3m --verbose + version: v2.4.0 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1549c694b..577f992ca 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -24,6 +24,6 @@ jobs: && sudo cp conftest /usr/local/bin/conftest - uses: actions/setup-go@v3 with: - go-version: 1.24 + go-version: 1.25 - uses: actions/checkout@v3 - run: make test-all diff --git a/.golangci.yml b/.golangci.yml index 5986dec2e..b5cbc300a 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,38 +1,59 @@ +version: "2" linters: enable: - - errcheck + - dogsled + - dupword - gochecknoinits - # We don't use goconst because it gives false positives in the tests. - # - goconst - - gofmt - # We don't use revive because it gives false positives in the tests. - # - revive - gosec - - gosimple - - ineffassign - - staticcheck - - typecheck + - interfacebloat - unconvert - - unused - - vet - - vetshadow - - dogsled - - dupword - unparam - - interfacebloat - usestdlibvars - whitespace -issues: - exclude-rules: - - path: server/legacy/controllers/events/events_controller(.+)test.go - linters: - - dogsled - - path: server/legacy/events/event_parser_test.go - linters: - - dogsled - - path: server/legacy/events/command_runner_test.go - linters: - - dogsled -linters-settings: - interfacebloat: - max: 7 + settings: + interfacebloat: + max: 7 + staticcheck: + checks: + - all + - -QF1001 + - -QF1007 + - -QF1008 + - -QF1011 + - -ST1000 + - -ST1003 + - -ST1016 + - -ST1020 + - -ST1021 + - -ST1022 + - -ST1023 + exclusions: + generated: lax + presets: + - comments + - common-false-positives + - legacy + - std-error-handling + rules: + - linters: + - dogsled + path: server/legacy/controllers/events/events_controller(.+)test.go + - linters: + - dogsled + path: server/legacy/events/event_parser_test.go + - linters: + - dogsled + path: server/legacy/events/command_runner_test.go + paths: + - third_party$ + - builtin$ + - examples$ +formatters: + enable: + - gofmt + exclusions: + generated: lax + paths: + - third_party$ + - builtin$ + - examples$ diff --git a/Makefile b/Makefile index 88242ec2e..034fec969 100644 --- a/Makefile +++ b/Makefile @@ -61,7 +61,7 @@ lint: ## Run linter locally golangci-lint run check-lint: ## Run linter in CI/CD. If running locally use 'lint' - curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b ./bin v1.39.0 + curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b ./bin v2.4.0 ./bin/golangci-lint run -j 4 --timeout 5m check-fmt: ## Fail if not formatted diff --git a/go.mod b/go.mod index b27439258..f0de80586 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/runatlantis/atlantis -go 1.24 +go 1.25 replace google.golang.org/grpc => google.golang.org/grpc v1.45.0 diff --git a/server/config/parser_validator_test.go b/server/config/parser_validator_test.go index bc17034a6..3e057acb4 100644 --- a/server/config/parser_validator_test.go +++ b/server/config/parser_validator_test.go @@ -1090,7 +1090,7 @@ repos: act, err := r.ParseGlobalCfg(path, valid.NewGlobalCfg("somedir")) if c.expErr != "" { - expErr := strings.Replace(c.expErr, "", path, -1) + expErr := strings.ReplaceAll(c.expErr, "", path) ErrEquals(t, expErr, err) return } @@ -1405,7 +1405,7 @@ deployment_workflows: act, err := r.ParseGlobalCfg(path, valid.NewGlobalCfg("somedir")) if c.expErr != "" { - expErr := strings.Replace(c.expErr, "", path, -1) + expErr := strings.ReplaceAll(c.expErr, "", path) ErrEquals(t, expErr, err) return } diff --git a/server/config/raw/project.go b/server/config/raw/project.go index 1723de2a7..20ab2feac 100644 --- a/server/config/raw/project.go +++ b/server/config/raw/project.go @@ -118,7 +118,7 @@ func (p Project) ToValid(defaultWorkflowModeType valid.WorkflowModeType) valid.P // support any characters that must be url escaped *except* for '/' because // users like to name their projects to match the directory it's in. func validProjectName(name string) bool { - nameWithoutSlashes := strings.Replace(name, "/", "-", -1) + nameWithoutSlashes := strings.ReplaceAll(name, "/", "-") return nameWithoutSlashes == url.QueryEscape(nameWithoutSlashes) } diff --git a/server/legacy/controllers/events/events_controller_e2e_test.go b/server/legacy/controllers/events/events_controller_e2e_test.go index c2c3db631..5ec3e2b33 100644 --- a/server/legacy/controllers/events/events_controller_e2e_test.go +++ b/server/legacy/controllers/events/events_controller_e2e_test.go @@ -785,7 +785,7 @@ func GitHubPullRequestOpenedEvent(t *testing.T, headSHA string) *http.Request { }, ) // Replace sha with expected sha. - requestJSONStr := strings.Replace(pullRequestOpenedJSON, "c31fd9ea6f557ad2ea659944c3844a059b83bc5d", headSHA, -1) + requestJSONStr := strings.ReplaceAll(pullRequestOpenedJSON, "c31fd9ea6f557ad2ea659944c3844a059b83bc5d", headSHA) req, err := http.NewRequest(http.MethodPost, "/events", bytes.NewBuffer([]byte(requestJSONStr))) Ok(t, err) req.Header.Set("Content-Type", "application/json") @@ -820,7 +820,7 @@ func GitHubPullRequestReviewedEvent(t *testing.T, headSHA string) *http.Request }, ) // Replace sha with expected sha. - requestJSONStr := strings.Replace(pullRequestReviewedJSON, "c31fd9ea6f557ad2ea659944c3844a059b83bc5d", headSHA, -1) + requestJSONStr := strings.ReplaceAll(pullRequestReviewedJSON, "c31fd9ea6f557ad2ea659944c3844a059b83bc5d", headSHA) req, err := http.NewRequest(http.MethodPost, "/events", bytes.NewBuffer([]byte(requestJSONStr))) Ok(t, err) req.Header.Set("Content-Type", "application/json") diff --git a/server/legacy/controllers/events/handlers/pull_request.go b/server/legacy/controllers/events/handlers/pull_request.go index d3ffdb38f..8d44087dd 100644 --- a/server/legacy/controllers/events/handlers/pull_request.go +++ b/server/legacy/controllers/events/handlers/pull_request.go @@ -120,7 +120,7 @@ func (h *PullRequestEvent) Handle(ctx context.Context, request *http.BufferedReq eventType := event.EventType if !h.RepoAllowlistChecker.IsAllowlisted(baseRepo.FullName, baseRepo.VCSHost.Hostname) { - return fmt.Errorf("Pull request event from non-allowlisted repo \"%s/%s\"", baseRepo.VCSHost.Hostname, baseRepo.FullName) + return fmt.Errorf("Pull request event from non-allowlisted repo \"%s/%s\"", baseRepo.VCSHost.Hostname, baseRepo.FullName) // nolint:staticcheck } switch eventType { diff --git a/server/legacy/controllers/websocket/instrumented_mux.go b/server/legacy/controllers/websocket/instrumented_mux.go index 66d7c90d0..d1644417b 100644 --- a/server/legacy/controllers/websocket/instrumented_mux.go +++ b/server/legacy/controllers/websocket/instrumented_mux.go @@ -1,8 +1,9 @@ package websocket import ( - "github.com/uber-go/tally/v4" "net/http" + + "github.com/uber-go/tally/v4" ) type InstrumentedMultiplexor struct { diff --git a/server/legacy/core/runtime/apply_step_runner.go b/server/legacy/core/runtime/apply_step_runner.go index fe3dfad98..21ef2aa92 100644 --- a/server/legacy/core/runtime/apply_step_runner.go +++ b/server/legacy/core/runtime/apply_step_runner.go @@ -201,7 +201,7 @@ func (a *ApplyStepRunner) remotePlanChanged(planfileContents string, applyOut st // Strip plan output after the prompt to execute the plan. planEndIdx := strings.Index(output, "Do you want to perform these actions in workspace \"") if planEndIdx < 0 { - return fmt.Errorf("Couldn't find plan end when parsing apply output:\n%q", applyOut) + return fmt.Errorf("Couldn't find plan end when parsing apply output:\n%q", applyOut) // nolint:staticcheck } currPlan := strings.TrimSpace(output[:planEndIdx]) diff --git a/server/legacy/core/runtime/policy/conftest_executor.go b/server/legacy/core/runtime/policy/conftest_executor.go index 70479ebb3..0ee46126e 100644 --- a/server/legacy/core/runtime/policy/conftest_executor.go +++ b/server/legacy/core/runtime/policy/conftest_executor.go @@ -123,7 +123,7 @@ func (c *ConfTestExecutor) buildTitle(policySetNames []string) string { } func (c *ConfTestExecutor) sanitizeOutput(inputFile string, output string) string { - return strings.Replace(output, inputFile, "", -1) + return strings.ReplaceAll(output, inputFile, "") } func (c *ConfTestExecutor) processOutput(output string, policySet valid.PolicySet, err error) string { diff --git a/server/legacy/core/runtime/pre_workflow_hook_runner_test.go b/server/legacy/core/runtime/pre_workflow_hook_runner_test.go index e95839951..da055d96c 100644 --- a/server/legacy/core/runtime/pre_workflow_hook_runner_test.go +++ b/server/legacy/core/runtime/pre_workflow_hook_runner_test.go @@ -72,7 +72,7 @@ func TestPreWorkflowHookRunner_Run(t *testing.T) { // Replace $DIR in the exp with the actual temp dir. We do this // here because when constructing the cases we don't yet know the // temp dir. - expOut := strings.Replace(c.ExpOut, "$DIR", tmpDir, -1) + expOut := strings.ReplaceAll(c.ExpOut, "$DIR", tmpDir) Equals(t, expOut, out) }) } diff --git a/server/legacy/core/runtime/run_step_runner_test.go b/server/legacy/core/runtime/run_step_runner_test.go index 5254e24fc..a43d220b3 100644 --- a/server/legacy/core/runtime/run_step_runner_test.go +++ b/server/legacy/core/runtime/run_step_runner_test.go @@ -146,7 +146,7 @@ func TestRunStepRunner_Run(t *testing.T) { // Replace $DIR in the exp with the actual temp dir. We do this // here because when constructing the cases we don't yet know the // temp dir. - expOut := strings.Replace(c.ExpOut, "$DIR", tmpDir, -1) + expOut := strings.ReplaceAll(c.ExpOut, "$DIR", tmpDir) Equals(t, expOut, out) terraform.VerifyWasCalledOnce().EnsureVersion(logger, projVersion) diff --git a/server/legacy/core/runtime/runtime.go b/server/legacy/core/runtime/runtime.go index 7a6b256fa..20ffa76ea 100644 --- a/server/legacy/core/runtime/runtime.go +++ b/server/legacy/core/runtime/runtime.go @@ -89,7 +89,7 @@ func GetPlanFilename(workspace string, projName string) string { if projName == "" { return fmt.Sprintf("%s.tfplan", workspace) } - projName = strings.Replace(projName, "/", planfileSlashReplace, -1) + projName = strings.ReplaceAll(projName, "/", planfileSlashReplace) return fmt.Sprintf("%s-%s.tfplan", projName, workspace) } @@ -115,5 +115,5 @@ func ProjectNameFromPlanfile(workspace string, filename string) (string, error) return "", nil } rawProjName := projMatch[0][1] - return strings.Replace(rawProjName, planfileSlashReplace, "/", -1), nil + return strings.ReplaceAll(rawProjName, planfileSlashReplace, "/"), nil } diff --git a/server/legacy/events/command/project_context.go b/server/legacy/events/command/project_context.go index 1eb88ab84..bd8c9a013 100644 --- a/server/legacy/events/command/project_context.go +++ b/server/legacy/events/command/project_context.go @@ -185,7 +185,7 @@ func (p ProjectContext) GetShowResultFileName() string { if p.ProjectName == "" { return fmt.Sprintf("%s.json", p.Workspace) } - projName := strings.Replace(p.ProjectName, "/", planfileSlashReplace, -1) + projName := strings.ReplaceAll(p.ProjectName, "/", planfileSlashReplace) return fmt.Sprintf("%s-%s.json", projName, p.Workspace) } diff --git a/server/legacy/events/command_runner_test.go b/server/legacy/events/command_runner_test.go index 3fe4db789..d54c9bc71 100644 --- a/server/legacy/events/command_runner_test.go +++ b/server/legacy/events/command_runner_test.go @@ -36,7 +36,6 @@ import ( lockingmocks "github.com/runatlantis/atlantis/server/legacy/core/locking/mocks" "github.com/runatlantis/atlantis/server/legacy/events" "github.com/runatlantis/atlantis/server/legacy/events/mocks" - eventmocks "github.com/runatlantis/atlantis/server/legacy/events/mocks" "github.com/runatlantis/atlantis/server/legacy/events/mocks/matchers" vcsmocks "github.com/runatlantis/atlantis/server/legacy/events/vcs/mocks" "github.com/runatlantis/atlantis/server/models" @@ -85,7 +84,7 @@ func setup(t *testing.T) *vcsmocks.MockClient { Ok(t, err) drainer = &events.Drainer{} - deleteLockCommand = eventmocks.NewMockDeleteLockCommand() + deleteLockCommand = mocks.NewMockDeleteLockCommand() applyLockChecker = lockingmocks.NewMockApplyLockChecker() dbUpdater = &events.DBUpdater{ diff --git a/server/legacy/events/matchers/logging_logger.go b/server/legacy/events/matchers/logging_logger.go index d43fd90e9..19eae48f9 100644 --- a/server/legacy/events/matchers/logging_logger.go +++ b/server/legacy/events/matchers/logging_logger.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + logging "github.com/runatlantis/atlantis/server/logging" ) diff --git a/server/legacy/events/matchers/models_pullrequest.go b/server/legacy/events/matchers/models_pullrequest.go index 94e36a1ab..eff31445d 100644 --- a/server/legacy/events/matchers/models_pullrequest.go +++ b/server/legacy/events/matchers/models_pullrequest.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + models "github.com/runatlantis/atlantis/server/models" ) diff --git a/server/legacy/events/matchers/models_repo.go b/server/legacy/events/matchers/models_repo.go index b36c3ee7c..bcf147850 100644 --- a/server/legacy/events/matchers/models_repo.go +++ b/server/legacy/events/matchers/models_repo.go @@ -2,9 +2,10 @@ package matchers import ( - "github.com/petergtz/pegomock" "reflect" + "github.com/petergtz/pegomock" + models "github.com/runatlantis/atlantis/server/models" ) diff --git a/server/legacy/events/mock_workingdir_test.go b/server/legacy/events/mock_workingdir_test.go index c0a932289..77ded22d2 100644 --- a/server/legacy/events/mock_workingdir_test.go +++ b/server/legacy/events/mock_workingdir_test.go @@ -4,11 +4,12 @@ package events import ( + "reflect" + "time" + pegomock "github.com/petergtz/pegomock" logging "github.com/runatlantis/atlantis/server/logging" models "github.com/runatlantis/atlantis/server/models" - "reflect" - "time" ) type MockWorkingDir struct { diff --git a/server/legacy/events/pending_plan_finder_test.go b/server/legacy/events/pending_plan_finder_test.go index bafadfad0..5eafd14cb 100644 --- a/server/legacy/events/pending_plan_finder_test.go +++ b/server/legacy/events/pending_plan_finder_test.go @@ -202,7 +202,7 @@ func TestPendingPlanFinder_Find(t *testing.T) { // Replace the actual dir with ??? to allow for comparison. var actPlansComparable []events.PendingPlan for _, p := range actPlans { - p.RepoDir = strings.Replace(p.RepoDir, tmpDir, "???", -1) + p.RepoDir = strings.ReplaceAll(p.RepoDir, tmpDir, "???") actPlansComparable = append(actPlansComparable, p) } Equals(t, c.expPlans, actPlansComparable) diff --git a/server/legacy/events/project_command_builder_test.go b/server/legacy/events/project_command_builder_test.go index 412555569..14feca4bc 100644 --- a/server/legacy/events/project_command_builder_test.go +++ b/server/legacy/events/project_command_builder_test.go @@ -925,7 +925,7 @@ projects: "main.tf": fmt.Sprintf(baseVersionConfig, exactSymbols[0]), }, "project2": map[string]interface{}{ - "main.tf": strings.Replace(fmt.Sprintf(baseVersionConfig, exactSymbols[0]), "0.12.8", "0.12.9", -1), + "main.tf": strings.ReplaceAll(fmt.Sprintf(baseVersionConfig, exactSymbols[0]), "0.12.8", "0.12.9"), }, }, ModifiedFiles: []string{"project1/main.tf", "project2/main.tf"}, diff --git a/server/legacy/events/size_limited_project_command_builder.go b/server/legacy/events/size_limited_project_command_builder.go index 136a2f34f..7e2f2f915 100644 --- a/server/legacy/events/size_limited_project_command_builder.go +++ b/server/legacy/events/size_limited_project_command_builder.go @@ -41,6 +41,7 @@ func (b *SizeLimitedProjectCommandBuilder) CheckAgainstLimit(projects []command. } if b.Limit != InfiniteProjectsPerPR && len(planCommands) > b.Limit { + // nolint:staticcheck return fmt.Errorf( "Number of projects cannot exceed %d. This can either be caused by:\n"+ "1) GH failure in recognizing the diff\n"+ diff --git a/server/legacy/events/vcs/fixtures/fixtures.go b/server/legacy/events/vcs/fixtures/fixtures.go index 4ce4e184b..f2b79e2cd 100644 --- a/server/legacy/events/vcs/fixtures/fixtures.go +++ b/server/legacy/events/vcs/fixtures/fixtures.go @@ -335,7 +335,7 @@ func validateGithubToken(tokenString string) error { token, err := jwt.Parse(tokenString, func(token *jwt.Token) (interface{}, error) { // Don't forget to validate the alg is what you expect: if _, ok := token.Method.(*jwt.SigningMethodRSA); !ok { - err := fmt.Errorf("Unexpected signing method: %v", token.Header["alg"]) + err := fmt.Errorf("Unexpected signing method: %v", token.Header["alg"]) // nolint:staticcheck return nil, err } @@ -347,7 +347,7 @@ func validateGithubToken(tokenString string) error { } if claims, ok := token.Claims.(jwt.MapClaims); !ok || !token.Valid || claims["iss"] != "1" { - return fmt.Errorf("Invalid token") + return fmt.Errorf("Invalid token") // nolint:staticcheck } return nil } diff --git a/server/legacy/events/vcs/github_client_lyft_test.go b/server/legacy/events/vcs/github_client_lyft_test.go index 8fafe82d0..e12042587 100644 --- a/server/legacy/events/vcs/github_client_lyft_test.go +++ b/server/legacy/events/vcs/github_client_lyft_test.go @@ -166,14 +166,12 @@ func TestLyftGithubClient_PullisMergeable_BlockedStatus(t *testing.T) { w.Write([]byte(pullResponse)) // nolint: errcheck return case "/api/v3/repos/owner/repo/commits/2/status?per_page=100": - _, _ = w.Write([]byte( - fmt.Sprintf(combinedStatusJSON, strings.Join(c.statuses, ",")), - )) // nolint: errcheck + _, _ = fmt.Fprintf(w, + combinedStatusJSON, strings.Join(c.statuses, ",")) // nolint: errcheck return case "/api/v3/repos/owner/repo/commits/2/check-runs?per_page=100": - _, _ = w.Write([]byte( - fmt.Sprintf(combinedChecksJSON, strings.Join(c.checks, ",")), - )) + _, _ = fmt.Fprintf(w, + combinedChecksJSON, strings.Join(c.checks, ",")) return default: t.Errorf("got unexpected request at %q", r.RequestURI) diff --git a/server/legacy/events/vcs/github_client_test.go b/server/legacy/events/vcs/github_client_test.go index ecd67c1ad..9bdedfb27 100644 --- a/server/legacy/events/vcs/github_client_test.go +++ b/server/legacy/events/vcs/github_client_test.go @@ -515,12 +515,11 @@ func TestGithubClient_PullIsMergeable(t *testing.T) { w.Write([]byte(response)) // nolint: errcheck return case "/api/v3/repos/owner/repo/commits/2/status?per_page=100": - _, _ = w.Write([]byte( - fmt.Sprintf(combinedStatusJSON, fmt.Sprintf(statusJSON, "success", "some_status")), - )) // nolint: errcheck + _, _ = fmt.Fprintf(w, + combinedStatusJSON, fmt.Sprintf(statusJSON, "success", "some_status")) // nolint: errcheck return case "/api/v3/repos/owner/repo/commits/2/check-runs?per_page=100": - _, _ = w.Write([]byte(fmt.Sprintf(checksJSON, "completed", "success"))) + _, _ = fmt.Fprintf(w, checksJSON, "completed", "success") return default: t.Errorf("got unexpected request at %q", r.RequestURI) @@ -662,14 +661,12 @@ func TestGithubClient_PullisMergeable_BlockedStatus(t *testing.T) { http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { switch r.RequestURI { case "/api/v3/repos/owner/repo/commits/2/status?per_page=100": - _, _ = w.Write([]byte( - fmt.Sprintf(combinedStatusJSON, strings.Join(c.statuses, ",")), - )) // nolint: errcheck + _, _ = fmt.Fprintf(w, + combinedStatusJSON, strings.Join(c.statuses, ",")) // nolint: errcheck return case "/api/v3/repos/owner/repo/commits/2/check-runs?per_page=100": - _, _ = w.Write([]byte( - fmt.Sprintf(combinedChecksJSON, len(c.checks), strings.Join(c.checks, ",")), - )) + _, _ = fmt.Fprintf(w, + combinedChecksJSON, len(c.checks), strings.Join(c.checks, ",")) return case "/api/v3/repos/owner/repo/pulls/1": w.Write([]byte(pullResponse)) // nolint: errcheck diff --git a/server/legacy/events/working_dir.go b/server/legacy/events/working_dir.go index 1e57b881e..7c5af3f5a 100644 --- a/server/legacy/events/working_dir.go +++ b/server/legacy/events/working_dir.go @@ -331,6 +331,6 @@ func (w *FileWorkspace) cloneDir(r models.Repo, p models.PullRequest, workspace // sanitizeGitCredentials replaces any git clone urls that contain credentials // in s with the sanitized versions. func (w *FileWorkspace) sanitizeGitCredentials(s string, base models.Repo, head models.Repo) string { - baseReplaced := strings.Replace(s, base.CloneURL, base.SanitizedCloneURL, -1) - return strings.Replace(baseReplaced, head.CloneURL, head.SanitizedCloneURL, -1) + baseReplaced := strings.ReplaceAll(s, base.CloneURL, base.SanitizedCloneURL) + return strings.ReplaceAll(baseReplaced, head.CloneURL, head.SanitizedCloneURL) } diff --git a/server/legacy/events/working_dir_locker.go b/server/legacy/events/working_dir_locker.go index 7642e0ca2..22ddf9ef4 100644 --- a/server/legacy/events/working_dir_locker.go +++ b/server/legacy/events/working_dir_locker.go @@ -63,6 +63,7 @@ func (d *DefaultWorkingDirLocker) TryLockPull(repoFullName string, pullNum int) pullKey := d.pullKey(repoFullName, pullNum) for _, l := range d.locks { if l == pullKey || strings.HasPrefix(l, pullKey+"/") { + // nolint:staticcheck return func() {}, fmt.Errorf("The Atlantis working dir is currently locked by another" + " command that is running for this pull request.\n" + "Wait until the previous command is complete and try again.") @@ -82,6 +83,7 @@ func (d *DefaultWorkingDirLocker) TryLock(repoFullName string, pullNum int, work workspaceKey := d.workspaceKey(repoFullName, pullNum, workspace) for _, l := range d.locks { if l == pullKey || l == workspaceKey { + // nolint:staticcheck return func() {}, fmt.Errorf("The %s workspace is currently locked by another"+ " command that is running for this pull request.\n"+ "Wait until the previous command is complete and try again.", workspace) diff --git a/server/legacy/server.go b/server/legacy/server.go index 942479243..dc85a7530 100644 --- a/server/legacy/server.go +++ b/server/legacy/server.go @@ -899,7 +899,7 @@ func (s *Server) Start() error { s.CtxLogger.Error(err.Error()) } - ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) // nolint: vet + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() if err := server.Shutdown(ctx); err != nil { return cli.NewExitError(fmt.Sprintf("while shutting down: %s", err), 1) @@ -1012,7 +1012,7 @@ func ParseAtlantisURL(u string) (*url.URL, error) { if err != nil { return nil, err } - if !(parsed.Scheme == "http" || parsed.Scheme == "https") { + if parsed.Scheme != "http" && parsed.Scheme != "https" { return nil, errors.New("http or https must be specified") } // We want the path to end without a trailing slash so we know how to diff --git a/server/models/models.go b/server/models/models.go index ff81ecfa6..55c888620 100644 --- a/server/models/models.go +++ b/server/models/models.go @@ -98,7 +98,7 @@ func NewRepo(vcsHostType VCSHostType, repoFullName string, cloneURL string, vcsU // We url encode because we're using them in a URL and weird characters can // mess up git. - cloneURL = strings.Replace(cloneURL, " ", "%20", -1) + cloneURL = strings.ReplaceAll(cloneURL, " ", "%20") escapedVCSUser := url.QueryEscape(vcsUser) escapedVCSToken := url.QueryEscape(vcsToken) auth := fmt.Sprintf("%s:%s@", escapedVCSUser, escapedVCSToken) @@ -106,10 +106,10 @@ func NewRepo(vcsHostType VCSHostType, repoFullName string, cloneURL string, vcsU // Construct clone urls with http and https auth. Need to do both // because Bitbucket supports http. - authedCloneURL := strings.Replace(cloneURL, "https://", "https://"+auth, -1) - authedCloneURL = strings.Replace(authedCloneURL, "http://", "http://"+auth, -1) - sanitizedCloneURL := strings.Replace(cloneURL, "https://", "https://"+redactedAuth, -1) - sanitizedCloneURL = strings.Replace(sanitizedCloneURL, "http://", "http://"+redactedAuth, -1) + authedCloneURL := strings.ReplaceAll(cloneURL, "https://", "https://"+auth) + authedCloneURL = strings.ReplaceAll(authedCloneURL, "http://", "http://"+auth) + sanitizedCloneURL := strings.ReplaceAll(cloneURL, "https://", "https://"+redactedAuth) + sanitizedCloneURL = strings.ReplaceAll(sanitizedCloneURL, "http://", "http://"+redactedAuth) // Get the owner and repo names from the full name. owner, repo := SplitRepoFullName(repoFullName) diff --git a/server/neptune/adhoc/adhocexecutionhelpers/adhoc_execution_params.go b/server/neptune/adhoc/adhocexecutionhelpers/adhoc_execution_params.go index cae5502de..a03c9ca26 100644 --- a/server/neptune/adhoc/adhocexecutionhelpers/adhoc_execution_params.go +++ b/server/neptune/adhoc/adhocexecutionhelpers/adhoc_execution_params.go @@ -4,7 +4,6 @@ import ( "context" "github.com/pkg/errors" - "github.com/runatlantis/atlantis/server/neptune/gateway/config" root_config "github.com/runatlantis/atlantis/server/neptune/gateway/config" "github.com/runatlantis/atlantis/server/neptune/workflows/activities/github" "github.com/runatlantis/atlantis/server/neptune/workflows/activities/terraform" @@ -44,7 +43,7 @@ func ConstructAdhocExecParams( return AdhocTerraformWorkflowExecutionParams{}, errors.Wrap(err, "converting commit") } - opts := config.BuilderOptions{ + opts := root_config.BuilderOptions{ RepoFetcherOptions: &internal_gh.RepoFetcherOptions{ CloneDepth: 1, SimplePath: true, diff --git a/server/neptune/adhoc/adhocexecutionhelpers/root_helpers_test.go b/server/neptune/adhoc/adhocexecutionhelpers/root_helpers_test.go index f818ef172..ade3ab7ec 100644 --- a/server/neptune/adhoc/adhocexecutionhelpers/root_helpers_test.go +++ b/server/neptune/adhoc/adhocexecutionhelpers/root_helpers_test.go @@ -3,7 +3,6 @@ package adhoc import ( "testing" - "github.com/runatlantis/atlantis/server/config/valid" v "github.com/runatlantis/atlantis/server/config/valid" "github.com/runatlantis/atlantis/server/neptune/workflows" "github.com/runatlantis/atlantis/server/neptune/workflows/activities/execute" @@ -12,11 +11,11 @@ import ( func TestPrependPlanEnvSteps(t *testing.T) { tests := []struct { - cfg *valid.MergedProjectCfg + cfg *v.MergedProjectCfg expectedSteps []workflows.Step }{ { - cfg: &valid.MergedProjectCfg{ + cfg: &v.MergedProjectCfg{ Tags: map[string]string{"manifest_path": "manifest_path"}, DeploymentWorkflow: v.Workflow{ Plan: v.Stage{ @@ -48,7 +47,7 @@ func TestPrependPlanEnvSteps(t *testing.T) { }, }, { - cfg: &valid.MergedProjectCfg{ + cfg: &v.MergedProjectCfg{ Tags: map[string]string{"foo": "foo"}, DeploymentWorkflow: v.Workflow{ Plan: v.Stage{ diff --git a/server/neptune/exec/exec_test.go b/server/neptune/exec/exec_test.go index 2ce74be73..07c9ead78 100644 --- a/server/neptune/exec/exec_test.go +++ b/server/neptune/exec/exec_test.go @@ -2,10 +2,11 @@ package exec_test import ( "context" + "testing" + "github.com/runatlantis/atlantis/server/logging" subprocess_exec "github.com/runatlantis/atlantis/server/neptune/exec" "github.com/stretchr/testify/assert" - "testing" ) func TestCmd_RunWithNewProcessGroup(t *testing.T) { diff --git a/server/neptune/gateway/api/deploy.go b/server/neptune/gateway/api/deploy.go index 549262d19..d3f7bb5e7 100644 --- a/server/neptune/gateway/api/deploy.go +++ b/server/neptune/gateway/api/deploy.go @@ -2,6 +2,7 @@ package api import ( "context" + "github.com/runatlantis/atlantis/server/logging" "github.com/runatlantis/atlantis/server/neptune/gateway/api/request" "github.com/runatlantis/atlantis/server/neptune/gateway/deploy" diff --git a/server/neptune/gateway/config/root_config_builder_test.go b/server/neptune/gateway/config/root_config_builder_test.go index 29d233e5b..0987f4d2e 100644 --- a/server/neptune/gateway/config/root_config_builder_test.go +++ b/server/neptune/gateway/config/root_config_builder_test.go @@ -17,7 +17,8 @@ import ( var rcb config.Builder var globalCfg valid.GlobalCfg -var expectedErr = errors.New("some error") //nolint:revive // error name is fine for testing purposes +var errTest = errors.New("some error") + const testRoot = "testroot" func setupTesting(t *testing.T) { @@ -147,7 +148,7 @@ func TestRootConfigBuilder_DetermineRootsError(t *testing.T) { Sha: "1234", } mockRootFinder := &mockRootFinder{ - error: expectedErr, + error: errTest, } rcb.Strategy.RootFinder = mockRootFinder projectConfigs, err := rcb.Build(context.Background(), commit, 2) @@ -166,7 +167,7 @@ func TestRootConfigBuilder_ParserValidatorParseError(t *testing.T) { Sha: "1234", } mockParserValidator := &mockParserValidator{ - error: expectedErr, + error: errTest, } rcb.ParserValidator = mockParserValidator projectConfigs, err := rcb.Build(context.Background(), commit, 2) @@ -185,7 +186,7 @@ func TestRootConfigBuilder_GetModifiedFilesError(t *testing.T) { Sha: "1234", } rcb.Strategy.FileFetcher = &mockFileFetcher{ - error: expectedErr, + error: errTest, } projectConfigs, err := rcb.Build(context.Background(), commit, 2) assert.Error(t, err) @@ -203,7 +204,7 @@ func TestRootConfigBuilder_CloneError(t *testing.T) { Sha: "1234", } rcb.RepoFetcher = &mockRepoFetcher{ - cloneError: expectedErr, + cloneError: errTest, } projectConfigs, err := rcb.Build(context.Background(), commit, 2) assert.Error(t, err) @@ -221,7 +222,7 @@ func TestRootConfigBuilder_HooksRunnerError(t *testing.T) { Sha: "1234", } mockHooksRunner := &mockHooksRunner{ - error: expectedErr, + error: errTest, } rcb.HooksRunner = mockHooksRunner projectConfigs, err := rcb.Build(context.Background(), commit, 2) diff --git a/server/neptune/gateway/deploy/signaler_test.go b/server/neptune/gateway/deploy/signaler_test.go index af347947a..3d56a7cf6 100644 --- a/server/neptune/gateway/deploy/signaler_test.go +++ b/server/neptune/gateway/deploy/signaler_test.go @@ -15,7 +15,7 @@ import ( "go.temporal.io/sdk/client" ) -var expectedErr = errors.New("some error") //nolint:revive // error name is fine for testing purposes +var errTest = errors.New("some error") type testRun struct{} @@ -44,7 +44,7 @@ type testSignaler struct { expectedOptions client.StartWorkflowOptions expectedWorkflow interface{} expectedWorkflowArgs interface{} - expectedErr error + errTest error called bool } @@ -56,7 +56,7 @@ func (s *testSignaler) SignalWorkflow(ctx context.Context, workflowID string, ru assert.Equal(s.t, s.expectedSignalName, signalName) assert.Equal(s.t, s.expectedSignalArg, arg) - return s.expectedErr + return s.errTest } func (s *testSignaler) SignalWithStartWorkflow(ctx context.Context, workflowID string, signalName string, signalArg interface{}, @@ -70,7 +70,7 @@ func (s *testSignaler) SignalWithStartWorkflow(ctx context.Context, workflowID s assert.IsType(s.t, s.expectedWorkflow, workflow) assert.Equal(s.t, []interface{}{s.expectedWorkflowArgs}, workflowArgs) - return testRun{}, s.expectedErr + return testRun{}, s.errTest } func TestSignalWithStartWorkflow_Success(t *testing.T) { @@ -332,7 +332,7 @@ func TestSignalWithStartWorkflow_Failure(t *testing.T) { Name: rootCfg.Name, }, }, - expectedErr: expectedErr, + errTest: errTest, } deploySignaler := deploy.WorkflowSignaler{ TemporalClient: testSignaler, diff --git a/server/neptune/gateway/server.go b/server/neptune/gateway/server.go index 53e5fb466..ff6e789e0 100644 --- a/server/neptune/gateway/server.go +++ b/server/neptune/gateway/server.go @@ -30,7 +30,6 @@ import ( "github.com/runatlantis/atlantis/server/neptune/gateway/event/preworkflow" httpInternal "github.com/runatlantis/atlantis/server/neptune/http" "github.com/runatlantis/atlantis/server/neptune/lyft/feature" - "github.com/runatlantis/atlantis/server/neptune/sync" internalSync "github.com/runatlantis/atlantis/server/neptune/sync" "github.com/runatlantis/atlantis/server/neptune/sync/crons" "github.com/runatlantis/atlantis/server/neptune/temporal" @@ -78,7 +77,7 @@ type Server struct { Logger logging.Logger Port int Drainer *events.Drainer - Scheduler *sync.AsyncScheduler + Scheduler *internalSync.AsyncScheduler Server httpInternal.ServerProxy TemporalClient client.Client CronScheduler *internalSync.CronScheduler @@ -186,11 +185,11 @@ func NewServer(config Config) (*Server, error) { GithubUser: config.GithubAppSlug, } - syncScheduler := &sync.SynchronousScheduler{ + syncScheduler := &internalSync.SynchronousScheduler{ Logger: ctxLogger, PanicRecoveryEnabled: true, } - asyncScheduler := sync.NewAsyncScheduler(ctxLogger, syncScheduler) + asyncScheduler := internalSync.NewAsyncScheduler(ctxLogger, syncScheduler) vcsStatusUpdater := &command.VCSStatusUpdater{Client: vcsClient, TitleBuilder: vcs.StatusTitleBuilder{TitlePrefix: config.GithubStatusName}} repoConverter := github_converter.RepoConverter{} diff --git a/server/neptune/lyft/activities/sns/writer.go b/server/neptune/lyft/activities/sns/writer.go index e8256d176..390826993 100644 --- a/server/neptune/lyft/activities/sns/writer.go +++ b/server/neptune/lyft/activities/sns/writer.go @@ -2,12 +2,11 @@ package sns import ( "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/sns" awsSns "github.com/aws/aws-sdk-go/service/sns" ) type snsPublisher interface { - Publish(*sns.PublishInput) (*sns.PublishOutput, error) + Publish(*awsSns.PublishInput) (*awsSns.PublishOutput, error) } type Writer struct { diff --git a/server/neptune/lyft/feature/retriever.go b/server/neptune/lyft/feature/retriever.go index 57f7e23b0..210716003 100644 --- a/server/neptune/lyft/feature/retriever.go +++ b/server/neptune/lyft/feature/retriever.go @@ -2,6 +2,7 @@ package feature import ( "context" + "github.com/pkg/errors" gh "github.com/runatlantis/atlantis/server/vcs/provider/github" ) diff --git a/server/neptune/sync/crons/ratelimit_stats.go b/server/neptune/sync/crons/ratelimit_stats.go index 9382ab014..5d3db177c 100644 --- a/server/neptune/sync/crons/ratelimit_stats.go +++ b/server/neptune/sync/crons/ratelimit_stats.go @@ -2,11 +2,12 @@ package crons import ( "context" + "net/http" + "github.com/palantir/go-githubapp/githubapp" "github.com/pkg/errors" "github.com/runatlantis/atlantis/server/metrics" "github.com/uber-go/tally/v4" - "net/http" ) const ( diff --git a/server/neptune/template/loader.go b/server/neptune/template/loader.go index 7d88f215f..ec286b091 100644 --- a/server/neptune/template/loader.go +++ b/server/neptune/template/loader.go @@ -94,7 +94,7 @@ func (l Loader[T]) Load(id Key, repo models.Repo, data T) (string, error) { buf := &bytes.Buffer{} if err := tmpl.Execute(buf, data); err != nil { - return "", fmt.Errorf("Failed to render template: %v", err) + return "", fmt.Errorf("Failed to render template: %v", err) // nolint:staticcheck } return buf.String(), nil } diff --git a/server/neptune/temporal/propagator.go b/server/neptune/temporal/propagator.go index 078f5330d..9082335fb 100644 --- a/server/neptune/temporal/propagator.go +++ b/server/neptune/temporal/propagator.go @@ -2,6 +2,7 @@ package temporal import ( "context" + internalContext "github.com/runatlantis/atlantis/server/neptune/context" "github.com/pkg/errors" diff --git a/server/neptune/workflows/activities/conftest.go b/server/neptune/workflows/activities/conftest.go index 4402b41d8..a94646fa9 100644 --- a/server/neptune/workflows/activities/conftest.go +++ b/server/neptune/workflows/activities/conftest.go @@ -4,11 +4,12 @@ import ( "bytes" "context" "fmt" + "strings" + "github.com/hashicorp/go-version" "github.com/runatlantis/atlantis/server/neptune/workflows/activities/command" "github.com/runatlantis/atlantis/server/neptune/workflows/activities/temporal" "go.temporal.io/sdk/activity" - "strings" ) type asyncClient interface { @@ -137,7 +138,7 @@ func (c *conftestActivity) buildTitle(policySetNames []string) string { } func (c *conftestActivity) sanitizeOutput(inputFile string, output string) string { - return strings.Replace(output, inputFile, "", -1) + return strings.ReplaceAll(output, inputFile, "") } func (c *conftestActivity) processOutput(output string, policySet PolicySet, err error) string { diff --git a/server/neptune/workflows/activities/conftest/summary.go b/server/neptune/workflows/activities/conftest/summary.go index 7b1cc0231..d2eb935dd 100644 --- a/server/neptune/workflows/activities/conftest/summary.go +++ b/server/neptune/workflows/activities/conftest/summary.go @@ -2,8 +2,9 @@ package conftest import ( "fmt" - "github.com/runatlantis/atlantis/server/neptune/workflows/activities" "strings" + + "github.com/runatlantis/atlantis/server/neptune/workflows/activities" ) type ValidateSummary struct { diff --git a/server/neptune/workflows/activities/conftest/summary_test.go b/server/neptune/workflows/activities/conftest/summary_test.go index 5d8d509ce..4892f0354 100644 --- a/server/neptune/workflows/activities/conftest/summary_test.go +++ b/server/neptune/workflows/activities/conftest/summary_test.go @@ -1,9 +1,10 @@ package conftest import ( + "testing" + "github.com/runatlantis/atlantis/server/neptune/workflows/activities" "gopkg.in/go-playground/assert.v1" - "testing" ) func TestNewValidateSummaryFromResults(t *testing.T) { diff --git a/server/neptune/workflows/activities/conftest_test.go b/server/neptune/workflows/activities/conftest_test.go index 5d3d264d6..b45681133 100644 --- a/server/neptune/workflows/activities/conftest_test.go +++ b/server/neptune/workflows/activities/conftest_test.go @@ -1,12 +1,13 @@ package activities import ( + "strings" + "testing" + "github.com/hashicorp/go-version" "github.com/runatlantis/atlantis/server/neptune/workflows/activities/command" "github.com/stretchr/testify/assert" "go.temporal.io/sdk/testsuite" - "strings" - "testing" ) func TestConftest_RequestValidation(t *testing.T) { diff --git a/server/neptune/workflows/activities/github/markdown/renderer.go b/server/neptune/workflows/activities/github/markdown/renderer.go index da4f822a0..0cddad60d 100644 --- a/server/neptune/workflows/activities/github/markdown/renderer.go +++ b/server/neptune/workflows/activities/github/markdown/renderer.go @@ -4,9 +4,10 @@ import ( "bytes" _ "embed" //embedding files "fmt" + "html/template" + "github.com/runatlantis/atlantis/server/neptune/workflows/activities/github" "github.com/runatlantis/atlantis/server/neptune/workflows/activities/terraform" - "html/template" "github.com/runatlantis/atlantis/server/neptune/workflows/internal/terraform/state" ) diff --git a/server/neptune/workflows/activities/github/middleware.go b/server/neptune/workflows/activities/github/middleware.go index f27c794da..c0020c459 100644 --- a/server/neptune/workflows/activities/github/middleware.go +++ b/server/neptune/workflows/activities/github/middleware.go @@ -1,11 +1,12 @@ package github import ( + "net/http" + "strconv" + "github.com/gregjones/httpcache" "github.com/palantir/go-githubapp/githubapp" "github.com/uber-go/tally/v4" - "net/http" - "strconv" ) const ( diff --git a/server/neptune/workflows/activities/temporal/heartbeat.go b/server/neptune/workflows/activities/temporal/heartbeat.go index 7d37481bf..41077dd8f 100644 --- a/server/neptune/workflows/activities/temporal/heartbeat.go +++ b/server/neptune/workflows/activities/temporal/heartbeat.go @@ -2,8 +2,9 @@ package temporal import ( "context" - "go.temporal.io/sdk/activity" "time" + + "go.temporal.io/sdk/activity" ) const HeartbeatTimeout = 5 * time.Second diff --git a/server/neptune/workflows/internal/deploy/revision/queue/deployer_test.go b/server/neptune/workflows/internal/deploy/revision/queue/deployer_test.go index 9989e8dbc..ff036f675 100644 --- a/server/neptune/workflows/internal/deploy/revision/queue/deployer_test.go +++ b/server/neptune/workflows/internal/deploy/revision/queue/deployer_test.go @@ -47,9 +47,10 @@ type testTerraformWorkflowRunner struct { } func (r testTerraformWorkflowRunner) Run(ctx workflow.Context, deploymentInfo terraform.DeploymentInfo, PlanApproval model.PlanApproval, scope metrics.Scope) error { - if r.expectedErrorType == PlanRejectionError { + switch r.expectedErrorType { + case PlanRejectionError: return terraform.NewPlanRejectionError("plan rejected") - } else if r.expectedErrorType == TerraformClientError { + case TerraformClientError: return activities.NewTerraformClientError(errors.New("error")) } return nil diff --git a/server/neptune/workflows/internal/deploy/revision/queue/worker.go b/server/neptune/workflows/internal/deploy/revision/queue/worker.go index f2acd0287..46887c6d0 100644 --- a/server/neptune/workflows/internal/deploy/revision/queue/worker.go +++ b/server/neptune/workflows/internal/deploy/revision/queue/worker.go @@ -10,7 +10,6 @@ import ( metricNames "github.com/runatlantis/atlantis/server/metrics" "github.com/pkg/errors" - internalContext "github.com/runatlantis/atlantis/server/neptune/context" "github.com/runatlantis/atlantis/server/neptune/workflows/activities/deployment" tfModel "github.com/runatlantis/atlantis/server/neptune/workflows/activities/terraform" "github.com/runatlantis/atlantis/server/neptune/workflows/internal/deploy/lock" @@ -285,11 +284,11 @@ func (w *Worker) awaitWork(ctx workflow.Context) workflow.Future { } func setContextKeys(ctx workflow.Context, requestedDeployment terraform.DeploymentInfo) workflow.Context { - ctx = workflow.WithValue(ctx, internalContext.SHAKey, requestedDeployment.Commit.Revision) - ctx = workflow.WithValue(ctx, internalContext.BranchKey, requestedDeployment.Commit.Branch) - ctx = workflow.WithValue(ctx, internalContext.DeploymentIDKey, requestedDeployment.ID) - ctx = workflow.WithValue(ctx, internalContext.PlanMode, string(requestedDeployment.Root.Plan.GetPlanMode())) - ctx = workflow.WithValue(ctx, internalContext.Trigger, string(requestedDeployment.Root.TriggerInfo.Type)) + ctx = workflow.WithValue(ctx, key.SHAKey, requestedDeployment.Commit.Revision) + ctx = workflow.WithValue(ctx, key.BranchKey, requestedDeployment.Commit.Branch) + ctx = workflow.WithValue(ctx, key.DeploymentIDKey, requestedDeployment.ID) + ctx = workflow.WithValue(ctx, key.PlanMode, string(requestedDeployment.Root.Plan.GetPlanMode())) + ctx = workflow.WithValue(ctx, key.Trigger, string(requestedDeployment.Root.TriggerInfo.Type)) return ctx } diff --git a/server/neptune/workflows/internal/deploy/terraform/state.go b/server/neptune/workflows/internal/deploy/terraform/state.go index 8d806199a..659db470e 100644 --- a/server/neptune/workflows/internal/deploy/terraform/state.go +++ b/server/neptune/workflows/internal/deploy/terraform/state.go @@ -73,10 +73,11 @@ func (n *StateReceiver) Receive(ctx workflow.Context, c workflow.ReceiveChannel, var actions []github.CheckRunAction var summary string - if workflowState.Apply.Status == state.WaitingJobStatus { + switch workflowState.Apply.Status { + case state.WaitingJobStatus: runLink := github.BuildRunURLMarkdown(deploymentInfo.Repo.GetFullName(), deploymentInfo.Commit.Revision, deploymentInfo.CheckRunID) summary = fmt.Sprintf("This deploy is queued pending action on run for revision %s.\n%s", runLink, revisionsSummary) - } else if workflowState.Apply.Status == state.RejectedJobStatus || workflowState.Apply.Status == state.InProgressJobStatus { + case state.RejectedJobStatus, state.InProgressJobStatus: // If the current deployment is Rejected or In Progress status, we need to restore the queued check runs to reflect that the queued deployments are not blocked. // If the queue is currently locked we need to provide the unlock action. queueLock := n.Queue.GetLockState() diff --git a/server/neptune/workflows/internal/deploy/workflow.go b/server/neptune/workflows/internal/deploy/workflow.go index 986317743..384e1896d 100644 --- a/server/neptune/workflows/internal/deploy/workflow.go +++ b/server/neptune/workflows/internal/deploy/workflow.go @@ -1,9 +1,10 @@ package deploy import ( - "github.com/runatlantis/atlantis/server/neptune/workflows/internal/notifier" "time" + "github.com/runatlantis/atlantis/server/neptune/workflows/internal/notifier" + "github.com/pkg/errors" key "github.com/runatlantis/atlantis/server/neptune/context" "github.com/runatlantis/atlantis/server/neptune/workflows/activities" diff --git a/server/neptune/workflows/internal/notifier/github.go b/server/neptune/workflows/internal/notifier/github.go index 45a7cd081..5f9a8d99f 100644 --- a/server/neptune/workflows/internal/notifier/github.go +++ b/server/neptune/workflows/internal/notifier/github.go @@ -3,6 +3,7 @@ package notifier import ( "context" "fmt" + "github.com/google/uuid" "github.com/pkg/errors" "github.com/runatlantis/atlantis/server/neptune/workflows/activities" diff --git a/server/neptune/workflows/internal/notifier/github_cache_test.go b/server/neptune/workflows/internal/notifier/github_cache_test.go index a38f8efa6..b09ea7ab2 100644 --- a/server/neptune/workflows/internal/notifier/github_cache_test.go +++ b/server/neptune/workflows/internal/notifier/github_cache_test.go @@ -2,10 +2,11 @@ package notifier_test import ( "context" - "github.com/runatlantis/atlantis/server/neptune/workflows/internal/notifier" "testing" "time" + "github.com/runatlantis/atlantis/server/neptune/workflows/internal/notifier" + "github.com/runatlantis/atlantis/server/neptune/workflows/activities" "github.com/runatlantis/atlantis/server/neptune/workflows/activities/github" "github.com/stretchr/testify/assert" diff --git a/server/neptune/workflows/internal/notifier/github_test.go b/server/neptune/workflows/internal/notifier/github_test.go index e638ad608..a50eb3ae8 100644 --- a/server/neptune/workflows/internal/notifier/github_test.go +++ b/server/neptune/workflows/internal/notifier/github_test.go @@ -1,11 +1,12 @@ package notifier_test import ( - "github.com/runatlantis/atlantis/server/neptune/workflows/internal/notifier" "net/url" "testing" "time" + "github.com/runatlantis/atlantis/server/neptune/workflows/internal/notifier" + "github.com/google/uuid" "github.com/runatlantis/atlantis/server/neptune/workflows/activities/github" "github.com/runatlantis/atlantis/server/neptune/workflows/activities/github/markdown" diff --git a/server/neptune/workflows/internal/pr/revision/policy/dismisser.go b/server/neptune/workflows/internal/pr/revision/policy/dismisser.go index efb7e8d4e..de2866fb9 100644 --- a/server/neptune/workflows/internal/pr/revision/policy/dismisser.go +++ b/server/neptune/workflows/internal/pr/revision/policy/dismisser.go @@ -2,11 +2,12 @@ package policy import ( "context" + "sort" + "github.com/google/go-github/v45/github" "github.com/runatlantis/atlantis/server/neptune/workflows/activities" "github.com/runatlantis/atlantis/server/neptune/workflows/internal/pr/revision" "go.temporal.io/sdk/workflow" - "sort" ) type dismisserGithubActivities interface { diff --git a/server/neptune/workflows/internal/pr/revision/policy/dismisser_test.go b/server/neptune/workflows/internal/pr/revision/policy/dismisser_test.go index 86385a82f..0ab76c9e7 100644 --- a/server/neptune/workflows/internal/pr/revision/policy/dismisser_test.go +++ b/server/neptune/workflows/internal/pr/revision/policy/dismisser_test.go @@ -2,6 +2,9 @@ package policy_test import ( "context" + "testing" + "time" + "github.com/google/go-github/v45/github" "github.com/runatlantis/atlantis/server/neptune/workflows/activities" gh "github.com/runatlantis/atlantis/server/neptune/workflows/activities/github" @@ -10,8 +13,6 @@ import ( "github.com/stretchr/testify/assert" "go.temporal.io/sdk/testsuite" "go.temporal.io/sdk/workflow" - "testing" - "time" ) type dismissRequest struct { diff --git a/server/neptune/workflows/internal/pr/revision/policy/filter_test.go b/server/neptune/workflows/internal/pr/revision/policy/filter_test.go index 67073c796..2a4b5ddde 100644 --- a/server/neptune/workflows/internal/pr/revision/policy/filter_test.go +++ b/server/neptune/workflows/internal/pr/revision/policy/filter_test.go @@ -1,11 +1,12 @@ package policy_test import ( + "testing" + "github.com/google/go-github/v45/github" "github.com/runatlantis/atlantis/server/neptune/workflows/activities" "github.com/runatlantis/atlantis/server/neptune/workflows/internal/pr/revision/policy" "github.com/stretchr/testify/assert" - "testing" ) func TestFilter_FilterOutTeamA(t *testing.T) { diff --git a/server/neptune/workflows/internal/pr/revision/policy/handler.go b/server/neptune/workflows/internal/pr/revision/policy/handler.go index 125e94aa9..153d0ae19 100644 --- a/server/neptune/workflows/internal/pr/revision/policy/handler.go +++ b/server/neptune/workflows/internal/pr/revision/policy/handler.go @@ -98,10 +98,7 @@ func (f *FailedPolicyHandler) Handle(ctx workflow.Context, revision revision.Rev // perform initial check immediately (subsequent polls can occur at larger intervals) cancelTimer, _ := s.AddTimeout(ctx, time.Millisecond, onTimeout) - for { - if len(failingTerraformWorkflows) == 0 { - break - } + for len(failingTerraformWorkflows) != 0 { s.Select(ctx) switch action { case onShutdown: diff --git a/server/neptune/workflows/internal/pr/revision/policy/handler_test.go b/server/neptune/workflows/internal/pr/revision/policy/handler_test.go index fcdbf1615..d1e66f035 100644 --- a/server/neptune/workflows/internal/pr/revision/policy/handler_test.go +++ b/server/neptune/workflows/internal/pr/revision/policy/handler_test.go @@ -2,6 +2,9 @@ package policy_test import ( "context" + "testing" + "time" + "github.com/google/go-github/v45/github" "github.com/runatlantis/atlantis/server/neptune/workflows/activities" gh "github.com/runatlantis/atlantis/server/neptune/workflows/activities/github" @@ -13,8 +16,6 @@ import ( "github.com/stretchr/testify/assert" "go.temporal.io/sdk/testsuite" "go.temporal.io/sdk/workflow" - "testing" - "time" ) type request struct { diff --git a/server/neptune/workflows/internal/pr/revision/processor_test.go b/server/neptune/workflows/internal/pr/revision/processor_test.go index f7d248cd4..511e2ef50 100644 --- a/server/neptune/workflows/internal/pr/revision/processor_test.go +++ b/server/neptune/workflows/internal/pr/revision/processor_test.go @@ -1,6 +1,9 @@ package revision_test import ( + "testing" + "time" + "github.com/runatlantis/atlantis/server/neptune/workflows/activities" "github.com/runatlantis/atlantis/server/neptune/workflows/activities/github" terraformActivities "github.com/runatlantis/atlantis/server/neptune/workflows/activities/terraform" @@ -11,8 +14,6 @@ import ( "github.com/stretchr/testify/assert" "go.temporal.io/sdk/testsuite" "go.temporal.io/sdk/workflow" - "testing" - "time" ) const ( diff --git a/server/neptune/workflows/internal/pr/revision/state.go b/server/neptune/workflows/internal/pr/revision/state.go index 633d7f15a..cdaa87d02 100644 --- a/server/neptune/workflows/internal/pr/revision/state.go +++ b/server/neptune/workflows/internal/pr/revision/state.go @@ -2,6 +2,7 @@ package revision import ( "fmt" + "github.com/pkg/errors" "github.com/runatlantis/atlantis/server/metrics" "github.com/runatlantis/atlantis/server/neptune/workflows/internal/notifier" diff --git a/server/neptune/workflows/internal/pr/revision/state_test.go b/server/neptune/workflows/internal/pr/revision/state_test.go index e4ffad9a1..1cf6cc037 100644 --- a/server/neptune/workflows/internal/pr/revision/state_test.go +++ b/server/neptune/workflows/internal/pr/revision/state_test.go @@ -1,12 +1,13 @@ package revision_test import ( - "github.com/runatlantis/atlantis/server/neptune/workflows/internal/notifier" - "github.com/runatlantis/atlantis/server/neptune/workflows/internal/pr/revision" "net/url" "testing" "time" + "github.com/runatlantis/atlantis/server/neptune/workflows/internal/notifier" + "github.com/runatlantis/atlantis/server/neptune/workflows/internal/pr/revision" + "github.com/google/uuid" "github.com/runatlantis/atlantis/server/neptune/workflows/activities/github" "github.com/runatlantis/atlantis/server/neptune/workflows/activities/terraform" diff --git a/server/neptune/workflows/internal/pr/runner.go b/server/neptune/workflows/internal/pr/runner.go index 8de8e9d4c..d6db0cd90 100644 --- a/server/neptune/workflows/internal/pr/runner.go +++ b/server/neptune/workflows/internal/pr/runner.go @@ -2,9 +2,10 @@ package pr import ( "context" + "time" + tfModel "github.com/runatlantis/atlantis/server/neptune/workflows/activities/terraform" "github.com/runatlantis/atlantis/server/neptune/workflows/internal/notifier" - "time" metricNames "github.com/runatlantis/atlantis/server/metrics" internalContext "github.com/runatlantis/atlantis/server/neptune/context" diff --git a/server/neptune/workflows/internal/pr/runner_test.go b/server/neptune/workflows/internal/pr/runner_test.go index 050ab318e..84035c52c 100644 --- a/server/neptune/workflows/internal/pr/runner_test.go +++ b/server/neptune/workflows/internal/pr/runner_test.go @@ -2,6 +2,9 @@ package pr import ( "context" + "testing" + "time" + "github.com/runatlantis/atlantis/server/neptune/workflows/activities" "github.com/runatlantis/atlantis/server/neptune/workflows/internal/metrics" "github.com/runatlantis/atlantis/server/neptune/workflows/internal/pr/revision" @@ -9,8 +12,6 @@ import ( "github.com/stretchr/testify/mock" "go.temporal.io/sdk/testsuite" "go.temporal.io/sdk/workflow" - "testing" - "time" ) type request struct { diff --git a/server/neptune/workflows/internal/pr/shutdown.go b/server/neptune/workflows/internal/pr/shutdown.go index d94121142..de22742ab 100644 --- a/server/neptune/workflows/internal/pr/shutdown.go +++ b/server/neptune/workflows/internal/pr/shutdown.go @@ -2,6 +2,7 @@ package pr import ( "context" + "github.com/runatlantis/atlantis/server/neptune/workflows/activities" "github.com/runatlantis/atlantis/server/neptune/workflows/internal/pr/revision" "go.temporal.io/sdk/workflow" diff --git a/server/neptune/workflows/internal/pr/shutdown_test.go b/server/neptune/workflows/internal/pr/shutdown_test.go index be39fb7a8..d9f2e2126 100644 --- a/server/neptune/workflows/internal/pr/shutdown_test.go +++ b/server/neptune/workflows/internal/pr/shutdown_test.go @@ -2,6 +2,9 @@ package pr_test import ( "context" + "testing" + "time" + "github.com/runatlantis/atlantis/server/neptune/workflows/activities" "github.com/runatlantis/atlantis/server/neptune/workflows/activities/github" "github.com/runatlantis/atlantis/server/neptune/workflows/internal/pr" @@ -9,8 +12,6 @@ import ( "github.com/stretchr/testify/assert" "go.temporal.io/sdk/testsuite" "go.temporal.io/sdk/workflow" - "testing" - "time" ) type request struct { diff --git a/server/neptune/workflows/internal/pr/workflow.go b/server/neptune/workflows/internal/pr/workflow.go index 06e7c4712..8054874fd 100644 --- a/server/neptune/workflows/internal/pr/workflow.go +++ b/server/neptune/workflows/internal/pr/workflow.go @@ -1,12 +1,13 @@ package pr import ( + "strconv" + "time" + "github.com/runatlantis/atlantis/server/neptune/workflows/activities" workflowMetrics "github.com/runatlantis/atlantis/server/neptune/workflows/internal/metrics" "github.com/runatlantis/atlantis/server/neptune/workflows/internal/pr/revision" "go.temporal.io/sdk/workflow" - "strconv" - "time" ) const TaskQueue = "pr" diff --git a/server/neptune/workflows/internal/temporal/selector.go b/server/neptune/workflows/internal/temporal/selector.go index fb7eda644..174cabdd4 100644 --- a/server/neptune/workflows/internal/temporal/selector.go +++ b/server/neptune/workflows/internal/temporal/selector.go @@ -1,8 +1,9 @@ package temporal import ( - "go.temporal.io/sdk/workflow" "time" + + "go.temporal.io/sdk/workflow" ) // SelectorWithTimeout makes it a bit easier to add Timeout futures diff --git a/server/neptune/workflows/internal/terraform/job/runner_test.go b/server/neptune/workflows/internal/terraform/job/runner_test.go index 7c4e4f378..36239d8fb 100644 --- a/server/neptune/workflows/internal/terraform/job/runner_test.go +++ b/server/neptune/workflows/internal/terraform/job/runner_test.go @@ -2,10 +2,11 @@ package job_test import ( "context" - "github.com/runatlantis/atlantis/server/neptune/workflows/activities/command" "testing" "time" + "github.com/runatlantis/atlantis/server/neptune/workflows/activities/command" + "github.com/runatlantis/atlantis/server/neptune/workflows/activities" "github.com/runatlantis/atlantis/server/neptune/workflows/activities/execute" "github.com/runatlantis/atlantis/server/neptune/workflows/activities/github" diff --git a/server/neptune/workflows/internal/terraform/state/store.go b/server/neptune/workflows/internal/terraform/state/store.go index 049d45fda..45488d5b5 100644 --- a/server/neptune/workflows/internal/terraform/state/store.go +++ b/server/neptune/workflows/internal/terraform/state/store.go @@ -2,10 +2,11 @@ package state import ( "fmt" - "github.com/runatlantis/atlantis/server/neptune/workflows/activities/conftest" "net/url" "time" + "github.com/runatlantis/atlantis/server/neptune/workflows/activities/conftest" + "github.com/gorilla/mux" "github.com/pkg/errors" "github.com/runatlantis/atlantis/server/neptune/workflows/activities/terraform" diff --git a/server/neptune/workflows/internal/terraform/state/workflow.go b/server/neptune/workflows/internal/terraform/state/workflow.go index 43056f898..96a1cc9ab 100644 --- a/server/neptune/workflows/internal/terraform/state/workflow.go +++ b/server/neptune/workflows/internal/terraform/state/workflow.go @@ -1,10 +1,11 @@ package state import ( - "github.com/runatlantis/atlantis/server/neptune/workflows/activities/conftest" "net/url" "time" + "github.com/runatlantis/atlantis/server/neptune/workflows/activities/conftest" + "github.com/runatlantis/atlantis/server/neptune/workflows/activities/github" "github.com/runatlantis/atlantis/server/neptune/workflows/activities/terraform" "github.com/runatlantis/atlantis/server/neptune/workflows/plugins" diff --git a/server/recovery/recovery.go b/server/recovery/recovery.go index 950ab7c88..a5c289090 100644 --- a/server/recovery/recovery.go +++ b/server/recovery/recovery.go @@ -92,6 +92,6 @@ func function(pc uintptr) []byte { if period := bytes.Index(name, dot); period >= 0 { name = name[period+1:] } - name = bytes.Replace(name, centerDot, dot, -1) + name = bytes.ReplaceAll(name, centerDot, dot) return name } diff --git a/server/vcs/markdown/markdown_renderer_test.go b/server/vcs/markdown/markdown_renderer_test.go index 0a17a27f9..a8da51711 100644 --- a/server/vcs/markdown/markdown_renderer_test.go +++ b/server/vcs/markdown/markdown_renderer_test.go @@ -187,7 +187,7 @@ $$$ res := command.Result{ ProjectResults: c.ProjectResults, } - expWithBackticks := strings.Replace(c.Expected, "$", "`", -1) + expWithBackticks := strings.ReplaceAll(c.Expected, "$", "`") t.Run(fmt.Sprintf("%s_%t", c.Description, false), func(t *testing.T) { s := r.Render(res, c.Command, testRepo) Equals(t, expWithBackticks, s) @@ -887,7 +887,7 @@ $$$ } t.Run(c.Description, func(t *testing.T) { s := r.Render(res, c.Command, testRepo) - expWithBackticks := strings.Replace(c.Expected, "$", "`", -1) + expWithBackticks := strings.ReplaceAll(c.Expected, "$", "`") Equals(t, expWithBackticks, s) }) }) @@ -1038,7 +1038,7 @@ $$$ } t.Run(c.Description, func(t *testing.T) { s := r.Render(res, c.Command, testRepo) - expWithBackticks := strings.Replace(c.Expected, "$", "`", -1) + expWithBackticks := strings.ReplaceAll(c.Expected, "$", "`") Equals(t, expWithBackticks, s) }) }) @@ -1182,7 +1182,7 @@ $$$ } t.Run(c.Description, func(t *testing.T) { s := r.Render(res, c.Command, testRepo) - expWithBackticks := strings.Replace(c.Expected, "$", "`", -1) + expWithBackticks := strings.ReplaceAll(c.Expected, "$", "`") Equals(t, expWithBackticks, s) }) }) @@ -1271,7 +1271,7 @@ $$$ ` } - expWithBackticks := strings.Replace(exp, "$", "`", -1) + expWithBackticks := strings.ReplaceAll(exp, "$", "`") Equals(t, expWithBackticks, rendered) }) } @@ -1402,7 +1402,7 @@ $$$ } } - expWithBackticks := strings.Replace(exp, "$", "`", -1) + expWithBackticks := strings.ReplaceAll(exp, "$", "`") Equals(t, expWithBackticks, rendered) }) } @@ -1451,7 +1451,7 @@ $$$ --- ` - expWithBackticks := strings.Replace(exp, "$", "`", -1) + expWithBackticks := strings.ReplaceAll(exp, "$", "`") Equals(t, expWithBackticks, rendered) } @@ -1526,7 +1526,7 @@ Plan: 1 to add, 0 to change, 0 to destroy. * :put_litter_in_its_place: To delete all plans and locks for the PR, comment: * $atlantis unlock$ ` - expWithBackticks := strings.Replace(exp, "$", "`", -1) + expWithBackticks := strings.ReplaceAll(exp, "$", "`") Equals(t, expWithBackticks, rendered) } @@ -1804,7 +1804,7 @@ Plan: 1 to add, 1 to change, 1 to destroy. Type: c.VCSHost, }, }) - expWithBackticks := strings.Replace(c.Expected, "$", "`", -1) + expWithBackticks := strings.ReplaceAll(c.Expected, "$", "`") Equals(t, expWithBackticks, s) }) }) @@ -1886,7 +1886,7 @@ $$$`, r := Renderer{ TemplateResolver: templateResolver, } - expWithBackticks := strings.Replace(c.Expected, "$", "`", -1) + expWithBackticks := strings.ReplaceAll(c.Expected, "$", "`") t.Run(fmt.Sprintf("%s_%t", c.Description, false), func(t *testing.T) { s := r.RenderProject(c.ProjectResult, c.Command, testRepo) fmt.Println(s) @@ -2050,7 +2050,7 @@ $$$ t.Run(c.Description, func(t *testing.T) { s := r.RenderProject(c.ProjectResult, c.Command, testRepo) fmt.Print(s) - expWithBackticks := strings.Replace(c.Expected, "$", "`", -1) + expWithBackticks := strings.ReplaceAll(c.Expected, "$", "`") Equals(t, expWithBackticks, s) }) } diff --git a/server/vcs/markdown/template_resolver.go b/server/vcs/markdown/template_resolver.go index e790fe4d7..549f4e8d8 100644 --- a/server/vcs/markdown/template_resolver.go +++ b/server/vcs/markdown/template_resolver.go @@ -83,12 +83,12 @@ func (t *TemplateResolver) Resolve(common commonData, baseRepo models.Repo, numP } var tmpl *template.Template - switch { - case common.Command == planCommandTitle, common.Command == policyCheckCommandTitle: + switch common.Command { + case planCommandTitle, policyCheckCommandTitle: tmpl = t.getPlanTmpl(common, templateOverrides, numPrjResults, numPlanSuccesses, numPolicyCheckSuccesses) - case common.Command == applyCommandTitle: + case applyCommandTitle: tmpl = t.getApplyTmpl(templateOverrides, numPrjResults) - case common.Command == versionCommandTitle: + case versionCommandTitle: tmpl = t.getVersionTmpl(templateOverrides, common, numPrjResults, numVersionSuccesses) } diff --git a/server/vcs/provider/github/git_cred_writer_test.go b/server/vcs/provider/github/git_cred_writer_test.go index c7f6bdc52..edc1ef57e 100644 --- a/server/vcs/provider/github/git_cred_writer_test.go +++ b/server/vcs/provider/github/git_cred_writer_test.go @@ -2,12 +2,13 @@ package github_test import ( "fmt" - "github.com/runatlantis/atlantis/server/vcs/provider/github" "os" "os/exec" "path/filepath" "testing" + "github.com/runatlantis/atlantis/server/vcs/provider/github" + "github.com/runatlantis/atlantis/server/logging" . "github.com/runatlantis/atlantis/testing" ) diff --git a/server/vcs/provider/github/list_iterator.go b/server/vcs/provider/github/list_iterator.go index f5db50700..94c564c7d 100644 --- a/server/vcs/provider/github/list_iterator.go +++ b/server/vcs/provider/github/list_iterator.go @@ -3,9 +3,10 @@ package github import ( "context" "fmt" + "net/http" + gh "github.com/google/go-github/v45/github" "github.com/pkg/errors" - "net/http" ) func Iterate[T interface{}]( diff --git a/server/vcs/provider/github/list_iterator_test.go b/server/vcs/provider/github/list_iterator_test.go index 57afa2c65..003b59874 100644 --- a/server/vcs/provider/github/list_iterator_test.go +++ b/server/vcs/provider/github/list_iterator_test.go @@ -2,11 +2,12 @@ package github_test import ( "context" + "net/http" + "testing" + gh "github.com/google/go-github/v45/github" "github.com/runatlantis/atlantis/server/vcs/provider/github" "github.com/stretchr/testify/assert" - "net/http" - "testing" ) const ( diff --git a/server/vcs/provider/github/pr_fetcher.go b/server/vcs/provider/github/pr_fetcher.go index 8f5cf907a..3782411c0 100644 --- a/server/vcs/provider/github/pr_fetcher.go +++ b/server/vcs/provider/github/pr_fetcher.go @@ -3,10 +3,11 @@ package github import ( "context" "fmt" + "net/http" + gh "github.com/google/go-github/v45/github" "github.com/palantir/go-githubapp/githubapp" "github.com/pkg/errors" - "net/http" ) type PRFetcher struct { diff --git a/server/vcs/provider/github/request/handler_test.go b/server/vcs/provider/github/request/handler_test.go index bab9f3e81..50e488e5f 100644 --- a/server/vcs/provider/github/request/handler_test.go +++ b/server/vcs/provider/github/request/handler_test.go @@ -9,7 +9,6 @@ import ( "github.com/google/go-github/v45/github" "github.com/runatlantis/atlantis/server/legacy/controllers/events/errors" - buffered "github.com/runatlantis/atlantis/server/legacy/http" httputils "github.com/runatlantis/atlantis/server/legacy/http" "github.com/runatlantis/atlantis/server/logging" "github.com/runatlantis/atlantis/server/metrics" @@ -125,7 +124,7 @@ type assertingPullRequestReviewHandler struct { expectedInput event.PullRequestReview } -func (h assertingPullRequestReviewHandler) Handle(_ context.Context, input event.PullRequestReview, _ *buffered.BufferedRequest) error { +func (h assertingPullRequestReviewHandler) Handle(_ context.Context, input event.PullRequestReview, _ *httputils.BufferedRequest) error { assert.Equal(h.t, h.expectedInput, input) return nil } diff --git a/server/vcs/provider/github/team_fetcher.go b/server/vcs/provider/github/team_fetcher.go index 05a471523..0c5e5a339 100644 --- a/server/vcs/provider/github/team_fetcher.go +++ b/server/vcs/provider/github/team_fetcher.go @@ -2,6 +2,7 @@ package github import ( "context" + gh "github.com/google/go-github/v45/github" "github.com/palantir/go-githubapp/githubapp" "github.com/pkg/errors"