Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(388)

Side by Side Diff: milo/buildsource/builder.go

Issue 2977863002: [milo] Refactor all html knowledge out of backends. (Closed)
Patch Set: now with case insensitivity Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « milo/buildsource/buildbucket/struct.go ('k') | milo/buildsource/id.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2017 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file.
4
5 package buildsource
6
7 import (
8 "strconv"
9 "strings"
10
11 "golang.org/x/net/context"
12
13 "github.com/luci/gae/service/datastore"
14
15 "github.com/luci/luci-go/common/errors"
16 "github.com/luci/luci-go/common/logging"
17 "github.com/luci/luci-go/milo/api/resp"
18 "github.com/luci/luci-go/milo/buildsource/buildbot"
19 "github.com/luci/luci-go/milo/buildsource/buildbucket"
20 "github.com/luci/luci-go/milo/common"
21 )
22
23 // BuilderID is the universal ID of a builder, and has the form:
24 // buildbucket/bucket/builder
25 // buildbot/master/builder
26 type BuilderID string
27
28 // Split breaks the BuilderID into pieces.
29 // - backend is either 'buildbot' or 'buildbucket'
30 // - backendGroup is either the bucket or master name
31 // - builderName is the builder name.
32 //
33 // Returns an error if the BuilderID is malformed (wrong # slashes) or if any of
34 // the pieces are empty.
35 func (b BuilderID) Split() (backend, backendGroup, builderName string, err error ) {
36 toks := strings.SplitN(string(b), "/", 3)
37 if len(toks) != 3 {
38 err = errors.Reason("bad BuilderID: not enough tokens: %q", b).
39 Tag(common.CodeParameterError).Err()
40 return
41 }
42 backend, backendGroup, builderName = toks[0], toks[1], toks[2]
43 switch backend {
44 case "buildbot", "buildbucket":
45 default:
46 err = errors.Reason("bad BuilderID: unknown backend %q", backend ).
47 Tag(common.CodeParameterError).Err()
48 return
49 }
50 if backendGroup == "" {
51 err = errors.New("bad BuilderID: empty backendGroup", common.Cod eParameterError)
52 return
53 }
54 if builderName == "" {
55 err = errors.New("bad BuilderID: empty builderName", common.Code ParameterError)
56 return
57 }
58 return
59 }
60
61 // Get allows you to obtain the resp.Builder that corresponds with this
62 // BuilderID.
63 func (b BuilderID) Get(c context.Context, limitStr string, cursorStr string) (*r esp.Builder, error) {
64 // 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()
80 if err != nil {
81 return nil, err
82 }
83
84 switch source {
85 case "buildbot":
86 cursor, err := datastore.DecodeCursor(c, cursorStr)
87 if err != nil {
88 return nil, errors.Annotate(err, "bad cursor").Err()
89 }
90 return buildbot.GetBuilder(c, group, builder, limit, cursor)
91
92 case "buildbucket":
93 return buildbucket.GetBuilder(c, group, builder, limit)
94 }
95
96 panic("impossible")
97 }
OLDNEW
« no previous file with comments | « milo/buildsource/buildbucket/struct.go ('k') | milo/buildsource/id.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698