| OLD | NEW |
| 1 // Copyright 2016 The LUCI Authors. All rights reserved. | 1 // Copyright 2016 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
| 4 | 4 |
| 5 package buildbucket | 5 package buildbucket |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "encoding/json" | 8 "encoding/json" |
| 9 "fmt" | 9 "fmt" |
| 10 "net/url" | 10 "net/url" |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 | 222 |
| 223 type builderQuery struct { | 223 type builderQuery struct { |
| 224 Bucket string | 224 Bucket string |
| 225 Builder string | 225 Builder string |
| 226 Limit int | 226 Limit int |
| 227 } | 227 } |
| 228 | 228 |
| 229 // builderImpl is the implementation for getting a milo builder page from buildb
ucket. | 229 // builderImpl is the implementation for getting a milo builder page from buildb
ucket. |
| 230 // if maxCompletedBuilds < 0, 25 is used. | 230 // if maxCompletedBuilds < 0, 25 is used. |
| 231 func builderImpl(c context.Context, q builderQuery) (*resp.Builder, error) { | 231 func builderImpl(c context.Context, q builderQuery) (*resp.Builder, error) { |
| 232 » settings, err := common.GetSettings(c) | 232 » settings := common.GetSettings(c) |
| 233 » if err != nil { | |
| 234 » » logging.WithError(err).Errorf(c, "failed to get settings") | |
| 235 » » return nil, err | |
| 236 » } | |
| 237 if settings.Buildbucket == nil || settings.Buildbucket.Host == "" { | 233 if settings.Buildbucket == nil || settings.Buildbucket.Host == "" { |
| 238 » » logging.WithError(err).Errorf(c, "missing buildbucket settings") | 234 » » logging.Errorf(c, "missing buildbucket settings") |
| 239 return nil, errors.New("missing buildbucket settings") | 235 return nil, errors.New("missing buildbucket settings") |
| 240 } | 236 } |
| 241 host := settings.Buildbucket.Host | 237 host := settings.Buildbucket.Host |
| 242 | 238 |
| 243 if q.Limit < 0 { | 239 if q.Limit < 0 { |
| 244 q.Limit = 20 | 240 q.Limit = 20 |
| 245 } | 241 } |
| 246 | 242 |
| 247 result := &resp.Builder{ | 243 result := &resp.Builder{ |
| 248 Name: q.Builder, | 244 Name: q.Builder, |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 return time.Unix(microseconds/1e6, microseconds%1e6*1000).UTC() | 287 return time.Unix(microseconds/1e6, microseconds%1e6*1000).UTC() |
| 292 } | 288 } |
| 293 | 289 |
| 294 type newBuildsFirst []*resp.BuildSummary | 290 type newBuildsFirst []*resp.BuildSummary |
| 295 | 291 |
| 296 func (a newBuildsFirst) Len() int { return len(a) } | 292 func (a newBuildsFirst) Len() int { return len(a) } |
| 297 func (a newBuildsFirst) Swap(i, j int) { a[i], a[j] = a[j], a[i] } | 293 func (a newBuildsFirst) Swap(i, j int) { a[i], a[j] = a[j], a[i] } |
| 298 func (a newBuildsFirst) Less(i, j int) bool { | 294 func (a newBuildsFirst) Less(i, j int) bool { |
| 299 return a[i].PendingTime.Started.After(a[j].PendingTime.Started) | 295 return a[i].PendingTime.Started.After(a[j].PendingTime.Started) |
| 300 } | 296 } |
| OLD | NEW |