diff --git a/server/server.go b/server/server.go index 278e14ccba..9e1e7a36ec 100644 --- a/server/server.go +++ b/server/server.go @@ -36,6 +36,7 @@ const LockRouteName = "lock-detail" // Server runs the Atlantis web server. type Server struct { + Version string Router *mux.Router Port int CommandHandler *events.CommandHandler @@ -73,6 +74,7 @@ type Config struct { SlackToken string `mapstructure:"slack-token"` SSLCertFile string `mapstructure:"ssl-cert-file"` SSLKeyFile string `mapstructure:"ssl-key-file"` + Version string `mapstructure:"version"` Webhooks []WebhookConfig `mapstructure:"webhooks"` } @@ -246,6 +248,7 @@ func NewServer(config Config, flagNames FlagNames) (*Server, error) { } router := mux.NewRouter() return &Server{ + Version: config.Version, Router: router, Port: config.Port, CommandHandler: commandHandler, @@ -324,17 +327,20 @@ func (s *Server) Index(w http.ResponseWriter, _ *http.Request) { return } - var results []LockIndexData + var lockResults []LockIndexData for id, v := range locks { lockURL, _ := s.Router.Get(LockRouteName).URL("id", url.QueryEscape(id)) - results = append(results, LockIndexData{ + lockResults = append(lockResults, LockIndexData{ LockURL: lockURL.String(), RepoFullName: v.Project.RepoFullName, PullNum: v.Pull.Num, Time: v.Time, }) } - s.IndexTemplate.Execute(w, results) // nolint: errcheck + s.IndexTemplate.Execute(w, IndexData { + Locks: lockResults, + Version: s.Version, + }) // nolint: errcheck } // GetLockRoute is the GET /locks/{id} route. It renders the lock detail view. diff --git a/server/server_test.go b/server/server_test.go index a7d8e5f7ad..fdfe2c609c 100644 --- a/server/server_test.go +++ b/server/server_test.go @@ -64,23 +64,28 @@ func TestIndex_Success(t *testing.T) { When(l.List()).ThenReturn(locks, nil) it := sMocks.NewMockTemplateWriter() r := mux.NewRouter() + version := "0.3.1" // Need to create a lock route since the server expects this route to exist. r.NewRoute().Path("").Name(server.LockRouteName) s := server.Server{ Locker: l, IndexTemplate: it, Router: r, + Version: version, } eventsReq, _ = http.NewRequest("GET", "", bytes.NewBuffer(nil)) w := httptest.NewRecorder() s.Index(w, eventsReq) - it.VerifyWasCalledOnce().Execute(w, []server.LockIndexData{ - { - LockURL: "", - RepoFullName: "owner/repo", - PullNum: 9, - Time: now, + it.VerifyWasCalledOnce().Execute(w, server.IndexData{ + Locks: []server.LockIndexData{ + { + LockURL: "", + RepoFullName: "owner/repo", + PullNum: 9, + Time: now, + }, }, + Version: version, }) responseContains(t, w, http.StatusOK, "") } diff --git a/server/web_templates.go b/server/web_templates.go index a42a206f88..3596bfffa2 100644 --- a/server/web_templates.go +++ b/server/web_templates.go @@ -24,6 +24,11 @@ type LockIndexData struct { Time time.Time } +type IndexData struct { + Locks []LockIndexData + Version string +} + var indexTemplate = template.Must(template.New("index.html.tmpl").Parse(` @@ -51,7 +56,7 @@ var indexTemplate = template.Must(template.New("index.html.tmpl").Parse(`