/
branch.go
57 lines (50 loc) · 1.13 KB
/
branch.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
48
49
50
51
52
53
54
55
56
57
package handlers
import (
"net/http"
"strings"
visualizer "github.com/jenkins-x/jx-pipelines-visualizer"
"github.com/gorilla/mux"
"github.com/sirupsen/logrus"
"github.com/unrolled/render"
)
type BranchHandler struct {
Store *visualizer.Store
Render *render.Render
Logger *logrus.Logger
}
func (h *BranchHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
owner := vars["owner"]
repository := vars["repo"]
branch := vars["branch"]
if strings.HasPrefix(branch, "pr-") {
branch = strings.ToUpper(branch)
}
pipelines, err := h.Store.Query(visualizer.Query{
Owner: owner,
Repository: repository,
Branch: branch,
Query: r.URL.Query().Get("q"),
})
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
err = h.Render.HTML(w, http.StatusOK, "home", struct {
Owner string
Repository string
Branch string
Query string
Pipelines *visualizer.Pipelines
}{
owner,
repository,
branch,
r.URL.Query().Get("q"),
pipelines,
})
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}