maintner/maintnerd/maintapi: validate page size in mixed mode

Return an error if the requested page size is too small to accommodate
all the branches.

For golang/go#48523.

Change-Id: I8515495a06a8c5890c1ec8e829fe983957d69532
Reviewed-on: https://go-review.googlesource.com/c/build/+/431356
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
diff --git a/maintner/maintnerd/maintapi/api.go b/maintner/maintnerd/maintapi/api.go
index 7953841..c011963 100644
--- a/maintner/maintnerd/maintapi/api.go
+++ b/maintner/maintnerd/maintapi/api.go
@@ -632,6 +632,9 @@
 			commitsPerPage = 30 // what build.golang.org historically used
 		}
 	}
+	if mixBranches && commitsPerPage < len(res.Branches) {
+		return nil, grpc.Errorf(codes.InvalidArgument, "page size too small for `mixed`: %v < %v", commitsPerPage, len(res.Branches))
+	}
 
 	if req.Page < 0 {
 		return nil, grpc.Errorf(codes.InvalidArgument, "invalid page")