app/build: expand JSON format output

This expands the JSON dashboard output to include everything that's
visible on the HTML dashboard (which includes all of the obviously
meaningful fields from the Commit objects).

Change-Id: Ib0437bec276a78ca9efd57fcc16041e40ccd3d4c
Reviewed-on: https://go-review.googlesource.com/16632
Reviewed-by: Andrew Gerrand <adg@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Austin Clements 2015-11-04 10:16:59 -05:00
Родитель 83f9748046
Коммит cf97336113
2 изменённых файлов: 31 добавлений и 6 удалений

Просмотреть файл

@ -214,11 +214,10 @@ func jsonHandler(w http.ResponseWriter, r *http.Request, data *uiTemplateData) {
// First the commits from the main section (the "go" repo)
for _, c := range data.Commits {
rev := types.BuildRevision{
Repo: "go",
Revision: c.Hash,
Date: c.Time.Format(time.RFC3339),
Results: make([]string, len(data.Builders)),
Repo: "go",
Results: make([]string, len(data.Builders)),
}
commitToBuildRevision(c, &rev)
for i, b := range data.Builders {
rev.Results[i] = cell(c.Result(b, ""))
}
@ -232,11 +231,10 @@ func jsonHandler(w http.ResponseWriter, r *http.Request, data *uiTemplateData) {
goRev := ts.Tag.Hash
rev := types.BuildRevision{
Repo: pkgState.Package.Name,
Revision: pkgState.Commit.Hash,
GoRevision: goRev,
Date: pkgState.Commit.Time.Format(time.RFC3339),
Results: make([]string, len(data.Builders)),
}
commitToBuildRevision(pkgState.Commit, &rev)
for i, b := range res.Builders {
rev.Results[i] = cell(pkgState.Commit.Result(b, goRev))
}
@ -249,6 +247,18 @@ func jsonHandler(w http.ResponseWriter, r *http.Request, data *uiTemplateData) {
w.Write(v)
}
// commitToBuildRevision fills in the fields of BuildRevision rev that
// are derived from Commit c.
func commitToBuildRevision(c *Commit, rev *types.BuildRevision) {
rev.Revision = c.Hash
// TODO: A comment may have more than one parent.
rev.ParentRevisions = []string{c.ParentHash}
rev.Date = c.Time.Format(time.RFC3339)
rev.Branch = c.Branch
rev.Author = c.User
rev.Desc = c.Desc
}
type Pagination struct {
Next, Prev int
HasPrev bool

Просмотреть файл

@ -29,6 +29,10 @@ type BuildRevision struct {
// Revision is the full git hash of the repo.
Revision string `json:"revision"`
// ParentRevisions is the full git hashes of the parents of
// Revision.
ParentRevisions []string `json:"parentRevisions"`
// GoRevision is the full git hash of the "go" repo, if Repo is not "go" itself.
// Otherwise this is empty.
GoRevision string `json:"goRevision,omitempty"`
@ -36,6 +40,17 @@ type BuildRevision struct {
// Date is the commit date of this revision, formatted in RFC3339.
Date string `json:"date"`
// Branch is the branch of this commit, e.g. "master" or "dev.ssa".
Branch string `json:"branch"`
// Author is the author of this commit in standard git form
// "Name <email>".
Author string `json:"author"`
// Desc is the commit message of this commit. It may be
// truncated.
Desc string `json:"desc"`
// Results are the build results for each of the builders in
// the same length slice BuildStatus.Builders.
// Each string is either "" (if no data), "ok", or the URL to failure logs.