Commit f1c8e1c5 authored by Quentin Smith's avatar Quentin Smith

analysis: linkify labels when possible

Change-Id: I18ee1d1eab704c628dd476ee3aa7dc90e729106d
Reviewed-on: https://go-review.googlesource.com/43053
Run-TryBot: Quentin Smith <quentin@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent b74b4574
......@@ -133,6 +133,25 @@ func addToQuery(query, add string) string {
return add + " | " + query
}
// linkify returns a link related to the label's value. If no such link exists, it returns an empty string.
// For example, "cl: 1234" is linked to golang.org/cl/1234.
// string is used as the return type and not template.URL so that html/template will validate the scheme.
func linkify(labels benchfmt.Labels, label string) string {
switch label {
case "cl", "commit":
return "https://golang.org/cl/" + template.URLQueryEscaper(labels[label])
case "ps":
// TODO(quentin): Figure out how to link to a particular patch set on Gerrit.
return ""
case "repo":
return labels["repo"]
case "try":
// TODO(quentin): Return link to farmer once farmer has permalinks.
return ""
}
return ""
}
// compare handles queries that require comparison of the groups in the query.
func (a *App) compare(w http.ResponseWriter, r *http.Request) {
ctx := requestContext(r)
......@@ -152,6 +171,7 @@ func (a *App) compare(w http.ResponseWriter, r *http.Request) {
t, err := template.New("main").Funcs(template.FuncMap{
"addToQuery": addToQuery,
"linkify": linkify,
}).Parse(string(tmpl))
if err != nil {
http.Error(w, err.Error(), 500)
......
......@@ -103,14 +103,14 @@ td.count {
<p>{{.}}</p>
{{else}}
<table id="labels">
{{with .CommonLabels}}
{{with $cl := .CommonLabels}}
<tbody>
<tr>
<th>label</th><th>common value</th>
</tr>
{{range $label, $value := .}}
<tr>
<th class="label">{{$label}}</th><td>{{$value}}</td>
<th class="label">{{$label}}</th><td>{{with $href := linkify $cl $label}}<a href="{{$href}}" rel="nofollow">{{$value}}</a>{{else}}{{$value}}{{end}}</td>
</tr>
{{end}}
</tbody>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment