| OLD | NEW |
| 1 // Copyright 2017 The LUCI Authors. All rights reserved. | 1 // Copyright 2017 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 buildsource | 5 package buildsource |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "strconv" | |
| 9 "strings" | 8 "strings" |
| 10 | 9 |
| 11 "golang.org/x/net/context" | 10 "golang.org/x/net/context" |
| 12 | 11 |
| 13 "github.com/luci/gae/service/datastore" | 12 "github.com/luci/gae/service/datastore" |
| 14 | 13 |
| 15 "github.com/luci/luci-go/common/errors" | 14 "github.com/luci/luci-go/common/errors" |
| 16 "github.com/luci/luci-go/common/logging" | |
| 17 "github.com/luci/luci-go/milo/api/resp" | 15 "github.com/luci/luci-go/milo/api/resp" |
| 18 "github.com/luci/luci-go/milo/buildsource/buildbot" | 16 "github.com/luci/luci-go/milo/buildsource/buildbot" |
| 19 "github.com/luci/luci-go/milo/buildsource/buildbucket" | 17 "github.com/luci/luci-go/milo/buildsource/buildbucket" |
| 20 "github.com/luci/luci-go/milo/common" | 18 "github.com/luci/luci-go/milo/common" |
| 21 ) | 19 ) |
| 22 | 20 |
| 23 // BuilderID is the universal ID of a builder, and has the form: | 21 // BuilderID is the universal ID of a builder, and has the form: |
| 24 // buildbucket/bucket/builder | 22 // buildbucket/bucket/builder |
| 25 // buildbot/master/builder | 23 // buildbot/master/builder |
| 26 type BuilderID string | 24 type BuilderID string |
| (...skipping 26 matching lines...) Expand all Loading... |
| 53 } | 51 } |
| 54 if builderName == "" { | 52 if builderName == "" { |
| 55 err = errors.New("bad BuilderID: empty builderName", common.Code
ParameterError) | 53 err = errors.New("bad BuilderID: empty builderName", common.Code
ParameterError) |
| 56 return | 54 return |
| 57 } | 55 } |
| 58 return | 56 return |
| 59 } | 57 } |
| 60 | 58 |
| 61 // Get allows you to obtain the resp.Builder that corresponds with this | 59 // Get allows you to obtain the resp.Builder that corresponds with this |
| 62 // BuilderID. | 60 // BuilderID. |
| 63 func (b BuilderID) Get(c context.Context, limitStr string, cursorStr string) (*r
esp.Builder, error) { | 61 func (b BuilderID) Get(c context.Context, limit int, cursorStr string) (*resp.Bu
ilder, error) { |
| 64 // TODO(iannucci): replace these implementations with a BuildSummary que
ry. | 62 // TODO(iannucci): replace these implementations with a BuildSummary que
ry. |
| 65 | |
| 66 limit := 0 | |
| 67 if limitStr != "" { | |
| 68 switch limitVal, err := strconv.ParseInt(limitStr, 10, 0); err { | |
| 69 case nil: | |
| 70 limit = int(limitVal) | |
| 71 default: | |
| 72 logging.WithError(err).Warningf(c, "ignoring bad limit %
q", limitStr) | |
| 73 } | |
| 74 } | |
| 75 if limit <= 0 { | |
| 76 limit = 25 | |
| 77 } | |
| 78 | |
| 79 source, group, builder, err := b.Split() | 63 source, group, builder, err := b.Split() |
| 80 if err != nil { | 64 if err != nil { |
| 81 return nil, err | 65 return nil, err |
| 82 } | 66 } |
| 83 | 67 |
| 84 switch source { | 68 switch source { |
| 85 case "buildbot": | 69 case "buildbot": |
| 86 cursor, err := datastore.DecodeCursor(c, cursorStr) | 70 cursor, err := datastore.DecodeCursor(c, cursorStr) |
| 87 if err != nil { | 71 if err != nil { |
| 88 return nil, errors.Annotate(err, "bad cursor").Err() | 72 return nil, errors.Annotate(err, "bad cursor").Err() |
| 89 } | 73 } |
| 90 return buildbot.GetBuilder(c, group, builder, limit, cursor) | 74 return buildbot.GetBuilder(c, group, builder, limit, cursor) |
| 91 | 75 |
| 92 case "buildbucket": | 76 case "buildbucket": |
| 93 return buildbucket.GetBuilder(c, group, builder, limit) | 77 return buildbucket.GetBuilder(c, group, builder, limit) |
| 94 } | 78 } |
| 95 | 79 |
| 96 panic("impossible") | 80 panic("impossible") |
| 97 } | 81 } |
| OLD | NEW |