diff options
Diffstat (limited to 'misc/dashboard/app/build')
-rw-r--r-- | misc/dashboard/app/build/build.go | 294 | ||||
-rw-r--r-- | misc/dashboard/app/build/handler.go | 428 | ||||
-rw-r--r-- | misc/dashboard/app/build/key.go | 62 | ||||
-rw-r--r-- | misc/dashboard/app/build/notify.go | 150 | ||||
-rw-r--r-- | misc/dashboard/app/build/notify.txt | 9 | ||||
-rw-r--r-- | misc/dashboard/app/build/test.go | 251 | ||||
-rw-r--r-- | misc/dashboard/app/build/ui.go | 313 | ||||
-rw-r--r-- | misc/dashboard/app/build/ui.html | 178 |
8 files changed, 1685 insertions, 0 deletions
diff --git a/misc/dashboard/app/build/build.go b/misc/dashboard/app/build/build.go new file mode 100644 index 000000000..175812a37 --- /dev/null +++ b/misc/dashboard/app/build/build.go @@ -0,0 +1,294 @@ +// Copyright 2011 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package build + +import ( + "bytes" + "compress/gzip" + "crypto/sha1" + "fmt" + "io" + "io/ioutil" + "os" + "strings" + + "appengine" + "appengine/datastore" +) + +const maxDatastoreStringLen = 500 + +// A Package describes a package that is listed on the dashboard. +type Package struct { + Name string + Path string // (empty for the main Go tree) + NextNum int // Num of the next head Commit +} + +func (p *Package) String() string { + return fmt.Sprintf("%s: %q", p.Path, p.Name) +} + +func (p *Package) Key(c appengine.Context) *datastore.Key { + key := p.Path + if key == "" { + key = "go" + } + return datastore.NewKey(c, "Package", key, 0, nil) +} + +// LastCommit returns the most recent Commit for this Package. +func (p *Package) LastCommit(c appengine.Context) (*Commit, os.Error) { + var commits []*Commit + _, err := datastore.NewQuery("Commit"). + Ancestor(p.Key(c)). + Order("-Time"). + Limit(1). + GetAll(c, &commits) + if err != nil { + return nil, err + } + if len(commits) != 1 { + return nil, datastore.ErrNoSuchEntity + } + return commits[0], nil +} + +// GetPackage fetches a Package by path from the datastore. +func GetPackage(c appengine.Context, path string) (*Package, os.Error) { + p := &Package{Path: path} + err := datastore.Get(c, p.Key(c), p) + if err == datastore.ErrNoSuchEntity { + return nil, fmt.Errorf("package %q not found", path) + } + return p, err +} + +// A Commit describes an individual commit in a package. +// +// Each Commit entity is a descendant of its associated Package entity. +// In other words, all Commits with the same PackagePath belong to the same +// datastore entity group. +type Commit struct { + PackagePath string // (empty for Go commits) + Hash string + ParentHash string + Num int // Internal monotonic counter unique to this package. + + User string + Desc string `datastore:",noindex"` + Time datastore.Time + + // ResultData is the Data string of each build Result for this Commit. + // For non-Go commits, only the Results for the current Go tip, weekly, + // and release Tags are stored here. This is purely de-normalized data. + // The complete data set is stored in Result entities. + ResultData []string `datastore:",noindex"` + + FailNotificationSent bool +} + +func (com *Commit) Key(c appengine.Context) *datastore.Key { + if com.Hash == "" { + panic("tried Key on Commit with empty Hash") + } + p := Package{Path: com.PackagePath} + key := com.PackagePath + "|" + com.Hash + return datastore.NewKey(c, "Commit", key, 0, p.Key(c)) +} + +func (c *Commit) Valid() os.Error { + if !validHash(c.Hash) { + return os.NewError("invalid Hash") + } + if c.ParentHash != "" && !validHash(c.ParentHash) { // empty is OK + return os.NewError("invalid ParentHash") + } + return nil +} + +// AddResult adds the denormalized Reuslt data to the Commit's Result field. +// It must be called from inside a datastore transaction. +func (com *Commit) AddResult(c appengine.Context, r *Result) os.Error { + if err := datastore.Get(c, com.Key(c), com); err != nil { + return fmt.Errorf("getting Commit: %v", err) + } + com.ResultData = append(com.ResultData, r.Data()) + if _, err := datastore.Put(c, com.Key(c), com); err != nil { + return fmt.Errorf("putting Commit: %v", err) + } + return nil +} + +// Result returns the build Result for this Commit for the given builder/goHash. +func (c *Commit) Result(builder, goHash string) *Result { + for _, r := range c.ResultData { + p := strings.SplitN(r, "|", 4) + if len(p) != 4 || p[0] != builder || p[3] != goHash { + continue + } + return partsToHash(c, p) + } + return nil +} + +// Results returns the build Results for this Commit for the given goHash. +func (c *Commit) Results(goHash string) (results []*Result) { + for _, r := range c.ResultData { + p := strings.SplitN(r, "|", 4) + if len(p) != 4 || p[3] != goHash { + continue + } + results = append(results, partsToHash(c, p)) + } + return +} + +// partsToHash converts a Commit and ResultData substrings to a Result. +func partsToHash(c *Commit, p []string) *Result { + return &Result{ + Builder: p[0], + Hash: c.Hash, + PackagePath: c.PackagePath, + GoHash: p[3], + OK: p[1] == "true", + LogHash: p[2], + } +} + +// OK returns the Commit's build state for a specific builder and goHash. +func (c *Commit) OK(builder, goHash string) (ok, present bool) { + r := c.Result(builder, goHash) + if r == nil { + return false, false + } + return r.OK, true +} + +// A Result describes a build result for a Commit on an OS/architecture. +// +// Each Result entity is a descendant of its associated Commit entity. +type Result struct { + Builder string // "arch-os[-note]" + Hash string + PackagePath string // (empty for Go commits) + + // The Go Commit this was built against (empty for Go commits). + GoHash string + + OK bool + Log string `datastore:"-"` // for JSON unmarshaling only + LogHash string `datastore:",noindex"` // Key to the Log record. + + RunTime int64 // time to build+test in nanoseconds +} + +func (r *Result) Key(c appengine.Context) *datastore.Key { + p := Package{Path: r.PackagePath} + key := r.Builder + "|" + r.PackagePath + "|" + r.Hash + "|" + r.GoHash + return datastore.NewKey(c, "Result", key, 0, p.Key(c)) +} + +func (r *Result) Valid() os.Error { + if !validHash(r.Hash) { + return os.NewError("invalid Hash") + } + if r.PackagePath != "" && !validHash(r.GoHash) { + return os.NewError("invalid GoHash") + } + return nil +} + +// Data returns the Result in string format +// to be stored in Commit's ResultData field. +func (r *Result) Data() string { + return fmt.Sprintf("%v|%v|%v|%v", r.Builder, r.OK, r.LogHash, r.GoHash) +} + +// A Log is a gzip-compressed log file stored under the SHA1 hash of the +// uncompressed log text. +type Log struct { + CompressedLog []byte +} + +func (l *Log) Text() ([]byte, os.Error) { + d, err := gzip.NewReader(bytes.NewBuffer(l.CompressedLog)) + if err != nil { + return nil, fmt.Errorf("reading log data: %v", err) + } + b, err := ioutil.ReadAll(d) + if err != nil { + return nil, fmt.Errorf("reading log data: %v", err) + } + return b, nil +} + +func PutLog(c appengine.Context, text string) (hash string, err os.Error) { + h := sha1.New() + io.WriteString(h, text) + b := new(bytes.Buffer) + z, _ := gzip.NewWriterLevel(b, gzip.BestCompression) + io.WriteString(z, text) + z.Close() + hash = fmt.Sprintf("%x", h.Sum()) + key := datastore.NewKey(c, "Log", hash, 0, nil) + _, err = datastore.Put(c, key, &Log{b.Bytes()}) + return +} + +// A Tag is used to keep track of the most recent Go weekly and release tags. +// Typically there will be one Tag entity for each kind of hg tag. +type Tag struct { + Kind string // "weekly", "release", or "tip" + Name string // the tag itself (for example: "release.r60") + Hash string +} + +func (t *Tag) Key(c appengine.Context) *datastore.Key { + p := &Package{} + return datastore.NewKey(c, "Tag", t.Kind, 0, p.Key(c)) +} + +func (t *Tag) Valid() os.Error { + if t.Kind != "weekly" && t.Kind != "release" && t.Kind != "tip" { + return os.NewError("invalid Kind") + } + if !validHash(t.Hash) { + return os.NewError("invalid Hash") + } + return nil +} + +// GetTag fetches a Tag by name from the datastore. +func GetTag(c appengine.Context, tag string) (*Tag, os.Error) { + t := &Tag{Kind: tag} + if err := datastore.Get(c, t.Key(c), t); err != nil { + if err == datastore.ErrNoSuchEntity { + return nil, os.NewError("tag not found: " + tag) + } + return nil, err + } + if err := t.Valid(); err != nil { + return nil, err + } + return t, nil +} + +// Packages returns all non-Go packages. +func Packages(c appengine.Context) ([]*Package, os.Error) { + var pkgs []*Package + for t := datastore.NewQuery("Package").Run(c); ; { + pkg := new(Package) + if _, err := t.Next(pkg); err == datastore.Done { + break + } else if err != nil { + return nil, err + } + if pkg.Path != "" { + pkgs = append(pkgs, pkg) + } + } + return pkgs, nil +} diff --git a/misc/dashboard/app/build/handler.go b/misc/dashboard/app/build/handler.go new file mode 100644 index 000000000..b3e62ad46 --- /dev/null +++ b/misc/dashboard/app/build/handler.go @@ -0,0 +1,428 @@ +// Copyright 2011 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package build + +import ( + "crypto/hmac" + "fmt" + "http" + "json" + "os" + + "appengine" + "appengine/datastore" + "cache" +) + +const commitsPerPage = 30 + +// defaultPackages specifies the Package records to be created by initHandler. +var defaultPackages = []*Package{ + &Package{Name: "Go"}, +} + +// commitHandler retrieves commit data or records a new commit. +// +// For GET requests it returns a Commit value for the specified +// packagePath and hash. +// +// For POST requests it reads a JSON-encoded Commit value from the request +// body and creates a new Commit entity. It also updates the "tip" Tag for +// each new commit at tip. +// +// This handler is used by a gobuilder process in -commit mode. +func commitHandler(r *http.Request) (interface{}, os.Error) { + c := appengine.NewContext(r) + com := new(Commit) + + if r.Method == "GET" { + com.PackagePath = r.FormValue("packagePath") + com.Hash = r.FormValue("hash") + if err := datastore.Get(c, com.Key(c), com); err != nil { + return nil, fmt.Errorf("getting Commit: %v", err) + } + return com, nil + } + if r.Method != "POST" { + return nil, errBadMethod(r.Method) + } + + // POST request + defer r.Body.Close() + if err := json.NewDecoder(r.Body).Decode(com); err != nil { + return nil, fmt.Errorf("decoding Body: %v", err) + } + if len(com.Desc) > maxDatastoreStringLen { + com.Desc = com.Desc[:maxDatastoreStringLen] + } + if err := com.Valid(); err != nil { + return nil, fmt.Errorf("validating Commit: %v", err) + } + defer cache.Tick(c) + tx := func(c appengine.Context) os.Error { + return addCommit(c, com) + } + return nil, datastore.RunInTransaction(c, tx, nil) +} + +// addCommit adds the Commit entity to the datastore and updates the tip Tag. +// It must be run inside a datastore transaction. +func addCommit(c appengine.Context, com *Commit) os.Error { + var tc Commit // temp value so we don't clobber com + err := datastore.Get(c, com.Key(c), &tc) + if err != datastore.ErrNoSuchEntity { + // if this commit is already in the datastore, do nothing + if err == nil { + return nil + } + return fmt.Errorf("getting Commit: %v", err) + } + // get the next commit number + p, err := GetPackage(c, com.PackagePath) + if err != nil { + return fmt.Errorf("GetPackage: %v", err) + } + com.Num = p.NextNum + p.NextNum++ + if _, err := datastore.Put(c, p.Key(c), p); err != nil { + return fmt.Errorf("putting Package: %v", err) + } + // if this isn't the first Commit test the parent commit exists + if com.Num > 0 { + n, err := datastore.NewQuery("Commit"). + Filter("Hash =", com.ParentHash). + Ancestor(p.Key(c)). + Count(c) + if err != nil { + return fmt.Errorf("testing for parent Commit: %v", err) + } + if n == 0 { + return os.NewError("parent commit not found") + } + } + // update the tip Tag if this is the Go repo + if p.Path == "" { + t := &Tag{Kind: "tip", Hash: com.Hash} + if _, err = datastore.Put(c, t.Key(c), t); err != nil { + return fmt.Errorf("putting Tag: %v", err) + } + } + // put the Commit + if _, err = datastore.Put(c, com.Key(c), com); err != nil { + return fmt.Errorf("putting Commit: %v", err) + } + return nil +} + +// tagHandler records a new tag. It reads a JSON-encoded Tag value from the +// request body and updates the Tag entity for the Kind of tag provided. +// +// This handler is used by a gobuilder process in -commit mode. +func tagHandler(r *http.Request) (interface{}, os.Error) { + if r.Method != "POST" { + return nil, errBadMethod(r.Method) + } + + t := new(Tag) + defer r.Body.Close() + if err := json.NewDecoder(r.Body).Decode(t); err != nil { + return nil, err + } + if err := t.Valid(); err != nil { + return nil, err + } + c := appengine.NewContext(r) + defer cache.Tick(c) + _, err := datastore.Put(c, t.Key(c), t) + return nil, err +} + +// Todo is a todoHandler response. +type Todo struct { + Kind string // "build-go-commit" or "build-package" + Data interface{} +} + +// todoHandler returns the next action to be performed by a builder. +// It expects "builder" and "kind" query parameters and returns a *Todo value. +// Multiple "kind" parameters may be specified. +func todoHandler(r *http.Request) (interface{}, os.Error) { + c := appengine.NewContext(r) + now := cache.Now(c) + key := "build-todo-" + r.Form.Encode() + var todo *Todo + if cache.Get(r, now, key, &todo) { + return todo, nil + } + var err os.Error + builder := r.FormValue("builder") + for _, kind := range r.Form["kind"] { + var data interface{} + switch kind { + case "build-go-commit": + data, err = buildTodo(c, builder, "", "") + case "build-package": + packagePath := r.FormValue("packagePath") + goHash := r.FormValue("goHash") + data, err = buildTodo(c, builder, packagePath, goHash) + } + if data != nil || err != nil { + todo = &Todo{Kind: kind, Data: data} + break + } + } + if err == nil { + cache.Set(r, now, key, todo) + } + return todo, err +} + +// buildTodo returns the next Commit to be built (or nil if none available). +// +// If packagePath and goHash are empty, it scans the first 20 Go Commits in +// Num-descending order and returns the first one it finds that doesn't have a +// Result for this builder. +// +// If provided with non-empty packagePath and goHash args, it scans the first +// 20 Commits in Num-descending order for the specified packagePath and +// returns the first that doesn't have a Result for this builder and goHash. +func buildTodo(c appengine.Context, builder, packagePath, goHash string) (interface{}, os.Error) { + p, err := GetPackage(c, packagePath) + if err != nil { + return nil, err + } + + t := datastore.NewQuery("Commit"). + Ancestor(p.Key(c)). + Limit(commitsPerPage). + Order("-Num"). + Run(c) + for { + com := new(Commit) + if _, err := t.Next(com); err != nil { + if err == datastore.Done { + err = nil + } + return nil, err + } + if com.Result(builder, goHash) == nil { + return com, nil + } + } + panic("unreachable") +} + +// packagesHandler returns a list of the non-Go Packages monitored +// by the dashboard. +func packagesHandler(r *http.Request) (interface{}, os.Error) { + c := appengine.NewContext(r) + now := cache.Now(c) + const key = "build-packages" + var p []*Package + if cache.Get(r, now, key, &p) { + return p, nil + } + p, err := Packages(c) + if err != nil { + return nil, err + } + cache.Set(r, now, key, p) + return p, nil +} + +// resultHandler records a build result. +// It reads a JSON-encoded Result value from the request body, +// creates a new Result entity, and updates the relevant Commit entity. +// If the Log field is not empty, resultHandler creates a new Log entity +// and updates the LogHash field before putting the Commit entity. +func resultHandler(r *http.Request) (interface{}, os.Error) { + if r.Method != "POST" { + return nil, errBadMethod(r.Method) + } + + c := appengine.NewContext(r) + res := new(Result) + defer r.Body.Close() + if err := json.NewDecoder(r.Body).Decode(res); err != nil { + return nil, fmt.Errorf("decoding Body: %v", err) + } + if err := res.Valid(); err != nil { + return nil, fmt.Errorf("validating Result: %v", err) + } + defer cache.Tick(c) + // store the Log text if supplied + if len(res.Log) > 0 { + hash, err := PutLog(c, res.Log) + if err != nil { + return nil, fmt.Errorf("putting Log: %v", err) + } + res.LogHash = hash + } + tx := func(c appengine.Context) os.Error { + // check Package exists + if _, err := GetPackage(c, res.PackagePath); err != nil { + return fmt.Errorf("GetPackage: %v", err) + } + // put Result + if _, err := datastore.Put(c, res.Key(c), res); err != nil { + return fmt.Errorf("putting Result: %v", err) + } + // add Result to Commit + com := &Commit{PackagePath: res.PackagePath, Hash: res.Hash} + if err := com.AddResult(c, res); err != nil { + return fmt.Errorf("AddResult: %v", err) + } + // Send build failure notifications, if necessary. + // Note this must run after the call AddResult, which + // populates the Commit's ResultData field. + return notifyOnFailure(c, com, res.Builder) + } + return nil, datastore.RunInTransaction(c, tx, nil) +} + +// logHandler displays log text for a given hash. +// It handles paths like "/log/hash". +func logHandler(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-type", "text/plain") + c := appengine.NewContext(r) + hash := r.URL.Path[len("/log/"):] + key := datastore.NewKey(c, "Log", hash, 0, nil) + l := new(Log) + if err := datastore.Get(c, key, l); err != nil { + logErr(w, r, err) + return + } + b, err := l.Text() + if err != nil { + logErr(w, r, err) + return + } + w.Write(b) +} + +type dashHandler func(*http.Request) (interface{}, os.Error) + +type dashResponse struct { + Response interface{} + Error string +} + +// errBadMethod is returned by a dashHandler when +// the request has an unsuitable method. +type errBadMethod string + +func (e errBadMethod) String() string { + return "bad method: " + string(e) +} + +// AuthHandler wraps a http.HandlerFunc with a handler that validates the +// supplied key and builder query parameters. +func AuthHandler(h dashHandler) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + c := appengine.NewContext(r) + + // Put the URL Query values into r.Form to avoid parsing the + // request body when calling r.FormValue. + r.Form = r.URL.Query() + + var err os.Error + var resp interface{} + + // Validate key query parameter for POST requests only. + key := r.FormValue("key") + builder := r.FormValue("builder") + if r.Method == "POST" && !validKey(c, key, builder) { + err = os.NewError("invalid key: " + key) + } + + // Call the original HandlerFunc and return the response. + if err == nil { + resp, err = h(r) + } + + // Write JSON response. + dashResp := &dashResponse{Response: resp} + if err != nil { + c.Errorf("%v", err) + dashResp.Error = err.String() + } + w.Header().Set("Content-Type", "application/json") + if err = json.NewEncoder(w).Encode(dashResp); err != nil { + c.Criticalf("encoding response: %v", err) + } + } +} + +func initHandler(w http.ResponseWriter, r *http.Request) { + // TODO(adg): devise a better way of bootstrapping new packages + c := appengine.NewContext(r) + defer cache.Tick(c) + for _, p := range defaultPackages { + if err := datastore.Get(c, p.Key(c), new(Package)); err == nil { + continue + } else if err != datastore.ErrNoSuchEntity { + logErr(w, r, err) + return + } + if _, err := datastore.Put(c, p.Key(c), p); err != nil { + logErr(w, r, err) + return + } + } + fmt.Fprint(w, "OK") +} + +func keyHandler(w http.ResponseWriter, r *http.Request) { + builder := r.FormValue("builder") + if builder == "" { + logErr(w, r, os.NewError("must supply builder in query string")) + return + } + c := appengine.NewContext(r) + fmt.Fprint(w, builderKey(c, builder)) +} + +func init() { + // admin handlers + http.HandleFunc("/init", initHandler) + http.HandleFunc("/key", keyHandler) + + // authenticated handlers + http.HandleFunc("/commit", AuthHandler(commitHandler)) + http.HandleFunc("/packages", AuthHandler(packagesHandler)) + http.HandleFunc("/result", AuthHandler(resultHandler)) + http.HandleFunc("/tag", AuthHandler(tagHandler)) + http.HandleFunc("/todo", AuthHandler(todoHandler)) + + // public handlers + http.HandleFunc("/log/", logHandler) +} + +func validHash(hash string) bool { + // TODO(adg): correctly validate a hash + return hash != "" +} + +func validKey(c appengine.Context, key, builder string) bool { + if appengine.IsDevAppServer() { + return true + } + if key == secretKey(c) { + return true + } + return key == builderKey(c, builder) +} + +func builderKey(c appengine.Context, builder string) string { + h := hmac.NewMD5([]byte(secretKey(c))) + h.Write([]byte(builder)) + return fmt.Sprintf("%x", h.Sum()) +} + +func logErr(w http.ResponseWriter, r *http.Request, err os.Error) { + appengine.NewContext(r).Errorf("Error: %v", err) + w.WriteHeader(http.StatusInternalServerError) + fmt.Fprint(w, "Error: ", err) +} diff --git a/misc/dashboard/app/build/key.go b/misc/dashboard/app/build/key.go new file mode 100644 index 000000000..5306c3b6b --- /dev/null +++ b/misc/dashboard/app/build/key.go @@ -0,0 +1,62 @@ +// Copyright 2011 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package build + +import ( + "sync" + + "appengine" + "appengine/datastore" +) + +var theKey struct { + sync.RWMutex + BuilderKey +} + +type BuilderKey struct { + Secret string +} + +func (k *BuilderKey) Key(c appengine.Context) *datastore.Key { + return datastore.NewKey(c, "BuilderKey", "root", 0, nil) +} + +func secretKey(c appengine.Context) string { + // check with rlock + theKey.RLock() + k := theKey.Secret + theKey.RUnlock() + if k != "" { + return k + } + + // prepare to fill; check with lock and keep lock + theKey.Lock() + defer theKey.Unlock() + if theKey.Secret != "" { + return theKey.Secret + } + + // fill + if err := datastore.Get(c, theKey.Key(c), &theKey.BuilderKey); err != nil { + if err == datastore.ErrNoSuchEntity { + // If the key is not stored in datastore, write it. + // This only happens at the beginning of a new deployment. + // The code is left here for SDK use and in case a fresh + // deployment is ever needed. "gophers rule" is not the + // real key. + if !appengine.IsDevAppServer() { + panic("lost key from datastore") + } + theKey.Secret = "gophers rule" + datastore.Put(c, theKey.Key(c), &theKey.BuilderKey) + return theKey.Secret + } + panic("cannot load builder key: " + err.String()) + } + + return theKey.Secret +} diff --git a/misc/dashboard/app/build/notify.go b/misc/dashboard/app/build/notify.go new file mode 100644 index 000000000..826132be2 --- /dev/null +++ b/misc/dashboard/app/build/notify.go @@ -0,0 +1,150 @@ +// Copyright 2011 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package build + +import ( + "appengine" + "appengine/datastore" + "appengine/delay" + "appengine/mail" + "bytes" + "fmt" + "gob" + "os" + "template" +) + +const ( + mailFrom = "builder@golang.org" // use this for sending any mail + failMailTo = "golang-dev@googlegroups.com" + domain = "build.golang.org" +) + +// notifyOnFailure checks whether the supplied Commit or the subsequent +// Commit (if present) breaks the build for this builder. +// If either of those commits break the build an email notification is sent +// from a delayed task. (We use a task because this way the mail won't be +// sent if the enclosing datastore transaction fails.) +// +// This must be run in a datastore transaction, and the provided *Commit must +// have been retrieved from the datastore within that transaction. +func notifyOnFailure(c appengine.Context, com *Commit, builder string) os.Error { + // TODO(adg): implement notifications for packages + if com.PackagePath != "" { + return nil + } + + p := &Package{Path: com.PackagePath} + var broken *Commit + ok, present := com.OK(builder, "") + if !present { + return fmt.Errorf("no result for %s/%s", com.Hash, builder) + } + q := datastore.NewQuery("Commit").Ancestor(p.Key(c)) + if ok { + // This commit is OK. Notify if next Commit is broken. + next := new(Commit) + q.Filter("ParentHash=", com.Hash) + if err := firstMatch(c, q, next); err != nil { + if err == datastore.ErrNoSuchEntity { + // OK at tip, no notification necessary. + return nil + } + return err + } + if ok, present := next.OK(builder, ""); present && !ok { + broken = next + } + } else { + // This commit is broken. Notify if the previous Commit is OK. + prev := new(Commit) + q.Filter("Hash=", com.ParentHash) + if err := firstMatch(c, q, prev); err != nil { + if err == datastore.ErrNoSuchEntity { + // No previous result, let the backfill of + // this result trigger the notification. + return nil + } + return err + } + if ok, present := prev.OK(builder, ""); present && ok { + broken = com + } + } + var err os.Error + if broken != nil && !broken.FailNotificationSent { + c.Infof("%s is broken commit; notifying", broken.Hash) + sendFailMailLater.Call(c, broken, builder) // add task to queue + broken.FailNotificationSent = true + _, err = datastore.Put(c, broken.Key(c), broken) + } + return err +} + +// firstMatch executes the query q and loads the first entity into v. +func firstMatch(c appengine.Context, q *datastore.Query, v interface{}) os.Error { + t := q.Limit(1).Run(c) + _, err := t.Next(v) + if err == datastore.Done { + err = datastore.ErrNoSuchEntity + } + return err +} + +var ( + sendFailMailLater = delay.Func("sendFailMail", sendFailMail) + sendFailMailTmpl = template.Must( + template.New("notify").Funcs(tmplFuncs).ParseFile("build/notify.txt"), + ) +) + +func init() { + gob.Register(&Commit{}) // for delay +} + +// sendFailMail sends a mail notification that the build failed on the +// provided commit and builder. +func sendFailMail(c appengine.Context, com *Commit, builder string) { + // TODO(adg): handle packages + + // get Result + r := com.Result(builder, "") + if r == nil { + c.Errorf("finding result for %q: %+v", builder, com) + return + } + + // get Log + k := datastore.NewKey(c, "Log", r.LogHash, 0, nil) + l := new(Log) + if err := datastore.Get(c, k, l); err != nil { + c.Errorf("finding Log record %v: %v", r.LogHash, err) + return + } + + // prepare mail message + var body bytes.Buffer + err := sendFailMailTmpl.Execute(&body, map[string]interface{}{ + "Builder": builder, "Commit": com, "Result": r, "Log": l, + "Hostname": domain, + }) + if err != nil { + c.Errorf("rendering mail template: %v", err) + return + } + subject := fmt.Sprintf("%s broken by %s", builder, shortDesc(com.Desc)) + msg := &mail.Message{ + Sender: mailFrom, + To: []string{failMailTo}, + ReplyTo: failMailTo, + Subject: subject, + Body: body.String(), + } + + // send mail + if err := mail.Send(c, msg); err != nil { + c.Errorf("sending mail: %v", err) + } +} diff --git a/misc/dashboard/app/build/notify.txt b/misc/dashboard/app/build/notify.txt new file mode 100644 index 000000000..6c9006703 --- /dev/null +++ b/misc/dashboard/app/build/notify.txt @@ -0,0 +1,9 @@ +Change {{shortHash .Commit.Hash}} broke the {{.Builder}} build: +http://{{.Hostname}}/log/{{.Result.LogHash}} + +{{.Commit.Desc}} + +http://code.google.com/p/go/source/detail?r={{shortHash .Commit.Hash}} + +$ tail -200 < log +{{printf "%s" .Log.Text | tail 200}} diff --git a/misc/dashboard/app/build/test.go b/misc/dashboard/app/build/test.go new file mode 100644 index 000000000..a923969bc --- /dev/null +++ b/misc/dashboard/app/build/test.go @@ -0,0 +1,251 @@ +// Copyright 2011 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package build + +// TODO(adg): test authentication + +import ( + "appengine" + "appengine/datastore" + "bytes" + "fmt" + "http" + "http/httptest" + "io" + "json" + "os" + "strings" + "time" + "url" +) + +func init() { + http.HandleFunc("/buildtest", testHandler) +} + +var testEntityKinds = []string{ + "Package", + "Commit", + "Result", + "Log", +} + +const testPkg = "code.google.com/p/go.test" + +var testPackage = &Package{Name: "Test", Path: testPkg} + +var testPackages = []*Package{ + &Package{Name: "Go", Path: ""}, + testPackage, +} + +var tCommitTime = time.Seconds() - 60*60*24*7 + +func tCommit(hash, parentHash string) *Commit { + tCommitTime += 60 * 60 * 12 // each commit should have a different time + return &Commit{ + Hash: hash, + ParentHash: parentHash, + Time: datastore.Time(tCommitTime * 1e6), + User: "adg", + Desc: "change description", + } +} + +var testRequests = []struct { + path string + vals url.Values + req interface{} + res interface{} +}{ + // Packages + {"/packages", nil, nil, []*Package{testPackage}}, + + // Go repo + {"/commit", nil, tCommit("0001", "0000"), nil}, + {"/commit", nil, tCommit("0002", "0001"), nil}, + {"/commit", nil, tCommit("0003", "0002"), nil}, + {"/todo", url.Values{"kind": {"build-go-commit"}, "builder": {"linux-386"}}, nil, &Todo{Kind: "build-go-commit", Data: &Commit{Hash: "0003"}}}, + {"/todo", url.Values{"kind": {"build-go-commit"}, "builder": {"linux-amd64"}}, nil, &Todo{Kind: "build-go-commit", Data: &Commit{Hash: "0003"}}}, + {"/result", nil, &Result{Builder: "linux-386", Hash: "0001", OK: true}, nil}, + {"/todo", url.Values{"kind": {"build-go-commit"}, "builder": {"linux-386"}}, nil, &Todo{Kind: "build-go-commit", Data: &Commit{Hash: "0003"}}}, + {"/result", nil, &Result{Builder: "linux-386", Hash: "0002", OK: true}, nil}, + {"/todo", url.Values{"kind": {"build-go-commit"}, "builder": {"linux-386"}}, nil, &Todo{Kind: "build-go-commit", Data: &Commit{Hash: "0003"}}}, + + // multiple builders + {"/todo", url.Values{"kind": {"build-go-commit"}, "builder": {"linux-amd64"}}, nil, &Todo{Kind: "build-go-commit", Data: &Commit{Hash: "0003"}}}, + {"/result", nil, &Result{Builder: "linux-amd64", Hash: "0003", OK: true}, nil}, + {"/todo", url.Values{"kind": {"build-go-commit"}, "builder": {"linux-386"}}, nil, &Todo{Kind: "build-go-commit", Data: &Commit{Hash: "0003"}}}, + {"/todo", url.Values{"kind": {"build-go-commit"}, "builder": {"linux-amd64"}}, nil, &Todo{Kind: "build-go-commit", Data: &Commit{Hash: "0002"}}}, + + // branches + {"/commit", nil, tCommit("0004", "0003"), nil}, + {"/commit", nil, tCommit("0005", "0002"), nil}, + {"/todo", url.Values{"kind": {"build-go-commit"}, "builder": {"linux-386"}}, nil, &Todo{Kind: "build-go-commit", Data: &Commit{Hash: "0005"}}}, + {"/result", nil, &Result{Builder: "linux-386", Hash: "0005", OK: true}, nil}, + {"/todo", url.Values{"kind": {"build-go-commit"}, "builder": {"linux-386"}}, nil, &Todo{Kind: "build-go-commit", Data: &Commit{Hash: "0004"}}}, + {"/result", nil, &Result{Builder: "linux-386", Hash: "0004", OK: true}, nil}, + {"/todo", url.Values{"kind": {"build-go-commit"}, "builder": {"linux-386"}}, nil, &Todo{Kind: "build-go-commit", Data: &Commit{Hash: "0003"}}}, + + // logs + {"/result", nil, &Result{Builder: "linux-386", Hash: "0003", OK: false, Log: "test"}, nil}, + {"/log/a94a8fe5ccb19ba61c4c0873d391e987982fbbd3", nil, nil, "test"}, + {"/todo", url.Values{"kind": {"build-go-commit"}, "builder": {"linux-386"}}, nil, nil}, + + // repeat failure (shouldn't re-send mail) + {"/result", nil, &Result{Builder: "linux-386", Hash: "0003", OK: false, Log: "test"}, nil}, + + // non-Go repos + {"/commit", nil, &Commit{PackagePath: testPkg, Hash: "1001", ParentHash: "1000"}, nil}, + {"/commit", nil, &Commit{PackagePath: testPkg, Hash: "1002", ParentHash: "1001"}, nil}, + {"/commit", nil, &Commit{PackagePath: testPkg, Hash: "1003", ParentHash: "1002"}, nil}, + {"/todo", url.Values{"kind": {"build-package"}, "builder": {"linux-386"}, "packagePath": {testPkg}, "goHash": {"0001"}}, nil, &Todo{Kind: "build-package", Data: &Commit{Hash: "1003"}}}, + {"/result", nil, &Result{PackagePath: testPkg, Builder: "linux-386", Hash: "1003", GoHash: "0001", OK: true}, nil}, + {"/todo", url.Values{"kind": {"build-package"}, "builder": {"linux-386"}, "packagePath": {testPkg}, "goHash": {"0001"}}, nil, &Todo{Kind: "build-package", Data: &Commit{Hash: "1002"}}}, + {"/result", nil, &Result{PackagePath: testPkg, Builder: "linux-386", Hash: "1002", GoHash: "0001", OK: true}, nil}, + {"/todo", url.Values{"kind": {"build-package"}, "builder": {"linux-386"}, "packagePath": {testPkg}, "goHash": {"0001"}}, nil, &Todo{Kind: "build-package", Data: &Commit{Hash: "1001"}}}, + {"/result", nil, &Result{PackagePath: testPkg, Builder: "linux-386", Hash: "1001", GoHash: "0001", OK: true}, nil}, + {"/todo", url.Values{"kind": {"build-package"}, "builder": {"linux-386"}, "packagePath": {testPkg}, "goHash": {"0001"}}, nil, nil}, + {"/todo", url.Values{"kind": {"build-package"}, "builder": {"linux-386"}, "packagePath": {testPkg}, "goHash": {"0002"}}, nil, &Todo{Kind: "build-package", Data: &Commit{Hash: "1003"}}}, + {"/result", nil, &Result{PackagePath: testPkg, Builder: "linux-386", Hash: "1001", GoHash: "0005", OK: false, Log: "boo"}, nil}, +} + +func testHandler(w http.ResponseWriter, r *http.Request) { + if !appengine.IsDevAppServer() { + fmt.Fprint(w, "These tests must be run under the dev_appserver.") + return + } + c := appengine.NewContext(r) + if err := nukeEntities(c, testEntityKinds); err != nil { + logErr(w, r, err) + return + } + if r.FormValue("nukeonly") != "" { + fmt.Fprint(w, "OK") + return + } + + for _, p := range testPackages { + if _, err := datastore.Put(c, p.Key(c), p); err != nil { + logErr(w, r, err) + return + } + } + + for i, t := range testRequests { + c.Infof("running test %d %s", i, t.path) + errorf := func(format string, args ...interface{}) { + fmt.Fprintf(w, "%d %s: ", i, t.path) + fmt.Fprintf(w, format, args...) + fmt.Fprintln(w) + } + var body io.ReadWriter + if t.req != nil { + body = new(bytes.Buffer) + json.NewEncoder(body).Encode(t.req) + } + url := "http://" + domain + t.path + if t.vals != nil { + url += "?" + t.vals.Encode() + } + req, err := http.NewRequest("POST", url, body) + if err != nil { + logErr(w, r, err) + return + } + if t.req != nil { + req.Method = "POST" + } + req.Header = r.Header + rec := httptest.NewRecorder() + + // Make the request + http.DefaultServeMux.ServeHTTP(rec, req) + + if rec.Code != 0 && rec.Code != 200 { + errorf(rec.Body.String()) + return + } + resp := new(dashResponse) + + // If we're expecting a *Todo value, + // prime the Response field with a Todo and a Commit inside it. + if _, ok := t.res.(*Todo); ok { + resp.Response = &Todo{Data: &Commit{}} + } + + if strings.HasPrefix(t.path, "/log/") { + resp.Response = rec.Body.String() + } else { + err := json.NewDecoder(rec.Body).Decode(resp) + if err != nil { + errorf("decoding response: %v", err) + return + } + } + if e, ok := t.res.(string); ok { + g, ok := resp.Response.(string) + if !ok { + errorf("Response not string: %T", resp.Response) + return + } + if g != e { + errorf("response mismatch: got %q want %q", g, e) + return + } + } + if e, ok := t.res.(*Todo); ok { + g, ok := resp.Response.(*Todo) + if !ok { + errorf("Response not *Todo: %T", resp.Response) + return + } + if e.Data == nil && g.Data != nil { + errorf("Response.Data should be nil, got: %v", g.Data) + return + } + if g.Data == nil { + errorf("Response.Data is nil, want: %v", e.Data) + return + } + gd, ok := g.Data.(*Commit) + if !ok { + errorf("Response.Data not *Commit: %T", g.Data) + return + } + if e.Data.(*Commit).Hash != gd.Hash { + errorf("hashes don't match: got %q, want %q", g, e) + return + } + } + if t.res == nil && resp.Response != nil { + errorf("response mismatch: got %q expected <nil>", + resp.Response) + return + } + } + fmt.Fprint(w, "PASS") +} + +func nukeEntities(c appengine.Context, kinds []string) os.Error { + if !appengine.IsDevAppServer() { + return os.NewError("can't nuke production data") + } + var keys []*datastore.Key + for _, kind := range kinds { + q := datastore.NewQuery(kind).KeysOnly() + for t := q.Run(c); ; { + k, err := t.Next(nil) + if err == datastore.Done { + break + } + if err != nil { + return err + } + keys = append(keys, k) + } + } + return datastore.DeleteMulti(c, keys) +} diff --git a/misc/dashboard/app/build/ui.go b/misc/dashboard/app/build/ui.go new file mode 100644 index 000000000..032fdbd84 --- /dev/null +++ b/misc/dashboard/app/build/ui.go @@ -0,0 +1,313 @@ +// Copyright 2011 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// TODO(adg): packages at weekly/release +// TODO(adg): some means to register new packages + +package build + +import ( + "bytes" + "exp/template/html" + "http" + "os" + "regexp" + "sort" + "strconv" + "strings" + "template" + + "appengine" + "appengine/datastore" + "cache" +) + +func init() { + http.HandleFunc("/", uiHandler) + html.Escape(uiTemplate) +} + +// uiHandler draws the build status page. +func uiHandler(w http.ResponseWriter, r *http.Request) { + c := appengine.NewContext(r) + now := cache.Now(c) + const key = "build-ui" + + page, _ := strconv.Atoi(r.FormValue("page")) + if page < 0 { + page = 0 + } + + // Used cached version of front page, if available. + if page == 0 { + var b []byte + if cache.Get(r, now, key, &b) { + w.Write(b) + return + } + } + + commits, err := goCommits(c, page) + if err != nil { + logErr(w, r, err) + return + } + builders := commitBuilders(commits) + + tipState, err := TagState(c, "tip") + if err != nil { + logErr(w, r, err) + return + } + + p := &Pagination{} + if len(commits) == commitsPerPage { + p.Next = page + 1 + } + if page > 0 { + p.Prev = page - 1 + p.HasPrev = true + } + data := &uiTemplateData{commits, builders, tipState, p} + + var buf bytes.Buffer + if err := uiTemplate.Execute(&buf, data); err != nil { + logErr(w, r, err) + return + } + + // Cache the front page. + if page == 0 { + cache.Set(r, now, key, buf.Bytes()) + } + + buf.WriteTo(w) +} + +type Pagination struct { + Next, Prev int + HasPrev bool +} + +// goCommits gets a slice of the latest Commits to the Go repository. +// If page > 0 it paginates by commitsPerPage. +func goCommits(c appengine.Context, page int) ([]*Commit, os.Error) { + q := datastore.NewQuery("Commit"). + Ancestor((&Package{}).Key(c)). + Order("-Time"). + Limit(commitsPerPage). + Offset(page * commitsPerPage) + var commits []*Commit + _, err := q.GetAll(c, &commits) + return commits, err +} + +// commitBuilders returns the names of the builders that provided +// Results for the provided commits. +func commitBuilders(commits []*Commit) []string { + builders := make(map[string]bool) + for _, commit := range commits { + for _, r := range commit.Results("") { + builders[r.Builder] = true + } + } + return keys(builders) +} + +func keys(m map[string]bool) (s []string) { + for k := range m { + s = append(s, k) + } + sort.Strings(s) + return +} + +// PackageState represents the state of a Package at a tag. +type PackageState struct { + *Package + *Commit + Results []*Result + OK bool +} + +// TagState fetches the results for all non-Go packages at the specified tag. +func TagState(c appengine.Context, name string) ([]*PackageState, os.Error) { + tag, err := GetTag(c, name) + if err != nil { + return nil, err + } + pkgs, err := Packages(c) + if err != nil { + return nil, err + } + var states []*PackageState + for _, pkg := range pkgs { + commit, err := pkg.LastCommit(c) + if err != nil { + c.Errorf("no Commit found: %v", pkg) + continue + } + results := commit.Results(tag.Hash) + ok := len(results) > 0 + for _, r := range results { + ok = ok && r.OK + } + states = append(states, &PackageState{ + pkg, commit, results, ok, + }) + } + return states, nil +} + +type uiTemplateData struct { + Commits []*Commit + Builders []string + TipState []*PackageState + Pagination *Pagination +} + +var uiTemplate = template.Must( + template.New("ui").Funcs(tmplFuncs).ParseFile("build/ui.html"), +) + +var tmplFuncs = template.FuncMap{ + "builderOS": builderOS, + "builderArch": builderArch, + "builderArchShort": builderArchShort, + "builderArchChar": builderArchChar, + "builderTitle": builderTitle, + "builderSpans": builderSpans, + "repoURL": repoURL, + "shortDesc": shortDesc, + "shortHash": shortHash, + "shortUser": shortUser, + "tail": tail, +} + +func splitDash(s string) (string, string) { + i := strings.Index(s, "-") + if i >= 0 { + return s[:i], s[i+1:] + } + return s, "" +} + +// builderOS returns the os tag for a builder string +func builderOS(s string) string { + os, _ := splitDash(s) + return os +} + +// builderArch returns the arch tag for a builder string +func builderArch(s string) string { + _, arch := splitDash(s) + arch, _ = splitDash(arch) // chop third part + return arch +} + +// builderArchShort returns a short arch tag for a builder string +func builderArchShort(s string) string { + arch := builderArch(s) + switch arch { + case "amd64": + return "x64" + } + return arch +} + +// builderArchChar returns the architecture letter for a builder string +func builderArchChar(s string) string { + arch := builderArch(s) + switch arch { + case "386": + return "8" + case "amd64": + return "6" + case "arm": + return "5" + } + return arch +} + +type builderSpan struct { + N int + OS string +} + +// builderSpans creates a list of tags showing +// the builder's operating system names, spanning +// the appropriate number of columns. +func builderSpans(s []string) []builderSpan { + var sp []builderSpan + for len(s) > 0 { + i := 1 + os := builderOS(s[0]) + for i < len(s) && builderOS(s[i]) == os { + i++ + } + sp = append(sp, builderSpan{i, os}) + s = s[i:] + } + return sp +} + +// builderTitle formats "linux-amd64-foo" as "linux amd64 foo". +func builderTitle(s string) string { + return strings.Replace(s, "-", " ", -1) +} + +// shortDesc returns the first line of a description. +func shortDesc(desc string) string { + if i := strings.Index(desc, "\n"); i != -1 { + desc = desc[:i] + } + return desc +} + +// shortHash returns a short version of a hash. +func shortHash(hash string) string { + if len(hash) > 12 { + hash = hash[:12] + } + return hash +} + +// shortUser returns a shortened version of a user string. +func shortUser(user string) string { + if i, j := strings.Index(user, "<"), strings.Index(user, ">"); 0 <= i && i < j { + user = user[i+1 : j] + } + if i := strings.Index(user, "@"); i >= 0 { + return user[:i] + } + return user +} + +// repoRe matches Google Code repositories and subrepositories (without paths). +var repoRe = regexp.MustCompile(`^code\.google\.com/p/([a-z0-9\-]+)(\.[a-z0-9\-]+)?$`) + +// repoURL returns the URL of a change at a Google Code repository or subrepo. +func repoURL(hash, packagePath string) (string, os.Error) { + if packagePath == "" { + return "https://code.google.com/p/go/source/detail?r=" + hash, nil + } + m := repoRe.FindStringSubmatch(packagePath) + if m == nil { + return "", os.NewError("unrecognized package: " + packagePath) + } + url := "https://code.google.com/p/" + m[1] + "/source/detail?r=" + hash + if len(m) > 2 { + url += "&repo=" + m[2][1:] + } + return url, nil +} + +// tail returns the trailing n lines of s. +func tail(n int, s string) string { + lines := strings.Split(s, "\n") + if len(lines) < n { + return s + } + return strings.Join(lines[len(lines)-n:], "\n") +} diff --git a/misc/dashboard/app/build/ui.html b/misc/dashboard/app/build/ui.html new file mode 100644 index 000000000..678c95238 --- /dev/null +++ b/misc/dashboard/app/build/ui.html @@ -0,0 +1,178 @@ +<!DOCTYPE HTML> +<html> + <head> + <title>Go Build Dashboard</title> + <style> + body { + font-family: sans-serif; + padding: 0; margin: 0; + } + h1, h2 { + margin: 0; + padding: 5px; + } + h1 { + background: #eee; + } + h2 { + margin-top: 10px; + } + .build, .packages { + margin: 5px; + border-collapse: collapse; + } + .build td, .build th, .packages td, .packages th { + vertical-align: top; + padding: 2px 4px; + font-size: 10pt; + } + .build tr.commit:nth-child(2n) { + background-color: #f0f0f0; + } + .build .hash { + font-family: monospace; + font-size: 9pt; + } + .build .result { + text-align: center; + width: 2em; + } + .col-hash, .col-result { + border-right: solid 1px #ccc; + } + .build .arch { + font-size: 66%; + font-weight: normal; + } + .build .time { + color: #666; + } + .build .ok { + font-size: 83%; + } + .build .desc, .build .time, .build .user { + white-space: nowrap; + } + .paginate { + padding: 0.5em; + } + .paginate a { + padding: 0.5em; + background: #eee; + color: blue; + } + .paginate a.inactive { + color: #999; + } + .fail { + color: #C00; + } + </style> + </head> + <body> + + <h1>Go Build Status</h1> + + {{if $.Commits}} + + <table class="build"> + <colgroup class="col-hash"></colgroup> + {{range $.Builders | builderSpans}} + <colgroup class="col-result" span="{{.N}}"></colgroup> + {{end}} + <colgroup class="col-user"></colgroup> + <colgroup class="col-time"></colgroup> + <colgroup class="col-desc"></colgroup> + <tr> + <!-- extra row to make alternating colors use dark for first result --> + </tr> + <tr> + <th> </th> + {{range $.Builders | builderSpans}} + <th colspan="{{.N}}">{{.OS}}</th> + {{end}} + <th></th> + <th></th> + <th></th> + </tr> + <tr> + <th> </th> + {{range $.Builders}} + <th class="result arch" title="{{.}}">{{builderArchShort .}}</th> + {{end}} + </tr> + {{range $c := $.Commits}} + <tr class="commit"> + <td class="hash"><a href="{{repoURL .Hash ""}}">{{shortHash .Hash}}</a></td> + {{range $.Builders}} + <td class="result"> + {{with $c.Result . ""}} + {{if .OK}} + <span class="ok">ok</span> + {{else}} + <a href="/log/{{.LogHash}}" class="fail">fail</a> + {{end}} + {{else}} + + {{end}} + </td> + {{end}} + <td class="user" title="{{.User}}">{{shortUser .User}}</td> + <td class="time">{{.Time.Time.Format "Mon 02 Jan 15:04"}}</td> + <td class="desc" title="{{.Desc}}">{{shortDesc .Desc}}</td> + </tr> + {{end}} + </table> + + {{with $.Pagination}} + <div class="paginate"> + <a {{if .HasPrev}}href="?page={{.Prev}}"{{else}}class="inactive"{{end}}>prev</a> + <a {{if .Next}}href="?page={{.Next}}"{{else}}class="inactive"{{end}}>next</a> + <a {{if .HasPrev}}href="?page=0}"{{else}}class="inactive"{{end}}>top</a> + </div> + {{end}} + + {{else}} + <p>No commits to display. Hm.</p> + {{end}} + + {{if $.TipState}} + <h2>Other packages</h2> + + <table class="packages"> + <tr> + <th>State</th> + <th>Package</th> + <th> </th> + </tr> + {{range $state := $.TipState}} + <tr> + <td> + {{if .Results}} + <img src="/static/status_{{if .OK}}good{{else}}alert{{end}}.gif" /> + {{else}} + + {{end}} + </td> + <td><a title="{{.Package.Path}}">{{.Package.Name}}</a></td> + <td> + {{range .Results}} + <div> + {{$h := $state.Commit.Hash}} + <a href="{{repoURL $h $state.Commit.PackagePath}}">{{shortHash $h}}</a> + {{if .OK}} + ok + {{else}} + <a href="/log/{{.LogHash}}" class="fail">failed</a> + {{end}} + on {{.Builder}}/<a href="{{repoURL .GoHash ""}}">{{shortHash .GoHash}}</a> + </a></div> + {{end}} + </td> + </tr> + {{end}} + </table> + {{end}} + + </body> +</html> |