Skip to content

Commit

Permalink
Show atlantis version in index page
Browse files Browse the repository at this point in the history
  • Loading branch information
psalaberria002 committed Mar 11, 2018
1 parent 10e1bf0 commit d8f5ff7
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
12 changes: 9 additions & 3 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"`
}

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand Down
17 changes: 11 additions & 6 deletions server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, "")
}
Expand Down
11 changes: 8 additions & 3 deletions server/web_templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(`
<!DOCTYPE html>
<html lang="en">
Expand Down Expand Up @@ -51,7 +56,7 @@ var indexTemplate = template.Must(template.New("index.html.tmpl").Parse(`
<div class="container">
<section class="header">
<a title="atlantis" href="/"><img src="/static/images/atlantis-icon.png"/></a>
<p class="title-heading">atlantis</p>
<p class="title-heading">atlantis {{ .Version }}</p>
<p class="js-discard-success"><strong>Plan discarded and unlocked!</strong></p>
</section>
<nav class="navbar">
Expand All @@ -62,8 +67,8 @@ var indexTemplate = template.Must(template.New("index.html.tmpl").Parse(`
<br>
<section>
<p class="title-heading small"><strong>Locks</strong></p>
{{ if . }}
{{ range . }}
{{ if .Locks }}
{{ range .Locks }}
<a href="{{.LockURL}}">
<div class="twelve columns button content lock-row">
<div class="list-title">{{.RepoFullName}} - <span class="heading-font-size">#{{.PullNum}}</span></div>
Expand Down

0 comments on commit d8f5ff7

Please sign in to comment.