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 3
/
coverage_handlers.go
104 lines (89 loc) · 2.42 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
99
100
101
102
103
104
package main
import (
"github.com/datatogether/api/apiutil"
"github.com/datatogether/coverage/coverage"
"github.com/datatogether/coverage/tree"
"net/http"
"strconv"
"strings"
)
// Concrete CoverateRequests instance
var CoverageRequests = new(coverage.CoverageRequests)
func CoverageHandler(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case "OPTIONS":
EmptyOkHandler(w, r)
case "GET":
CoverageSummaryHandler(w, r)
default:
NotFoundHandler(w, r)
}
}
func CoverageSummaryHandler(w http.ResponseWriter, r *http.Request) {
args := &coverage.CoverageSummaryParams{
Patterns: strings.Split(r.FormValue("patterns"), ","),
RepoIds: strings.Split(r.FormValue("repos"), ","),
}
res := &coverage.Summary{}
err := CoverageRequests.Summary(args, res)
if err != nil {
log.Info(err.Error())
apiutil.WriteErrResponse(w, http.StatusInternalServerError, err)
return
}
apiutil.WriteResponse(w, res)
}
func CoverageTreeHandler(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case "OPTIONS":
EmptyOkHandler(w, r)
case "GET":
GetCoverageTreeHandler(w, r)
default:
NotFoundHandler(w, r)
}
}
func GetCoverageTreeHandler(w http.ResponseWriter, r *http.Request) {
args := &coverage.CoverageTreeParams{
Root: r.FormValue("root"),
Depth: 0,
}
if depth, err := strconv.ParseInt(r.FormValue("depth"), 10, 0); err == nil {
args.Depth = int(depth)
}
if r.FormValue("patterns") != "" {
args.Patterns = strings.Split(r.FormValue("patterns"), ",")
}
if r.FormValue("repos") != "" {
args.RepoIds = strings.Split(r.FormValue("repos"), ",")
}
res := &tree.Node{}
err := CoverageRequests.Tree(args, res)
if err != nil {
log.Info(err.Error())
apiutil.WriteErrResponse(w, http.StatusInternalServerError, err)
return
}
apiutil.WriteResponse(w, res)
}
func DownloadCoverageTreeHandler(w http.ResponseWriter, r *http.Request) {
// u := &archive.Url{Id: r.URL.Path[len("/urls/"):]}
// if err := u.Read(appDB); err != nil {
// w.WriteHeader(http.StatusNotFound)
// io.WriteString(w, err.Error())
// return
// }
// f, err := u.File()
// if err != nil {
// w.WriteHeader(http.StatusNotFound)
// io.WriteString(w, err.Error())
// return
// }
// if err := f.GetS3(); err != nil {
// w.WriteHeader(http.StatusNotFound)
// io.WriteString(w, err.Error())
// return
// }
// w.Header().Set("Content-Disposition", fmt.Sprintf(`inline; filename="%s"`, u.FileName))
// w.Write(f.Data)
}