Chromium Code Reviews| Index: go/src/infra/appengine/sheriff-o-matic/main.go |
| diff --git a/go/src/infra/appengine/sheriff-o-matic/main.go b/go/src/infra/appengine/sheriff-o-matic/main.go |
| index f331585cd3ce0fb3bff908d62a1427a8ac27eae4..34d848514f0db5a4f584d154b0e1044770ed6d93 100644 |
| --- a/go/src/infra/appengine/sheriff-o-matic/main.go |
| +++ b/go/src/infra/appengine/sheriff-o-matic/main.go |
| @@ -10,6 +10,7 @@ import ( |
| "encoding/json" |
| "fmt" |
| "html/template" |
| + "infra/monorail" |
| "io/ioutil" |
| "net/http" |
| "strings" |
| @@ -17,6 +18,7 @@ import ( |
| "github.com/julienschmidt/httprouter" |
| "golang.org/x/net/context" |
| "google.golang.org/appengine" |
| + "google.golang.org/appengine/urlfetch" |
|
martiniss
2016/06/09 18:36:07
You should use https://godoc.org/github.com/luci/l
seanmccullough1
2016/06/09 19:02:57
Done.
|
| "github.com/luci/gae/service/datastore" |
| "github.com/luci/luci-go/appengine/gaeauth/server" |
| @@ -34,6 +36,8 @@ const authGroup = "sheriff-o-matic-access" |
| var ( |
| mainPage = template.Must(template.ParseFiles("./index.html")) |
| accessDeniedPage = template.Must(template.ParseFiles("./access-denied.html")) |
| + // Set to "http://localhost:9090/_ah/api/monorail/v1/" to debug locally. |
| + monorailEndpoint = "https://monorail-prod.appspot.com/_ah/api/monorail/v1/" |
| ) |
| var errStatus = func(w http.ResponseWriter, status int, msg string) { |
| @@ -369,6 +373,32 @@ func postAnnotationsHandler(c context.Context, w http.ResponseWriter, r *http.Re |
| w.Write(data) |
| } |
| +func getBugQueueHandler(c context.Context, w http.ResponseWriter, r *http.Request, p httprouter.Params) { |
| + c = appengine.NewContext(r) |
| + mr := monorail.NewEndpointsClient(urlfetch.Client(c), monorailEndpoint) |
| + tree := p.ByName("tree") |
| + req := &monorail.IssuesListRequest{ |
| + ProjectId: tree, |
| + Can: monorail.IssuesListRequest_OPEN, |
| + Q: fmt.Sprintf("label:Sheriff-%s", tree), |
| + } |
| + |
| + res, err := mr.IssuesList(c, req) |
| + if err != nil { |
| + errStatus(w, http.StatusInternalServerError, err.Error()) |
| + return |
| + } |
| + |
| + bytes, err := json.Marshal(res) |
| + if err != nil { |
| + errStatus(w, http.StatusInternalServerError, err.Error()) |
| + return |
| + } |
| + |
| + w.Header().Set("Content-Type", "application/json") |
| + w.Write(bytes) |
| +} |
| + |
| // base is the root of the middleware chain. |
| func base(h middleware.Handler) httprouter.Handle { |
| methods := auth.Authenticator{ |
| @@ -394,6 +424,7 @@ func init() { |
| router.POST("/api/v1/alerts/:tree", base(auth.Authenticate(postAlertsHandler))) |
| router.GET("/api/v1/annotations/", base(auth.Authenticate(getAnnotationsHandler))) |
| router.POST("/api/v1/annotations/:annKey/:action", base(auth.Authenticate(postAnnotationsHandler))) |
| + router.GET("/api/v1/bugqueue/:tree", base(auth.Authenticate(getBugQueueHandler))) |
| rootRouter := httprouter.New() |
| rootRouter.GET("/*path", base(auth.Authenticate(indexPage))) |