diff --git a/webapp/api_handlers.go b/webapp/api_handlers.go index dedeb85256c..e0dc2d8922f 100644 --- a/webapp/api_handlers.go +++ b/webapp/api_handlers.go @@ -11,6 +11,7 @@ import ( "net/http" "net/url" "strconv" + "strings" "time" models "github.com/web-platform-tests/wpt.fyi/shared" @@ -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 { @@ -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) @@ -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...) } diff --git a/webapp/params.go b/webapp/params.go index de8469d7dcf..6c0f087fb2d 100644 --- a/webapp/params.go +++ b/webapp/params.go @@ -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 +} diff --git a/webapp/test_results_handler.go b/webapp/test_results_handler.go index f8469686dc0..ef7429c55d3 100644 --- a/webapp/test_results_handler.go +++ b/webapp/test_results_handler.go @@ -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)} } diff --git a/webapp/test_run_handler.go b/webapp/test_run_handler.go index a3f827fdb15..eec0fc779ce 100644 --- a/webapp/test_run_handler.go +++ b/webapp/test_run_handler.go @@ -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 {