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

Unified 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 side-by-side diff with in-line comments
Download patch
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 552f444cb87eecf782a3a3735200466a15d743d5..4ce3c3b2086baee7c9d7e6899881c6b28364fdba 100644
--- a/go/src/infra/appengine/sheriff-o-matic/main.go
+++ b/go/src/infra/appengine/sheriff-o-matic/main.go
@@ -440,6 +440,55 @@ func getBugQueueHandler(c context.Context, w http.ResponseWriter, r *http.Reques
w.Write(bytes)
}
+func getCrRevJSON(c context.Context, pos string) (map[string]string, error) {
+ c = client.UseServiceAccountTransport(c, nil, nil)
+
+ hc := &http.Client{Transport: urlfetch.Get(c)}
+
+ resp, err := hc.Get(fmt.Sprintf("https://cr-rev.appspot.com/_ah/api/crrev/v1/redirect/%s", pos))
+ if err != nil {
+ return nil, err
+ }
+
+ defer resp.Body.Close()
+ body, err := ioutil.ReadAll(resp.Body)
+ if err != nil {
+ return nil, err
+ }
+
+ m := map[string]string{}
+ err = json.Unmarshal(body, &m)
+ if err != nil {
+ return nil, err
+ }
+
+ return m, nil
+}
+
+func getRevRangeHandler(c context.Context, w http.ResponseWriter, r *http.Request, p httprouter.Params) {
martiniss 2016/06/13 22:01:04 test me bro
seanmccullough1 2016/06/13 23:27:38 Done.
+ start := p.ByName("start")
martiniss 2016/06/13 22:01:03 check these?
seanmccullough1 2016/06/13 23:27:38 Done.
+ end := p.ByName("end")
+
+ startRev, err := getCrRevJSON(c, start)
+ if err != nil {
+ errStatus(w, http.StatusInternalServerError, err.Error())
+ return
+ }
+
+ endRev, err := getCrRevJSON(c, end)
+ if err != nil {
+ errStatus(w, http.StatusInternalServerError, err.Error())
+ return
+ }
+
+ // TODO(seanmccullough): some sanity checking of the rev json (same repo etc)
+
+ gitilesURL := fmt.Sprintf("https://chromium.googlesource.com/chromium/src/+log/%s^..%s?format=JSON",
+ startRev["git_sha"], endRev["git_sha"])
+
+ http.Redirect(w, r, gitilesURL, 301)
+}
+
// base is the root of the middleware chain.
func base(h middleware.Handler) httprouter.Handle {
methods := auth.Authenticator{
@@ -466,6 +515,7 @@ func init() {
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)))
+ router.GET("/api/v1/revrange/:start/:end", base(auth.Authenticate(getRevRangeHandler)))
rootRouter := httprouter.New()
rootRouter.GET("/*path", base(auth.Authenticate(indexPage)))

Powered by Google App Engine
This is Rietveld 408576698