This repository has been archived by the owner on Nov 5, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
coverage_handlers.go
98 lines (87 loc) · 2.48 KB
/
coverage_handlers.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package main
import (
"github.com/datatogether/api/apiutil"
"github.com/datatogether/core"
"github.com/datatogether/coverage/coverage"
"github.com/datatogether/coverage/tree"
"net"
"net/http"
"net/rpc"
"strings"
)
func CoverageHandler(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case "OPTIONS":
EmptyOkHandler(w, r)
case "GET":
CoverageTreeHandler(w, r)
default:
NotFoundHandler(w, r)
}
}
func CoverageTreeHandler(w http.ResponseWriter, r *http.Request) {
var primer *core.Primer
patterns := strings.Split(r.FormValue("patterns"), ",")
if r.FormValue("primer") != "" {
primer = &core.Primer{Id: r.FormValue("primer")}
if err := primer.Read(store); err != nil {
apiutil.WriteErrResponse(w, http.StatusBadRequest, err)
return
}
if err := primer.ReadSources(appDB); err != nil {
apiutil.WriteErrResponse(w, http.StatusBadRequest, err)
return
}
patterns = make([]string, len(primer.Sources))
for i, s := range primer.Sources {
patterns[i] = s.Url
}
}
conn, err := net.Dial("tcp", cfg.CoverageServiceUrl)
if err != nil {
apiutil.WriteErrResponse(w, http.StatusInternalServerError, err)
return
}
cli := rpc.NewClient(conn)
p := coverage.CoverageTreeParams{
Root: r.FormValue("root"),
Patterns: patterns,
// Depth: depth,
// RepoIds: strings.Split(r.FormValue("repositories"), ","),
}
if depth, err := apiutil.ReqParamInt("depth", r); err == nil {
p.Depth = depth
}
// if r.FormValue("patterns") != "" {
// args.Patterns = strings.Split(r.FormValue("patterns"), ",")
// }
if r.FormValue("repos") != "" {
p.RepoIds = strings.Split(r.FormValue("repos"), ",")
}
reply := &tree.Node{}
if err := cli.Call("CoverageRequests.Tree", p, reply); err != nil {
apiutil.WriteErrResponse(w, http.StatusInternalServerError, err)
return
}
if primer != nil {
reply.Name = primer.Title
}
apiutil.WriteResponse(w, reply)
}
// func CoverageSummaryHandler(w http.ResponseWriter, r *http.Request) {
// conn, err := net.Dial("tcp", cfg.CoverageServiceUrl)
// if err != nil {
// apiutil.WriteErrResponse(w, http.StatusInternalServerError, err)
// return
// }
// cli := rpc.NewClient(conn)
// p := coverage.CoverageSummaryParams{
// Patterns: strings.Split(r.FormValue("patterns"), ","),
// }
// reply := &coverage.Summary{}
// if err := cli.Call("CoverageRequests.Summary", p, reply); err != nil {
// apiutil.WriteErrResponse(w, http.StatusInternalServerError, err)
// return
// }
// apiutil.WriteResponse(w, reply)
// }