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

Side by Side Diff: go/src/infra/appengine/sheriff-o-matic/main.go

Issue 2058173003: [som] Add revision range exapansion. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: add tests Created 4 years, 6 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Package som implements HTTP server that handles requests to default module. 5 // Package som implements HTTP server that handles requests to default module.
6 package som 6 package som
7 7
8 import ( 8 import (
9 "crypto/sha1" 9 "crypto/sha1"
10 "encoding/json" 10 "encoding/json"
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 bytes, err := json.Marshal(res) 433 bytes, err := json.Marshal(res)
434 if err != nil { 434 if err != nil {
435 errStatus(w, http.StatusInternalServerError, err.Error()) 435 errStatus(w, http.StatusInternalServerError, err.Error())
436 return 436 return
437 } 437 }
438 438
439 w.Header().Set("Content-Type", "application/json") 439 w.Header().Set("Content-Type", "application/json")
440 w.Write(bytes) 440 w.Write(bytes)
441 } 441 }
442 442
443 func getCrRevJSON(c context.Context, pos string) (map[string]string, error) {
444 c = client.UseServiceAccountTransport(c, nil, nil)
445
446 hc := &http.Client{Transport: urlfetch.Get(c)}
447
448 resp, err := hc.Get(fmt.Sprintf("https://cr-rev.appspot.com/_ah/api/crre v/v1/redirect/%s", pos))
449 if err != nil {
450 return nil, err
451 }
452
453 defer resp.Body.Close()
454 body, err := ioutil.ReadAll(resp.Body)
455 if err != nil {
456 return nil, err
457 }
458
459 m := map[string]string{}
460 err = json.Unmarshal(body, &m)
461 if err != nil {
462 return nil, err
463 }
464
465 return m, nil
466 }
467
468 func getRevRangeHandler(c context.Context, w http.ResponseWriter, r *http.Reques t, p httprouter.Params) {
martiniss 2016/06/13 22:01:04 test me bro
seanmccullough1 2016/06/13 23:27:38 Done.
469 start := p.ByName("start")
martiniss 2016/06/13 22:01:03 check these?
seanmccullough1 2016/06/13 23:27:38 Done.
470 end := p.ByName("end")
471
472 startRev, err := getCrRevJSON(c, start)
473 if err != nil {
474 errStatus(w, http.StatusInternalServerError, err.Error())
475 return
476 }
477
478 endRev, err := getCrRevJSON(c, end)
479 if err != nil {
480 errStatus(w, http.StatusInternalServerError, err.Error())
481 return
482 }
483
484 // TODO(seanmccullough): some sanity checking of the rev json (same repo etc)
485
486 gitilesURL := fmt.Sprintf("https://chromium.googlesource.com/chromium/sr c/+log/%s^..%s?format=JSON",
487 startRev["git_sha"], endRev["git_sha"])
488
489 http.Redirect(w, r, gitilesURL, 301)
490 }
491
443 // base is the root of the middleware chain. 492 // base is the root of the middleware chain.
444 func base(h middleware.Handler) httprouter.Handle { 493 func base(h middleware.Handler) httprouter.Handle {
445 methods := auth.Authenticator{ 494 methods := auth.Authenticator{
446 &server.OAuth2Method{Scopes: []string{server.EmailScope}}, 495 &server.OAuth2Method{Scopes: []string{server.EmailScope}},
447 server.CookieAuth, 496 server.CookieAuth,
448 &server.InboundAppIDAuthMethod{}, 497 &server.InboundAppIDAuthMethod{},
449 } 498 }
450 h = auth.Use(h, methods) 499 h = auth.Use(h, methods)
451 if !appengine.IsDevAppServer() { 500 if !appengine.IsDevAppServer() {
452 h = middleware.WithPanicCatcher(h) 501 h = middleware.WithPanicCatcher(h)
453 } 502 }
454 return gaemiddleware.BaseProd(h) 503 return gaemiddleware.BaseProd(h)
455 } 504 }
456 505
457 //// Routes. 506 //// Routes.
458 func init() { 507 func init() {
459 settings.RegisterUIPage(settingsKey, settingsUIPage{}) 508 settings.RegisterUIPage(settingsKey, settingsUIPage{})
460 509
461 router := httprouter.New() 510 router := httprouter.New()
462 gaemiddleware.InstallHandlers(router, base) 511 gaemiddleware.InstallHandlers(router, base)
463 router.GET("/api/v1/trees/", base(auth.Authenticate(getTreesHandler))) 512 router.GET("/api/v1/trees/", base(auth.Authenticate(getTreesHandler)))
464 router.GET("/api/v1/alerts/:tree", base(auth.Authenticate(getAlertsHandl er))) 513 router.GET("/api/v1/alerts/:tree", base(auth.Authenticate(getAlertsHandl er)))
465 router.POST("/api/v1/alerts/:tree", base(auth.Authenticate(postAlertsHan dler))) 514 router.POST("/api/v1/alerts/:tree", base(auth.Authenticate(postAlertsHan dler)))
466 router.GET("/api/v1/annotations/", base(auth.Authenticate(getAnnotations Handler))) 515 router.GET("/api/v1/annotations/", base(auth.Authenticate(getAnnotations Handler)))
467 router.POST("/api/v1/annotations/:annKey/:action", base(auth.Authenticat e(postAnnotationsHandler))) 516 router.POST("/api/v1/annotations/:annKey/:action", base(auth.Authenticat e(postAnnotationsHandler)))
468 router.GET("/api/v1/bugqueue/:tree", base(auth.Authenticate(getBugQueueH andler))) 517 router.GET("/api/v1/bugqueue/:tree", base(auth.Authenticate(getBugQueueH andler)))
518 router.GET("/api/v1/revrange/:start/:end", base(auth.Authenticate(getRev RangeHandler)))
469 519
470 rootRouter := httprouter.New() 520 rootRouter := httprouter.New()
471 rootRouter.GET("/*path", base(auth.Authenticate(indexPage))) 521 rootRouter.GET("/*path", base(auth.Authenticate(indexPage)))
472 522
473 http.DefaultServeMux.Handle("/api/", router) 523 http.DefaultServeMux.Handle("/api/", router)
474 http.DefaultServeMux.Handle("/admin/", router) 524 http.DefaultServeMux.Handle("/admin/", router)
475 http.DefaultServeMux.Handle("/auth/", router) 525 http.DefaultServeMux.Handle("/auth/", router)
476 http.DefaultServeMux.Handle("/_ah/", router) 526 http.DefaultServeMux.Handle("/_ah/", router)
477 http.DefaultServeMux.Handle("/", rootRouter) 527 http.DefaultServeMux.Handle("/", rootRouter)
478 } 528 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698