OLD | NEW |
1 package rietveld | 1 package rietveld |
2 | 2 |
3 import ( | 3 import ( |
4 "encoding/json" | 4 "encoding/json" |
5 "fmt" | 5 "fmt" |
6 "io/ioutil" | 6 "io/ioutil" |
7 "net/http" | 7 "net/http" |
8 "net/url" | 8 "net/url" |
9 "regexp" | 9 "regexp" |
10 "sort" | 10 "sort" |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 url: url, | 76 url: url, |
77 client: client, | 77 client: client, |
78 } | 78 } |
79 } | 79 } |
80 | 80 |
81 // Url returns the URL of the server for this Rietveld instance. | 81 // Url returns the URL of the server for this Rietveld instance. |
82 func (r *Rietveld) Url() string { | 82 func (r *Rietveld) Url() string { |
83 return r.url | 83 return r.url |
84 } | 84 } |
85 | 85 |
| 86 // Patchset contains the information about one patchset. |
| 87 // Currently we ommit fields that we don't need. |
| 88 type Patchset struct { |
| 89 Patchset int64 `json:"patchset"` |
| 90 Issue int64 `json:"issue"` |
| 91 Owner string `json:"owner"` |
| 92 OwnerEmail string `json:"owner_email"` |
| 93 Created time.Time |
| 94 CreatedStr string `json:"created"` |
| 95 Modified time.Time |
| 96 ModifiedStr string `json:"modified"` |
| 97 } |
| 98 |
86 func parseTime(t string) time.Time { | 99 func parseTime(t string) time.Time { |
87 parsed, _ := time.Parse("2006-01-02 15:04:05.999999", t) | 100 parsed, _ := time.Parse("2006-01-02 15:04:05.999999", t) |
88 return parsed | 101 return parsed |
89 } | 102 } |
90 | 103 |
91 // getIssueProperties returns a fully filled-in Issue object, as opposed to | 104 // getIssueProperties returns a fully filled-in Issue object, as opposed to |
92 // the partial data returned by Rietveld's search endpoint. | 105 // the partial data returned by Rietveld's search endpoint. |
93 func (r *Rietveld) GetIssueProperties(issue int64, messages bool) (*Issue, error
) { | 106 func (r *Rietveld) GetIssueProperties(issue int64, messages bool) (*Issue, error
) { |
94 url := fmt.Sprintf("/api/%v", issue) | 107 url := fmt.Sprintf("/api/%v", issue) |
95 if messages { | 108 if messages { |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 } | 277 } |
265 } | 278 } |
266 if len(issues) >= limit { | 279 if len(issues) >= limit { |
267 break | 280 break |
268 } | 281 } |
269 cursor = "&cursor=" + data.Cursor | 282 cursor = "&cursor=" + data.Cursor |
270 } | 283 } |
271 sort.Sort(issues) | 284 sort.Sort(issues) |
272 return issues, nil | 285 return issues, nil |
273 } | 286 } |
| 287 |
| 288 func (r Rietveld) GetPatchset(issueID int64, patchsetID int64) (*Patchset, error
) { |
| 289 url := fmt.Sprintf("/api/%d/%d", issueID, patchsetID) |
| 290 patchset := &Patchset{} |
| 291 if err := r.get(url, patchset); err != nil { |
| 292 return nil, err |
| 293 } |
| 294 |
| 295 patchset.Created = parseTime(patchset.CreatedStr) |
| 296 patchset.Modified = parseTime(patchset.ModifiedStr) |
| 297 return patchset, nil |
| 298 } |
OLD | NEW |