Skip to content

Commit

Permalink
Fake-support the label=unstable param
Browse files Browse the repository at this point in the history
  • Loading branch information
lukebjerring committed Apr 24, 2018
1 parent 4179ddd commit 7b7c471
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 1 deletion.
12 changes: 12 additions & 0 deletions webapp/api_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"net/http"
"net/url"
"strconv"
"strings"
"time"

models "github.com/web-platform-tests/wpt.fyi/shared"
Expand Down Expand Up @@ -48,6 +49,9 @@ func apiTestRunsHandler(w http.ResponseWriter, r *http.Request) {
return
}

labels := ParseLabelsParam(r)
unstable := labels != nil && labels.Contains("unstable")

var testRuns []models.TestRun
var limit int
if limit, err = ParseMaxCountParam(r); err != nil {
Expand All @@ -61,6 +65,9 @@ func apiTestRunsHandler(w http.ResponseWriter, r *http.Request) {

for _, browserName := range browserNames {
var testRunResults []models.TestRun
if unstable {
browserName = browserName + "-experimental"
}
query := baseQuery.Filter("BrowserName =", browserName)
if runSHA != "" && runSHA != "latest" {
query = query.Filter("Revision =", runSHA)
Expand All @@ -69,6 +76,11 @@ func apiTestRunsHandler(w http.ResponseWriter, r *http.Request) {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
if unstable {
for i := range testRunResults {
testRunResults[i].BrowserName = strings.Replace(testRunResults[i].BrowserName, "-experimental", "", 1)
}
}
testRuns = append(testRuns, testRunResults...)
}

Expand Down
27 changes: 27 additions & 0 deletions webapp/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,3 +190,30 @@ func ParsePathsParam(r *http.Request) (paths mapset.Set) {
}
return paths
}

// ParseLabelsParam returns a set list of test-run labels to include, or nil if
// no labels are provided.
func ParseLabelsParam(r *http.Request) (labels mapset.Set) {
labelParams := r.URL.Query()["label"]
labelsParam := r.URL.Query().Get("labels")
if len(labelParams) == 0 && labelsParam == "" {
return nil
}

labels = mapset.NewSet()
for _, label := range labelParams {
labels.Add(label)
}
if labelsParam != "" {
for _, label := range strings.Split(labelsParam, ",") {
labels.Add(label)
}
}
if labels.Contains("") {
labels.Remove("")
}
if labels.Cardinality() == 0 {
return nil
}
return labels
}
8 changes: 7 additions & 1 deletion webapp/test_results_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,13 @@ func getTestRunsAndSources(r *http.Request, runSHA string) (testRunSources []str
testRunSources = append(testRunSources, fmt.Sprintf(singleRunURL, afterSpec.Revision, afterSpec.Platform))
}
} else {
const sourceURL = `/api/runs?sha=%s`
var sourceURL = `/api/runs?sha=%s`
labels := ParseLabelsParam(r)
if labels != nil {
for label := range labels.Iterator().C {
sourceURL = sourceURL + "&label=" + label.(string)
}
}
testRunSources = []string{fmt.Sprintf(sourceURL, runSHA)}
}

Expand Down
7 changes: 7 additions & 0 deletions webapp/test_run_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ func handleTestRunGet(w http.ResponseWriter, r *http.Request) {
}
sourceURL := fmt.Sprintf(`/api/runs?max-count=%d`, maxCount)

labels := ParseLabelsParam(r)
if labels != nil {
for label := range labels.Iterator().C {
sourceURL = sourceURL + "&label=" + label.(string)
}
}

// Serialize the data + pipe through the test-runs.html template.
testRunSourcesBytes, err := json.Marshal([]string{sourceURL})
if err != nil {
Expand Down

0 comments on commit 7b7c471

Please sign in to comment.