From fb69965fd72bf65bdde21bf33d13f15dad046e44 Mon Sep 17 00:00:00 2001 From: Simon Heather <32168619+X-Guardian@users.noreply.github.com> Date: Wed, 27 Mar 2024 16:05:52 +0000 Subject: [PATCH] chore: Rename templates package to web_templates (#4383) --- server/controllers/github_app_controller.go | 6 ++-- server/controllers/jobs_controller.go | 8 ++--- server/controllers/locks_controller.go | 6 ++-- server/controllers/locks_controller_test.go | 6 ++-- .../mocks/mock_template_writer.go | 0 .../web_templates.go | 2 +- .../web_templates_test.go | 2 +- server/server.go | 32 +++++++++---------- server/server_test.go | 10 +++--- 9 files changed, 36 insertions(+), 36 deletions(-) rename server/controllers/{templates => web_templates}/mocks/mock_template_writer.go (100%) rename server/controllers/{templates => web_templates}/web_templates.go (99%) rename server/controllers/{templates => web_templates}/web_templates_test.go (99%) diff --git a/server/controllers/github_app_controller.go b/server/controllers/github_app_controller.go index 5ac08d00fa..823c82928e 100644 --- a/server/controllers/github_app_controller.go +++ b/server/controllers/github_app_controller.go @@ -6,7 +6,7 @@ import ( "net/http" "net/url" - "github.com/runatlantis/atlantis/server/controllers/templates" + "github.com/runatlantis/atlantis/server/controllers/web_templates" "github.com/runatlantis/atlantis/server/events/vcs" "github.com/runatlantis/atlantis/server/logging" ) @@ -70,7 +70,7 @@ func (g *GithubAppController) ExchangeCode(w http.ResponseWriter, r *http.Reques g.Logger.Debug("Found credentials for GitHub app %q with id %d", app.Name, app.ID) - err = templates.GithubAppSetupTemplate.Execute(w, templates.GithubSetupData{ + err = web_templates.GithubAppSetupTemplate.Execute(w, web_templates.GithubSetupData{ Target: "", Manifest: "", ID: app.ID, @@ -142,7 +142,7 @@ func (g *GithubAppController) New(w http.ResponseWriter, _ *http.Request) { return } - err = templates.GithubAppSetupTemplate.Execute(w, templates.GithubSetupData{ + err = web_templates.GithubAppSetupTemplate.Execute(w, web_templates.GithubSetupData{ Target: url.String(), Manifest: string(jsonManifest), }) diff --git a/server/controllers/jobs_controller.go b/server/controllers/jobs_controller.go index 0363977944..bb38a05e44 100644 --- a/server/controllers/jobs_controller.go +++ b/server/controllers/jobs_controller.go @@ -6,7 +6,7 @@ import ( "net/url" "github.com/gorilla/mux" - "github.com/runatlantis/atlantis/server/controllers/templates" + "github.com/runatlantis/atlantis/server/controllers/web_templates" "github.com/runatlantis/atlantis/server/controllers/websocket" "github.com/runatlantis/atlantis/server/core/locking" "github.com/runatlantis/atlantis/server/logging" @@ -29,8 +29,8 @@ type JobsController struct { AtlantisVersion string AtlantisURL *url.URL Logger logging.SimpleLogging - ProjectJobsTemplate templates.TemplateWriter - ProjectJobsErrorTemplate templates.TemplateWriter + ProjectJobsTemplate web_templates.TemplateWriter + ProjectJobsErrorTemplate web_templates.TemplateWriter Backend locking.Backend WsMux *websocket.Multiplexor KeyGenerator JobIDKeyGenerator @@ -45,7 +45,7 @@ func (j *JobsController) getProjectJobs(w http.ResponseWriter, r *http.Request) return err } - viewData := templates.ProjectJobData{ + viewData := web_templates.ProjectJobData{ AtlantisVersion: j.AtlantisVersion, ProjectPath: jobID, CleanedBasePath: j.AtlantisURL.Path, diff --git a/server/controllers/locks_controller.go b/server/controllers/locks_controller.go index bab7fad27a..c16d828e69 100644 --- a/server/controllers/locks_controller.go +++ b/server/controllers/locks_controller.go @@ -5,7 +5,7 @@ import ( "net/http" "net/url" - "github.com/runatlantis/atlantis/server/controllers/templates" + "github.com/runatlantis/atlantis/server/controllers/web_templates" "github.com/gorilla/mux" "github.com/runatlantis/atlantis/server/core/locking" @@ -23,7 +23,7 @@ type LocksController struct { Logger logging.SimpleLogging ApplyLocker locking.ApplyLocker VCSClient vcs.Client - LockDetailTemplate templates.TemplateWriter + LockDetailTemplate web_templates.TemplateWriter WorkingDir events.WorkingDir WorkingDirLocker events.WorkingDirLocker Backend locking.Backend @@ -78,7 +78,7 @@ func (l *LocksController) GetLock(w http.ResponseWriter, r *http.Request) { } owner, repo := models.SplitRepoFullName(lock.Project.RepoFullName) - viewData := templates.LockDetailData{ + viewData := web_templates.LockDetailData{ LockKeyEncoded: id, LockKey: idUnencoded, PullRequestLink: lock.Pull.URL, diff --git a/server/controllers/locks_controller_test.go b/server/controllers/locks_controller_test.go index 0f80e7c1f7..f06a7faeaa 100644 --- a/server/controllers/locks_controller_test.go +++ b/server/controllers/locks_controller_test.go @@ -11,8 +11,8 @@ import ( "time" "github.com/runatlantis/atlantis/server/controllers" - "github.com/runatlantis/atlantis/server/controllers/templates" - tMocks "github.com/runatlantis/atlantis/server/controllers/templates/mocks" + "github.com/runatlantis/atlantis/server/controllers/web_templates" + tMocks "github.com/runatlantis/atlantis/server/controllers/web_templates/mocks" "github.com/runatlantis/atlantis/server/core/db" "github.com/runatlantis/atlantis/server/core/locking" @@ -185,7 +185,7 @@ func TestGetLock_Success(t *testing.T) { req = mux.SetURLVars(req, map[string]string{"id": "id"}) w := httptest.NewRecorder() lc.GetLock(w, req) - tmpl.VerifyWasCalledOnce().Execute(w, templates.LockDetailData{ + tmpl.VerifyWasCalledOnce().Execute(w, web_templates.LockDetailData{ LockKeyEncoded: "id", LockKey: "id", RepoOwner: "owner", diff --git a/server/controllers/templates/mocks/mock_template_writer.go b/server/controllers/web_templates/mocks/mock_template_writer.go similarity index 100% rename from server/controllers/templates/mocks/mock_template_writer.go rename to server/controllers/web_templates/mocks/mock_template_writer.go diff --git a/server/controllers/templates/web_templates.go b/server/controllers/web_templates/web_templates.go similarity index 99% rename from server/controllers/templates/web_templates.go rename to server/controllers/web_templates/web_templates.go index 01bbc2faac..c3be8e4daa 100644 --- a/server/controllers/templates/web_templates.go +++ b/server/controllers/web_templates/web_templates.go @@ -11,7 +11,7 @@ // limitations under the License. // Modified hereafter by contributors to runatlantis/atlantis. -package templates +package web_templates import ( "html/template" diff --git a/server/controllers/templates/web_templates_test.go b/server/controllers/web_templates/web_templates_test.go similarity index 99% rename from server/controllers/templates/web_templates_test.go rename to server/controllers/web_templates/web_templates_test.go index 5b88c3e1d9..22fd4e90fe 100644 --- a/server/controllers/templates/web_templates_test.go +++ b/server/controllers/web_templates/web_templates_test.go @@ -1,4 +1,4 @@ -package templates +package web_templates import ( "io" diff --git a/server/server.go b/server/server.go index 14fea9c613..9e53a55698 100644 --- a/server/server.go +++ b/server/server.go @@ -50,7 +50,7 @@ import ( "github.com/pkg/errors" "github.com/runatlantis/atlantis/server/controllers" events_controllers "github.com/runatlantis/atlantis/server/controllers/events" - "github.com/runatlantis/atlantis/server/controllers/templates" + "github.com/runatlantis/atlantis/server/controllers/web_templates" "github.com/runatlantis/atlantis/server/controllers/websocket" "github.com/runatlantis/atlantis/server/core/locking" "github.com/runatlantis/atlantis/server/core/runtime" @@ -107,10 +107,10 @@ type Server struct { StatusController *controllers.StatusController JobsController *controllers.JobsController APIController *controllers.APIController - IndexTemplate templates.TemplateWriter - LockDetailTemplate templates.TemplateWriter - ProjectJobsTemplate templates.TemplateWriter - ProjectJobsErrorTemplate templates.TemplateWriter + IndexTemplate web_templates.TemplateWriter + LockDetailTemplate web_templates.TemplateWriter + ProjectJobsTemplate web_templates.TemplateWriter + ProjectJobsErrorTemplate web_templates.TemplateWriter SSLCertFile string SSLKeyFile string CertLastRefreshTime time.Time @@ -853,7 +853,7 @@ func NewServer(userConfig UserConfig, config Config) (*Server, error) { ApplyLocker: applyLockingClient, Logger: logger, VCSClient: vcsClient, - LockDetailTemplate: templates.LockTemplate, + LockDetailTemplate: web_templates.LockTemplate, WorkingDir: workingDir, WorkingDirLocker: workingDirLocker, Backend: backend, @@ -871,8 +871,8 @@ func NewServer(userConfig UserConfig, config Config) (*Server, error) { AtlantisVersion: config.AtlantisVersion, AtlantisURL: parsedURL, Logger: logger, - ProjectJobsTemplate: templates.ProjectJobsTemplate, - ProjectJobsErrorTemplate: templates.ProjectJobsErrorTemplate, + ProjectJobsTemplate: web_templates.ProjectJobsTemplate, + ProjectJobsErrorTemplate: web_templates.ProjectJobsErrorTemplate, Backend: backend, WsMux: wsMux, KeyGenerator: controllers.JobIDKeyGenerator{}, @@ -943,10 +943,10 @@ func NewServer(userConfig UserConfig, config Config) (*Server, error) { JobsController: jobsController, StatusController: statusController, APIController: apiController, - IndexTemplate: templates.IndexTemplate, - LockDetailTemplate: templates.LockTemplate, - ProjectJobsTemplate: templates.ProjectJobsTemplate, - ProjectJobsErrorTemplate: templates.ProjectJobsErrorTemplate, + IndexTemplate: web_templates.IndexTemplate, + LockDetailTemplate: web_templates.LockTemplate, + ProjectJobsTemplate: web_templates.ProjectJobsTemplate, + ProjectJobsErrorTemplate: web_templates.ProjectJobsErrorTemplate, SSLKeyFile: userConfig.SSLKeyFile, SSLCertFile: userConfig.SSLCertFile, DisableGlobalApplyLock: userConfig.DisableGlobalApplyLock, @@ -1071,10 +1071,10 @@ func (s *Server) Index(w http.ResponseWriter, _ *http.Request) { return } - var lockResults []templates.LockIndexData + var lockResults []web_templates.LockIndexData for id, v := range locks { lockURL, _ := s.Router.Get(LockViewRouteName).URL("id", url.QueryEscape(id)) - lockResults = append(lockResults, templates.LockIndexData{ + lockResults = append(lockResults, web_templates.LockIndexData{ // NOTE: must use .String() instead of .Path because we need the // query params as part of the lock URL. LockPath: lockURL.String(), @@ -1096,7 +1096,7 @@ func (s *Server) Index(w http.ResponseWriter, _ *http.Request) { return } - applyLockData := templates.ApplyLockData{ + applyLockData := web_templates.ApplyLockData{ Time: applyCmdLock.Time, Locked: applyCmdLock.Locked, GlobalApplyLockEnabled: applyCmdLock.GlobalApplyLockEnabled, @@ -1105,7 +1105,7 @@ func (s *Server) Index(w http.ResponseWriter, _ *http.Request) { //Sort by date - newest to oldest. sort.SliceStable(lockResults, func(i, j int) bool { return lockResults[i].Time.After(lockResults[j].Time) }) - err = s.IndexTemplate.Execute(w, templates.IndexData{ + err = s.IndexTemplate.Execute(w, web_templates.IndexData{ Locks: lockResults, PullToJobMapping: preparePullToJobMappings(s), ApplyLock: applyLockData, diff --git a/server/server_test.go b/server/server_test.go index e9151443e2..e96c6aa6b4 100644 --- a/server/server_test.go +++ b/server/server_test.go @@ -27,8 +27,8 @@ import ( "github.com/gorilla/mux" . "github.com/petergtz/pegomock/v4" "github.com/runatlantis/atlantis/server" - "github.com/runatlantis/atlantis/server/controllers/templates" - tMocks "github.com/runatlantis/atlantis/server/controllers/templates/mocks" + "github.com/runatlantis/atlantis/server/controllers/web_templates" + tMocks "github.com/runatlantis/atlantis/server/controllers/web_templates/mocks" "github.com/runatlantis/atlantis/server/core/locking/mocks" "github.com/runatlantis/atlantis/server/events/models" "github.com/runatlantis/atlantis/server/jobs" @@ -113,13 +113,13 @@ func TestIndex_Success(t *testing.T) { req, _ := http.NewRequest("GET", "", bytes.NewBuffer(nil)) w := httptest.NewRecorder() s.Index(w, req) - it.VerifyWasCalledOnce().Execute(w, templates.IndexData{ - ApplyLock: templates.ApplyLockData{ + it.VerifyWasCalledOnce().Execute(w, web_templates.IndexData{ + ApplyLock: web_templates.ApplyLockData{ Locked: false, Time: time.Time{}, TimeFormatted: "01-01-0001 00:00:00", }, - Locks: []templates.LockIndexData{ + Locks: []web_templates.LockIndexData{ { LockPath: "/lock?id=lkysow%252Fatlantis-example%252F.%252Fdefault", RepoFullName: "lkysow/atlantis-example",