Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(773)

Unified Diff: milo/appengine/settings/settings.go

Issue 2328733002: Milo: Add ?limit= support to builders (Closed)
Patch Set: Regenerate Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « milo/appengine/frontend/templates/buildbot/pages/builder.html ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: milo/appengine/settings/settings.go
diff --git a/milo/appengine/settings/settings.go b/milo/appengine/settings/settings.go
index 82148f8869a3ef93e69f2f92d3cdd43352368049..718f100b75ddc6f55d99ea21c8db0da17f7d4e9e 100644
--- a/milo/appengine/settings/settings.go
+++ b/milo/appengine/settings/settings.go
@@ -9,10 +9,12 @@ import (
"encoding/json"
"fmt"
"net/http"
+ "strconv"
ds "github.com/luci/gae/service/datastore"
"github.com/luci/luci-go/milo/api/resp"
"github.com/luci/luci-go/milo/appengine/model"
+ "github.com/luci/luci-go/milo/common/miloerror"
"github.com/luci/luci-go/server/auth"
"github.com/luci/luci-go/server/auth/identity"
"github.com/luci/luci-go/server/auth/xsrf"
@@ -149,3 +151,32 @@ func getSettings(c context.Context, r *http.Request) (*resp.Settings, error) {
return result, nil
}
+
+// GetLimit extracts the "limit", "numbuilds", or "num_builds" http param from
+// the request, or returns "-1" implying no limit was specified.
+func GetLimit(r *http.Request) (int, error) {
+ sLimit := r.FormValue("limit")
+ if sLimit == "" {
+ sLimit = r.FormValue("numbuilds")
+ if sLimit == "" {
+ sLimit = r.FormValue("num_builds")
+ if sLimit == "" {
+ return -1, nil
+ }
+ }
+ }
+ limit, err := strconv.Atoi(sLimit)
+ if err != nil {
+ return -1, &miloerror.Error{
+ Message: fmt.Sprintf("limit parameter value %q is not a number: %s", sLimit, err),
+ Code: http.StatusBadRequest,
+ }
+ }
+ if limit < 0 {
+ return -1, &miloerror.Error{
+ Message: fmt.Sprintf("limit parameter value %q is less than 0", sLimit),
+ Code: http.StatusBadRequest,
+ }
+ }
+ return limit, nil
+}
« no previous file with comments | « milo/appengine/frontend/templates/buildbot/pages/builder.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698