| Index: go/src/infra/appengine/test-results/frontend/revision.go
|
| diff --git a/go/src/infra/appengine/test-results/frontend/revision.go b/go/src/infra/appengine/test-results/frontend/revision.go
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..1c3fe9ba1942535ef8c36870b894c8471b06714d
|
| --- /dev/null
|
| +++ b/go/src/infra/appengine/test-results/frontend/revision.go
|
| @@ -0,0 +1,84 @@
|
| +package frontend
|
| +
|
| +import (
|
| + "encoding/json"
|
| + "fmt"
|
| + "net/http"
|
| + "sync"
|
| +
|
| + "github.com/luci/gae/service/urlfetch"
|
| + "github.com/luci/luci-go/server/router"
|
| +)
|
| +
|
| +// TODO(estaab): Comment copied from python implementation:
|
| +// Get rid of this one crrev.com supports this directly.
|
| +// See http://crbug.com/407198.
|
| +
|
| +// crRevURL is the base URL of the Chromium Revision's API.
|
| +const crRevURL = "https://cr-rev.appspot.com/_ah/api/crrev/v1/redirect"
|
| +
|
| +type crRevClient struct {
|
| + HTTPClient *http.Client
|
| + BaseURL string
|
| +}
|
| +
|
| +// commitHash returns the commit hash for the supplied commit
|
| +// position.
|
| +func (c *crRevClient) commitHash(pos string) (string, error) {
|
| + resp, err := c.HTTPClient.Get(c.BaseURL + "/" + pos)
|
| + if err != nil {
|
| + return "", err
|
| + }
|
| + defer resp.Body.Close()
|
| +
|
| + if resp.StatusCode != http.StatusOK {
|
| + return "", fmt.Errorf("HTTP status code %d from %s", resp.StatusCode, resp.Request.URL)
|
| + }
|
| +
|
| + hash := struct {
|
| + Hash string `json:"git_sha"`
|
| + }{}
|
| + if err := json.NewDecoder(resp.Body).Decode(&hash); err != nil {
|
| + return "", err
|
| + }
|
| + return hash.Hash, nil
|
| +}
|
| +
|
| +func revisionHandler(c *router.Context) {
|
| + client := crRevClient{
|
| + HTTPClient: &http.Client{Transport: urlfetch.Get(c.Context)},
|
| + BaseURL: crRevURL,
|
| + }
|
| + type result struct {
|
| + hash string
|
| + err error
|
| + }
|
| + results := make([]result, 2)
|
| + wg := sync.WaitGroup{}
|
| + wg.Add(2)
|
| +
|
| + go func() {
|
| + defer wg.Done()
|
| + hash, err := client.commitHash(c.Request.FormValue("start"))
|
| + results[0] = result{hash, err}
|
| + }()
|
| + go func() {
|
| + defer wg.Done()
|
| + hash, err := client.commitHash(c.Request.FormValue("end"))
|
| + results[1] = result{hash, err}
|
| + }()
|
| +
|
| + wg.Wait()
|
| + for _, r := range results {
|
| + if r.err != nil {
|
| + http.Error(c.Writer, r.err.Error(), http.StatusInternalServerError)
|
| + return
|
| + }
|
| + }
|
| +
|
| + http.Redirect(c.Writer, c.Request, fmt.Sprintf(
|
| + "https://chromium.googlesource.com/chromium/src/+log/%s^..%s?pretty=fuller",
|
| + results[0].hash,
|
| + results[1].hash,
|
| + ), http.StatusMovedPermanently)
|
| +}
|
|
|