Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The LUCI Authors. All rights reserved. | |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 | |
| 3 // that can be found in the LICENSE file. | |
| 4 | |
| 5 package git | |
| 6 | |
| 7 import ( | |
| 8 "encoding/json" | |
| 9 "fmt" | |
| 10 "strings" | |
| 11 | |
| 12 "github.com/luci/luci-go/appengine/cmd/milo/resp" | |
| 13 "github.com/luci/luci-go/common/transport" | |
| 14 "golang.org/x/net/context" | |
| 15 ) | |
| 16 | |
| 17 type Repo struct { | |
| 18 Server string | |
| 19 Branch string | |
| 20 } | |
| 21 | |
| 22 type GerritCommit struct { | |
|
nodir
2016/08/03 20:26:18
this is Gitiles, not Gerrit
hinoka
2016/08/03 21:55:40
Done.
| |
| 23 Log []struct { | |
| 24 Commit string `json:"commit"` | |
| 25 Tree string `json:"tree"` | |
| 26 Parents []string `json:"parents"` | |
| 27 Author struct { | |
|
nodir
2016/08/03 20:26:18
consider defining a type so you don't copy-paste t
hinoka
2016/08/03 21:55:40
Done.
| |
| 28 Name string `json:"name"` | |
| 29 Email string `json:"email"` | |
| 30 Time string `json:"time"` | |
| 31 } `json:"author"` | |
| 32 Committer struct { | |
| 33 Name string `json:"name"` | |
| 34 Email string `json:"email"` | |
| 35 Time string `json:"time"` | |
| 36 } `json:"committer"` | |
| 37 Message string `json:"message"` | |
| 38 } `json:"log"` | |
| 39 Next string `json:"next"` | |
| 40 } | |
| 41 | |
| 42 func GetCommits(c context.Context, repo, treeish string) ([]resp.Commit, error) { | |
|
nodir
2016/08/03 20:26:18
repo looks like an URL (chromium.googlesource.com/
hinoka
2016/08/03 21:55:40
Done.
| |
| 43 URL := fmt.Sprintf("https://%s/+log/%s?format=JSON", repo, treeish) | |
|
nodir
2016/08/03 20:26:18
add /a/ in the beginning, so you get a bigger quot
hinoka
2016/08/03 21:55:40
Done. App is already whitelisted.
| |
| 44 client := transport.GetClient(c) | |
|
nodir
2016/08/03 20:26:18
this needs to be rebased
hinoka
2016/08/03 21:55:40
...?
| |
| 45 r, err := client.Get(URL) | |
| 46 if err != nil { | |
| 47 return nil, err | |
| 48 } | |
| 49 if r.StatusCode != 200 { | |
| 50 return nil, fmt.Errorf("Failed to fetch %s, status code %d", URL , r.StatusCode) | |
| 51 } | |
| 52 defer r.Body.Close() | |
| 53 trash := make([]byte, 4) | |
|
nodir
2016/08/03 20:26:18
at least add a comment what is the prefix
hinoka
2016/08/03 21:55:40
Done.
| |
| 54 r.Body.Read(trash) // Read the jsonp header | |
| 55 d := json.NewDecoder(r.Body) | |
|
nodir
2016/08/03 20:26:18
inline d
hinoka
2016/08/03 21:55:40
Done.
| |
| 56 cms := GerritCommit{} | |
|
nodir
2016/08/03 20:26:18
what cms stands for?
hinoka
2016/08/03 21:55:40
commits
| |
| 57 if err := d.Decode(&cms); err != nil { | |
| 58 return nil, err | |
| 59 } | |
| 60 // TODO(hinoka): Follow paging | |
| 61 | |
| 62 // Move things into our own datastructure. | |
| 63 result := make([]resp.Commit, len(cms.Log)) | |
| 64 for i, log := range cms.Log { | |
| 65 result[i] = resp.Commit{ | |
| 66 AuthorName: log.Author.Name, | |
| 67 AuthorEmail: log.Author.Email, | |
| 68 Repo: URL, | |
|
nodir
2016/08/03 20:26:18
URL is not a repo URL
I think you meant repoURL
hinoka
2016/08/03 21:55:40
Done.
| |
| 69 Revision: log.Commit, | |
| 70 Description: log.Message, | |
| 71 Title: strings.SplitN(log.Message, "\n", 2)[0], | |
| 72 // TODO(hinoka): The other stuff | |
| 73 } | |
| 74 } | |
| 75 return result, nil | |
| 76 } | |
| OLD | NEW |