/
repository.go
49 lines (42 loc) · 994 Bytes
/
repository.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
package handlers
import (
"net/http"
visualizer "github.com/jenkins-x/jx-pipelines-visualizer"
"github.com/gorilla/mux"
"github.com/sirupsen/logrus"
"github.com/unrolled/render"
)
type RepositoryHandler struct {
Store *visualizer.Store
Render *render.Render
Logger *logrus.Logger
}
func (h *RepositoryHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
owner := vars["owner"]
repository := vars["repo"]
pipelines, err := h.Store.Query(visualizer.Query{
Owner: owner,
Repository: repository,
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
Query string
Pipelines *visualizer.Pipelines
}{
owner,
repository,
r.URL.Query().Get("q"),
pipelines,
})
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}