Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 // Copyright 2011 The Go Authors. All rights reserved. | 1 // Copyright 2011 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 // TODO(adg): packages at weekly/release | 5 // TODO(adg): packages at weekly/release |
6 // TODO(adg): some means to register new packages | 6 // TODO(adg): some means to register new packages |
7 | 7 |
8 package build | 8 package build |
9 | 9 |
10 import ( | 10 import ( |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
49 } | 49 } |
50 | 50 |
51 p := &Pagination{} | 51 p := &Pagination{} |
52 if len(commits) == commitsPerPage { | 52 if len(commits) == commitsPerPage { |
53 p.Next = page + 1 | 53 p.Next = page + 1 |
54 } | 54 } |
55 if page > 0 { | 55 if page > 0 { |
56 p.Prev = page - 1 | 56 p.Prev = page - 1 |
57 p.HasPrev = true | 57 p.HasPrev = true |
58 } | 58 } |
59 » err = uiTemplate.Execute(w, struct { | 59 » data := &uiTemplateData{commits, builders, tipState, p} |
rsc
2011/12/15 23:33:58
The fields get named types. The struct should hav
adg
2011/12/15 23:48:16
Done.
| |
60 » » Commits []*Commit | 60 » if err := uiTemplate.Execute(w, data); err != nil { |
61 » » Builders []string | |
62 » » TipState []*PackageState | |
63 » » Pagination *Pagination | |
64 » }{ | |
65 » » commits, builders, tipState, p, | |
66 » }) | |
67 » if err != nil { | |
68 logErr(w, r, err) | 61 logErr(w, r, err) |
69 } | 62 } |
70 } | 63 } |
71 | 64 |
72 type Pagination struct { | 65 type Pagination struct { |
73 Next, Prev int | 66 Next, Prev int |
74 HasPrev bool | 67 HasPrev bool |
75 } | 68 } |
76 | 69 |
77 // goCommits gets a slice of the latest Commits to the Go repository. | 70 // goCommits gets a slice of the latest Commits to the Go repository. |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
137 for _, r := range results { | 130 for _, r := range results { |
138 ok = ok && r.OK | 131 ok = ok && r.OK |
139 } | 132 } |
140 states = append(states, &PackageState{ | 133 states = append(states, &PackageState{ |
141 pkg, commit, results, ok, | 134 pkg, commit, results, ok, |
142 }) | 135 }) |
143 } | 136 } |
144 return states, nil | 137 return states, nil |
145 } | 138 } |
146 | 139 |
147 var uiTemplate = template.Must(template.New("ui").Funcs( | 140 type uiTemplateData struct { |
rsc
2011/12/15 23:33:58
how about
var uiTemplate = template.Must(
tem
adg
2011/12/15 23:48:16
Done.
| |
148 » template.FuncMap{ | 141 » Commits []*Commit |
149 » » "builderTitle": builderTitle, | 142 » Builders []string |
150 » » "timeString": timeString, | 143 » TipState []*PackageState |
rsc
2011/12/15 23:33:58
A better name might be datastoreTime
Of course, yo
adg
2011/12/15 23:48:16
Done.
| |
151 » » "shortHash": shortHash, | 144 » Pagination *Pagination |
152 » » "repoURL": repoURL, | 145 } |
153 » }).ParseFile("build/ui.html")) | 146 |
147 var uiTemplate = template.Must( | |
148 » template.New("ui"). | |
149 » » Funcs(template.FuncMap{ | |
150 » » » "builderTitle": builderTitle, | |
151 » » » "shortHash": shortHash, | |
152 » » » "repoURL": repoURL, | |
153 » » }). | |
154 » » ParseFile("build/ui.html"), | |
155 ) | |
154 | 156 |
155 // builderTitle formats "linux-amd64-foo" as "linux amd64 foo". | 157 // builderTitle formats "linux-amd64-foo" as "linux amd64 foo". |
156 func builderTitle(s string) string { | 158 func builderTitle(s string) string { |
157 return strings.Replace(s, "-", " ", -1) | 159 return strings.Replace(s, "-", " ", -1) |
158 } | 160 } |
159 | |
160 // timeString returns a datastore.Time in string form. | |
161 func timeString(t datastore.Time) string { return t.Time().String() } | |
162 | 161 |
163 // shortHash returns a the short version of a hash. | 162 // shortHash returns a the short version of a hash. |
164 func shortHash(hash string) string { | 163 func shortHash(hash string) string { |
165 if len(hash) > 12 { | 164 if len(hash) > 12 { |
166 hash = hash[:12] | 165 hash = hash[:12] |
167 } | 166 } |
168 return hash | 167 return hash |
169 } | 168 } |
170 | 169 |
171 // repoRe matches Google Code repositories and subrepositories (without paths). | 170 // repoRe matches Google Code repositories and subrepositories (without paths). |
172 var repoRe = regexp.MustCompile(`^code\.google\.com/p/([a-z0-9\-]+)(\.[a-z0-9\-] +)?$`) | 171 var repoRe = regexp.MustCompile(`^code\.google\.com/p/([a-z0-9\-]+)(\.[a-z0-9\-] +)?$`) |
173 | 172 |
174 // repoURL returns the URL of a change at a Google Code repository or subrepo. | 173 // repoURL returns the URL of a change at a Google Code repository or subrepo. |
175 func repoURL(hash, packagePath string) (string, os.Error) { | 174 func repoURL(hash, packagePath string) (string, os.Error) { |
176 if packagePath == "" { | 175 if packagePath == "" { |
177 return "https://code.google.com/p/go/source/detail?r=" + hash, n il | 176 return "https://code.google.com/p/go/source/detail?r=" + hash, n il |
178 } | 177 } |
179 m := repoRe.FindStringSubmatch(packagePath) | 178 m := repoRe.FindStringSubmatch(packagePath) |
180 if m == nil { | 179 if m == nil { |
181 return "", os.NewError("unrecognized package: " + packagePath) | 180 return "", os.NewError("unrecognized package: " + packagePath) |
182 } | 181 } |
183 url := "https://code.google.com/p/" + m[1] + "/source/detail?r=" + hash | 182 url := "https://code.google.com/p/" + m[1] + "/source/detail?r=" + hash |
184 if len(m) > 2 { | 183 if len(m) > 2 { |
185 url += "&repo=" + m[2][1:] | 184 url += "&repo=" + m[2][1:] |
186 } | 185 } |
187 return url, nil | 186 return url, nil |
188 } | 187 } |
LEFT | RIGHT |