forked from Luzifer/gobuilder
/
buildlog.go
47 lines (39 loc) · 1011 Bytes
/
buildlog.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main
import (
"fmt"
"net/http"
"strings"
"github.com/flosch/pongo2"
"github.com/gorilla/mux"
)
func handlerBuildLog(res http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
file, err := redisClient.Get(fmt.Sprintf("project::%s::logs::%s", params["repo"], params["logid"]))
if err != nil {
file = []byte("No build log was found for this build.")
}
template := pongo2.Must(pongo2.FromFile("frontend/buildlog.html"))
ctx := getBasicContext(res, r)
ctx["repo"] = params["repo"]
ctx["log"] = logHighlight(file)
template.ExecuteWriter(ctx, res)
}
type logline struct {
Line string
BuildComment bool
}
func logHighlight(log []byte) []logline {
lines := strings.Split(string(log), "\n")
highlightedLines := []logline{}
for _, line := range lines {
tmp := logline{
Line: line,
BuildComment: false,
}
if strings.HasPrefix(line, "[") {
tmp.BuildComment = true
}
highlightedLines = append(highlightedLines, tmp)
}
return highlightedLines
}