OLD | NEW |
1 // Package buildbucket provides tools for interacting with the buildbucket API. | 1 // Package buildbucket provides tools for interacting with the buildbucket API. |
2 package buildbucket | 2 package buildbucket |
3 | 3 |
4 import ( | 4 import ( |
5 "bytes" | 5 "bytes" |
6 "encoding/json" | 6 "encoding/json" |
7 "fmt" | 7 "fmt" |
8 "io/ioutil" | 8 "io/ioutil" |
9 "net/http" | 9 "net/http" |
| 10 "strconv" |
| 11 "time" |
10 | 12 |
11 "go.skia.org/infra/go/util" | 13 "go.skia.org/infra/go/util" |
12 ) | 14 ) |
13 | 15 |
14 const ( | 16 const ( |
15 apiUrl = "https://cr-buildbucket.appspot.com/_ah/api/buildbucket/v1" | 17 apiUrl = "https://cr-buildbucket.appspot.com/_ah/api/buildbucket/v1" |
16 ) | 18 ) |
17 | 19 |
18 var ( | 20 var ( |
19 DEFAULT_SCOPES = []string{ | 21 DEFAULT_SCOPES = []string{ |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 Url string `json:"url"` | 62 Url string `json:"url"` |
61 ParametersJson string `json:"parameters_json"` | 63 ParametersJson string `json:"parameters_json"` |
62 Result string `json:"result"` | 64 Result string `json:"result"` |
63 ResultDetailsJson string `json:"result_details_json"` | 65 ResultDetailsJson string `json:"result_details_json"` |
64 Status string `json:"status"` | 66 Status string `json:"status"` |
65 StatusChangedTimestamp string `json:"status_changed_ts"` | 67 StatusChangedTimestamp string `json:"status_changed_ts"` |
66 UpdatedTimestamp string `json:"updated_ts"` | 68 UpdatedTimestamp string `json:"updated_ts"` |
67 UtcNowTimestamp string `json:"utcnow_ts"` | 69 UtcNowTimestamp string `json:"utcnow_ts"` |
68 } | 70 } |
69 | 71 |
| 72 func (b *Build) Copy() *Build { |
| 73 return &Build{ |
| 74 Bucket: b.Bucket, |
| 75 CompletedTimestamp: b.CompletedTimestamp, |
| 76 CreatedBy: b.CreatedBy, |
| 77 CreatedTimestamp: b.CreatedTimestamp, |
| 78 FailureReason: b.FailureReason, |
| 79 Id: b.Id, |
| 80 Url: b.Url, |
| 81 ParametersJson: b.ParametersJson, |
| 82 Result: b.Result, |
| 83 ResultDetailsJson: b.ResultDetailsJson, |
| 84 Status: b.Status, |
| 85 StatusChangedTimestamp: b.StatusChangedTimestamp, |
| 86 UpdatedTimestamp: b.UpdatedTimestamp, |
| 87 UtcNowTimestamp: b.UtcNowTimestamp, |
| 88 } |
| 89 } |
| 90 |
| 91 func parseTime(t string) (time.Time, error) { |
| 92 i, err := strconv.ParseInt(t, 10, 64) |
| 93 if err != nil { |
| 94 return time.Time{}, err |
| 95 } |
| 96 return time.Unix(0, i), nil |
| 97 } |
| 98 |
| 99 func (b *Build) Created() (time.Time, error) { |
| 100 return parseTime(b.CreatedTimestamp) |
| 101 } |
| 102 |
| 103 func (b *Build) Completed() (time.Time, error) { |
| 104 return parseTime(b.CompletedTimestamp) |
| 105 } |
| 106 |
| 107 func (b *Build) StatusChanged() (time.Time, error) { |
| 108 return parseTime(b.StatusChangedTimestamp) |
| 109 } |
| 110 |
| 111 func (b *Build) Updated() (time.Time, error) { |
| 112 return parseTime(b.UpdatedTimestamp) |
| 113 } |
| 114 |
70 // Client is used for interacting with the BuildBucket API. | 115 // Client is used for interacting with the BuildBucket API. |
71 type Client struct { | 116 type Client struct { |
72 *http.Client | 117 *http.Client |
73 } | 118 } |
74 | 119 |
75 // NewClient returns an authenticated Client instance. | 120 // NewClient returns an authenticated Client instance. |
76 func NewClient(c *http.Client) *Client { | 121 func NewClient(c *http.Client) *Client { |
77 return &Client{c} | 122 return &Client{c} |
78 } | 123 } |
79 | 124 |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 } | 242 } |
198 } | 243 } |
199 return rv, nil | 244 return rv, nil |
200 } | 245 } |
201 | 246 |
202 // GetTrybotsForCL retrieves trybot results for the given CL. | 247 // GetTrybotsForCL retrieves trybot results for the given CL. |
203 func (c *Client) GetTrybotsForCL(issueID int64, patchsetID int64) ([]*Build, err
or) { | 248 func (c *Client) GetTrybotsForCL(issueID int64, patchsetID int64) ([]*Build, err
or) { |
204 url := fmt.Sprintf("%s/search?tag=buildset%%3Apatch%%2Frietveld%%2Fcoder
eview.chromium.org%%2F%d%%2F%d", apiUrl, issueID, patchsetID) | 249 url := fmt.Sprintf("%s/search?tag=buildset%%3Apatch%%2Frietveld%%2Fcoder
eview.chromium.org%%2F%d%%2F%d", apiUrl, issueID, patchsetID) |
205 return c.Search(url) | 250 return c.Search(url) |
206 } | 251 } |
OLD | NEW |