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

Side by Side Diff: go/src/infra/appengine/test-results/frontend/revision.go

Issue 2255433003: test-results: Add revisions handler (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Use c.BaseURL, not crRevURL always Created 4 years, 4 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
(Empty)
1 package frontend
2
3 import (
4 "encoding/json"
5 "fmt"
6 "net/http"
7 "sync"
8
9 "github.com/luci/gae/service/urlfetch"
10 "github.com/luci/luci-go/server/router"
11 )
12
13 // TODO(estaab): Comment copied from python implementation:
14 // Get rid of this one crrev.com supports this directly.
15 // See http://crbug.com/407198.
16
17 // crRevURL is the base URL of the Chromium Revision's API.
18 const crRevURL = "https://cr-rev.appspot.com/_ah/api/crrev/v1/redirect"
19
20 type crRevClient struct {
21 HTTPClient *http.Client
22 BaseURL string
23 }
24
25 // commitHash returns the commit hash for the supplied commit
26 // position.
27 func (c *crRevClient) commitHash(pos string) (string, error) {
28 resp, err := c.HTTPClient.Get(c.BaseURL + "/" + pos)
29 if err != nil {
30 return "", err
31 }
32 defer resp.Body.Close()
33
34 if resp.StatusCode != http.StatusOK {
35 return "", fmt.Errorf("HTTP status code %d from %s", resp.Status Code, resp.Request.URL)
36 }
37
38 hash := struct {
39 Hash string `json:"git_sha"`
40 }{}
41 if err := json.NewDecoder(resp.Body).Decode(&hash); err != nil {
42 return "", err
43 }
44 return hash.Hash, nil
45 }
46
47 func revisionHandler(c *router.Context) {
48 client := crRevClient{
49 HTTPClient: &http.Client{Transport: urlfetch.Get(c.Context)},
50 BaseURL: crRevURL,
51 }
52 type result struct {
53 hash string
54 err error
55 }
56 results := make([]result, 2)
57 wg := sync.WaitGroup{}
58 wg.Add(2)
59
60 go func() {
61 defer wg.Done()
62 hash, err := client.commitHash(c.Request.FormValue("start"))
63 results[0] = result{hash, err}
64 }()
65 go func() {
66 defer wg.Done()
67 hash, err := client.commitHash(c.Request.FormValue("end"))
68 results[1] = result{hash, err}
69 }()
70
71 wg.Wait()
72 for _, r := range results {
73 if r.err != nil {
74 http.Error(c.Writer, r.err.Error(), http.StatusInternalS erverError)
75 return
76 }
77 }
78
79 http.Redirect(c.Writer, c.Request, fmt.Sprintf(
80 "https://chromium.googlesource.com/chromium/src/+log/%s^..%s?pre tty=fuller",
81 results[0].hash,
82 results[1].hash,
83 ), http.StatusMovedPermanently)
84 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698