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

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: no-message:) 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) {
469 start := p.ByName("start")
470 end := p.ByName("end")
471 if start == "" || end == "" {
472 errStatus(w, http.StatusBadRequest, "Start and end parameters mu st be set.")
473 return
474 }
475
476 startRev, err := getCrRevJSON(c, start)
477 if err != nil {
478 errStatus(w, http.StatusInternalServerError, err.Error())
479 return
480 }
481
482 endRev, err := getCrRevJSON(c, end)
483 if err != nil {
484 errStatus(w, http.StatusInternalServerError, err.Error())
485 return
486 }
487
488 // TODO(seanmccullough): some sanity checking of the rev json (same repo etc)
489
490 gitilesURL := fmt.Sprintf("https://chromium.googlesource.com/chromium/sr c/+log/%s^..%s?format=JSON",
491 startRev["git_sha"], endRev["git_sha"])
492
493 http.Redirect(w, r, gitilesURL, 301)
494 }
495
443 // base is the root of the middleware chain. 496 // base is the root of the middleware chain.
444 func base(h middleware.Handler) httprouter.Handle { 497 func base(h middleware.Handler) httprouter.Handle {
445 methods := auth.Authenticator{ 498 methods := auth.Authenticator{
446 &server.OAuth2Method{Scopes: []string{server.EmailScope}}, 499 &server.OAuth2Method{Scopes: []string{server.EmailScope}},
447 server.CookieAuth, 500 server.CookieAuth,
448 &server.InboundAppIDAuthMethod{}, 501 &server.InboundAppIDAuthMethod{},
449 } 502 }
450 h = auth.Use(h, methods) 503 h = auth.Use(h, methods)
451 if !appengine.IsDevAppServer() { 504 if !appengine.IsDevAppServer() {
452 h = middleware.WithPanicCatcher(h) 505 h = middleware.WithPanicCatcher(h)
453 } 506 }
454 return gaemiddleware.BaseProd(h) 507 return gaemiddleware.BaseProd(h)
455 } 508 }
456 509
457 //// Routes. 510 //// Routes.
458 func init() { 511 func init() {
459 settings.RegisterUIPage(settingsKey, settingsUIPage{}) 512 settings.RegisterUIPage(settingsKey, settingsUIPage{})
460 513
461 router := httprouter.New() 514 router := httprouter.New()
462 gaemiddleware.InstallHandlers(router, base) 515 gaemiddleware.InstallHandlers(router, base)
463 router.GET("/api/v1/trees/", base(auth.Authenticate(getTreesHandler))) 516 router.GET("/api/v1/trees/", base(auth.Authenticate(getTreesHandler)))
464 router.GET("/api/v1/alerts/:tree", base(auth.Authenticate(getAlertsHandl er))) 517 router.GET("/api/v1/alerts/:tree", base(auth.Authenticate(getAlertsHandl er)))
465 router.POST("/api/v1/alerts/:tree", base(auth.Authenticate(postAlertsHan dler))) 518 router.POST("/api/v1/alerts/:tree", base(auth.Authenticate(postAlertsHan dler)))
466 router.GET("/api/v1/annotations/", base(auth.Authenticate(getAnnotations Handler))) 519 router.GET("/api/v1/annotations/", base(auth.Authenticate(getAnnotations Handler)))
467 router.POST("/api/v1/annotations/:annKey/:action", base(auth.Authenticat e(postAnnotationsHandler))) 520 router.POST("/api/v1/annotations/:annKey/:action", base(auth.Authenticat e(postAnnotationsHandler)))
468 router.GET("/api/v1/bugqueue/:tree", base(auth.Authenticate(getBugQueueH andler))) 521 router.GET("/api/v1/bugqueue/:tree", base(auth.Authenticate(getBugQueueH andler)))
522 router.GET("/api/v1/revrange/:start/:end", base(getRevRangeHandler))
469 523
470 rootRouter := httprouter.New() 524 rootRouter := httprouter.New()
471 rootRouter.GET("/*path", base(auth.Authenticate(indexPage))) 525 rootRouter.GET("/*path", base(auth.Authenticate(indexPage)))
472 526
473 http.DefaultServeMux.Handle("/api/", router) 527 http.DefaultServeMux.Handle("/api/", router)
474 http.DefaultServeMux.Handle("/admin/", router) 528 http.DefaultServeMux.Handle("/admin/", router)
475 http.DefaultServeMux.Handle("/auth/", router) 529 http.DefaultServeMux.Handle("/auth/", router)
476 http.DefaultServeMux.Handle("/_ah/", router) 530 http.DefaultServeMux.Handle("/_ah/", router)
477 http.DefaultServeMux.Handle("/", rootRouter) 531 http.DefaultServeMux.Handle("/", rootRouter)
478 } 532 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698