-
Notifications
You must be signed in to change notification settings - Fork 89
/
test_runs_handler.go
59 lines (50 loc) · 1.5 KB
/
test_runs_handler.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
// Copyright 2017 The WPT Dashboard Project. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package webapp
import (
"net/http"
"time"
"github.com/web-platform-tests/wpt.fyi/shared"
)
// testRunsHandler handles GET/POST requests to /test-runs
func testRunsHandler(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet {
http.Error(w, "Only GET is supported.", http.StatusMethodNotAllowed)
return
}
filter, err := parseTestRunsUIFilter(r)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
RenderTemplate(w, r, "test-runs.html", filter)
}
// parseTestRunsUIFilter parses the standard TestRunFilter, as well as the extra
// pr param.
func parseTestRunsUIFilter(r *http.Request) (filter testRunUIFilter, err error) {
q := r.URL.Query()
testRunFilter, err := shared.ParseTestRunFilterParams(q)
if err != nil {
return filter, err
}
pr, err := shared.ParsePRParam(q)
if err != nil {
return filter, err
}
isDefault := testRunFilter.IsDefaultQuery() && pr == nil
if isDefault {
// Get runs from a week ago, onward, by default.
aWeekAgo := time.Now().Truncate(time.Hour*24).AddDate(0, 0, -7)
testRunFilter.From = &aWeekAgo
testRunFilter = testRunFilter.MasterOnly()
} else if testRunFilter.MaxCount == nil {
oneHundred := 100
testRunFilter.MaxCount = &oneHundred
}
filter = convertTestRunUIFilter(testRunFilter)
if pr != nil {
filter.PR = pr
}
return filter, nil
}