OLD | NEW |
1 // Copyright 2016 The LUCI Authors. | 1 // Copyright 2016 The LUCI Authors. |
2 // | 2 // |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
6 // | 6 // |
7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
8 // | 8 // |
9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 // See the License for the specific language governing permissions and | 12 // See the License for the specific language governing permissions and |
13 // limitations under the License. | 13 // limitations under the License. |
14 | 14 |
15 package buildbot | 15 package buildbot |
16 | 16 |
17 import ( | 17 import ( |
18 "encoding/json" | 18 "encoding/json" |
19 "errors" | |
20 "fmt" | 19 "fmt" |
21 "io/ioutil" | 20 "io/ioutil" |
22 "math" | 21 "math" |
23 "path/filepath" | 22 "path/filepath" |
24 "regexp" | 23 "regexp" |
25 "sort" | 24 "sort" |
26 "strconv" | 25 "strconv" |
27 "strings" | 26 "strings" |
28 "time" | 27 "time" |
29 | 28 |
30 "golang.org/x/net/context" | 29 "golang.org/x/net/context" |
31 | 30 |
32 "github.com/luci/gae/service/datastore" | 31 "github.com/luci/gae/service/datastore" |
33 "github.com/luci/luci-go/common/data/stringset" | 32 "github.com/luci/luci-go/common/data/stringset" |
| 33 "github.com/luci/luci-go/common/errors" |
34 "github.com/luci/luci-go/common/logging" | 34 "github.com/luci/luci-go/common/logging" |
35 "github.com/luci/luci-go/milo/api/resp" | 35 "github.com/luci/luci-go/milo/api/resp" |
| 36 "github.com/luci/luci-go/milo/common" |
36 "github.com/luci/luci-go/milo/common/model" | 37 "github.com/luci/luci-go/milo/common/model" |
37 ) | 38 ) |
38 | 39 |
39 var errBuildNotFound = errors.New("Build not found") | |
40 | |
41 // getBuild fetches a buildbot build from the datastore and checks ACLs. | 40 // getBuild fetches a buildbot build from the datastore and checks ACLs. |
42 // The return code matches the master responses. | 41 // The return code matches the master responses. |
43 func getBuild(c context.Context, master, builder string, buildNum int) (*buildbo
tBuild, error) { | 42 func getBuild(c context.Context, master, builder string, buildNum int) (*buildbo
tBuild, error) { |
44 if err := canAccessMaster(c, master); err != nil { | 43 if err := canAccessMaster(c, master); err != nil { |
45 return nil, err | 44 return nil, err |
46 } | 45 } |
47 | 46 |
48 result := &buildbotBuild{ | 47 result := &buildbotBuild{ |
49 Master: master, | 48 Master: master, |
50 Buildername: builder, | 49 Buildername: builder, |
51 Number: buildNum, | 50 Number: buildNum, |
52 } | 51 } |
53 | 52 |
54 err := datastore.Get(c, result) | 53 err := datastore.Get(c, result) |
55 if err == datastore.ErrNoSuchEntity { | 54 if err == datastore.ErrNoSuchEntity { |
56 » » err = errBuildNotFound | 55 » » err = errors.New("build not found", common.CodeNotFound) |
57 } | 56 } |
58 | 57 |
59 return result, err | 58 return result, err |
60 } | 59 } |
61 | 60 |
62 // result2Status translates a buildbot result integer into a model.Status. | 61 // result2Status translates a buildbot result integer into a model.Status. |
63 func result2Status(s *int) (status model.Status) { | 62 func result2Status(s *int) (status model.Status) { |
64 if s == nil { | 63 if s == nil { |
65 return model.Running | 64 return model.Running |
66 } | 65 } |
(...skipping 598 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
665 var newAliases map[string][]*buildbotLinkAlias | 664 var newAliases map[string][]*buildbotLinkAlias |
666 if l := remainingAliases.Len(); l > 0 { | 665 if l := remainingAliases.Len(); l > 0 { |
667 newAliases = make(map[string][]*buildbotLinkAlias, l) | 666 newAliases = make(map[string][]*buildbotLinkAlias, l) |
668 remainingAliases.Iter(func(v string) bool { | 667 remainingAliases.Iter(func(v string) bool { |
669 newAliases[v] = s.Aliases[v] | 668 newAliases[v] = s.Aliases[v] |
670 return true | 669 return true |
671 }) | 670 }) |
672 } | 671 } |
673 s.Aliases = newAliases | 672 s.Aliases = newAliases |
674 } | 673 } |
| 674 |
| 675 // BuildID is buildbots's notion of a Build. See buildsource.ID. |
| 676 type BuildID struct { |
| 677 Master string |
| 678 BuilderName string |
| 679 BuildNumber string |
| 680 } |
| 681 |
| 682 // GetLog implements buildsource.ID. |
| 683 func (b *BuildID) GetLog(context.Context, string) (string, bool, error) { panic(
"not implemented") } |
| 684 |
| 685 // Get implements buildsource.ID. |
| 686 func (b *BuildID) Get(c context.Context) (*resp.MiloBuild, error) { |
| 687 num, err := strconv.ParseInt(b.BuildNumber, 10, 0) |
| 688 if err != nil { |
| 689 return nil, errors.Annotate(err, "BuildNumber is not a number"). |
| 690 Tag(common.CodeParameterError). |
| 691 Err() |
| 692 } |
| 693 if num <= 0 { |
| 694 return nil, errors.New("BuildNumber must be > 0", common.CodePar
ameterError) |
| 695 } |
| 696 |
| 697 if b.Master == "" { |
| 698 return nil, errors.New("Master name is required", common.CodePar
ameterError) |
| 699 } |
| 700 if b.BuilderName == "" { |
| 701 return nil, errors.New("BuilderName name is required", common.Co
deParameterError) |
| 702 } |
| 703 |
| 704 return Build(c, b.Master, b.BuilderName, int(num)) |
| 705 } |
OLD | NEW |