| OLD | NEW |
| 1 // Copyright 2016 The LUCI Authors. | 1 // Copyright 2016 The LUCI Authors. |
| 2 // | 2 // |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
| 5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
| 6 // | 6 // |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 // | 8 // |
| 9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 // See the License for the specific language governing permissions and | 12 // See the License for the specific language governing permissions and |
| 13 // limitations under the License. | 13 // limitations under the License. |
| 14 | 14 |
| 15 package gitiles | 15 package gitiles |
| 16 | 16 |
| 17 // TODO(tandrii): add tests. | 17 // TODO(tandrii): add tests. |
| 18 | 18 |
| 19 import ( | 19 import ( |
| 20 "encoding/json" | 20 "encoding/json" |
| 21 "fmt" | 21 "fmt" |
| 22 "net/http" | 22 "net/http" |
| 23 "net/url" | 23 "net/url" |
| 24 "strings" | 24 "strings" |
| 25 "time" |
| 25 | 26 |
| 26 "github.com/luci/luci-go/server/auth" | 27 "github.com/luci/luci-go/server/auth" |
| 27 "golang.org/x/net/context" | 28 "golang.org/x/net/context" |
| 28 ) | 29 ) |
| 29 | 30 |
| 30 // User is the author or the committer returned from gitiles. | 31 // User is the author or the committer returned from gitiles. |
| 31 type User struct { | 32 type User struct { |
| 32 Name string `json:"name"` | 33 Name string `json:"name"` |
| 33 Email string `json:"email"` | 34 Email string `json:"email"` |
| 34 Time string `json:"time"` | 35 Time string `json:"time"` |
| 35 } | 36 } |
| 36 | 37 |
| 38 // GetTime returns the Time field as real data! |
| 39 func (u *User) GetTime() (time.Time, error) { |
| 40 return time.Parse(time.ANSIC, u.Time) |
| 41 } |
| 42 |
| 37 // Commit is the information of a commit returned from gitiles. | 43 // Commit is the information of a commit returned from gitiles. |
| 38 type Commit struct { | 44 type Commit struct { |
| 39 Commit string `json:"commit"` | 45 Commit string `json:"commit"` |
| 40 Tree string `json:"tree"` | 46 Tree string `json:"tree"` |
| 41 Parents []string `json:"parents"` | 47 Parents []string `json:"parents"` |
| 42 Author User `json:"author"` | 48 Author User `json:"author"` |
| 43 Committer User `json:"committer"` | 49 Committer User `json:"committer"` |
| 44 Message string `json:"message"` | 50 Message string `json:"message"` |
| 45 } | 51 } |
| 46 | 52 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 trash := make([]byte, 4) | 101 trash := make([]byte, 4) |
| 96 r.Body.Read(trash) // Read the jsonp header | 102 r.Body.Read(trash) // Read the jsonp header |
| 97 commits := LogResponse{} | 103 commits := LogResponse{} |
| 98 if err := json.NewDecoder(r.Body).Decode(&commits); err != nil { | 104 if err := json.NewDecoder(r.Body).Decode(&commits); err != nil { |
| 99 return nil, err | 105 return nil, err |
| 100 } | 106 } |
| 101 // TODO(hinoka): If there is a page and we have gotten less than the lim
it, | 107 // TODO(hinoka): If there is a page and we have gotten less than the lim
it, |
| 102 // keep making requests for the next page until we have enough commits. | 108 // keep making requests for the next page until we have enough commits. |
| 103 return commits.Log, nil | 109 return commits.Log, nil |
| 104 } | 110 } |
| OLD | NEW |