OLD | NEW |
| (Empty) |
1 // Copyright 2015 The LUCI Authors. | |
2 // | |
3 // Licensed under the Apache License, Version 2.0 (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 | |
6 // | |
7 // http://www.apache.org/licenses/LICENSE-2.0 | |
8 // | |
9 // Unless required by applicable law or agreed to in writing, software | |
10 // distributed under the License is distributed on an "AS IS" BASIS, | |
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
12 // See the License for the specific language governing permissions and | |
13 // limitations under the License. | |
14 | |
15 package buildbot | |
16 | |
17 import ( | |
18 "fmt" | |
19 "net/http" | |
20 "strconv" | |
21 | |
22 "github.com/luci/luci-go/milo/common" | |
23 "github.com/luci/luci-go/server/router" | |
24 "github.com/luci/luci-go/server/templates" | |
25 ) | |
26 | |
27 // BuildHandler Renders the buildbot build page. | |
28 func BuildHandler(c *router.Context) { | |
29 master := c.Params.ByName("master") | |
30 if master == "" { | |
31 common.ErrorPage(c, http.StatusBadRequest, "No master specified"
) | |
32 return | |
33 } | |
34 builder := c.Params.ByName("builder") | |
35 if builder == "" { | |
36 common.ErrorPage(c, http.StatusBadRequest, "No builder specified
") | |
37 return | |
38 } | |
39 buildNum := c.Params.ByName("build") | |
40 if buildNum == "" { | |
41 common.ErrorPage(c, http.StatusBadRequest, "No build number") | |
42 return | |
43 } | |
44 num, err := strconv.Atoi(buildNum) | |
45 if err != nil { | |
46 common.ErrorPage(c, http.StatusBadRequest, | |
47 fmt.Sprintf("%s does not look like a number", buildNum)) | |
48 return | |
49 } | |
50 | |
51 result, err := Build(c.Context, master, builder, num) | |
52 if err != nil { | |
53 var code int | |
54 switch err { | |
55 case errBuildNotFound: | |
56 code = http.StatusNotFound | |
57 case errNotAuth: | |
58 code = http.StatusUnauthorized | |
59 default: | |
60 code = http.StatusInternalServerError | |
61 } | |
62 common.ErrorPage(c, code, err.Error()) | |
63 return | |
64 } | |
65 | |
66 templates.MustRender(c.Context, c.Writer, "pages/build.html", templates.
Args{ | |
67 "Build": result, | |
68 }) | |
69 } | |
70 | |
71 // BuilderHandler renders the buildbot builder page. | |
72 // Note: The builder html template contains self links to "?limit=123", which co
uld | |
73 // potentially override any other request parameters set. | |
74 func BuilderHandler(c *router.Context) { | |
75 master := c.Params.ByName("master") | |
76 if master == "" { | |
77 common.ErrorPage(c, http.StatusBadRequest, "No master specified"
) | |
78 return | |
79 } | |
80 builder := c.Params.ByName("builder") | |
81 if builder == "" { | |
82 common.ErrorPage(c, http.StatusBadRequest, "No builder specified
") | |
83 return | |
84 } | |
85 limit, err := common.GetLimit(c.Request) | |
86 if err != nil { | |
87 common.ErrorPage(c, http.StatusBadRequest, err.Error()) | |
88 return | |
89 } | |
90 if limit < 0 { | |
91 limit = 25 | |
92 } | |
93 cursor := c.Request.FormValue("cursor") | |
94 | |
95 result, err := builderImpl(c.Context, master, builder, limit, cursor) | |
96 _, notFound := err.(errBuilderNotFound) | |
97 switch { | |
98 case err == nil: | |
99 templates.MustRender(c.Context, c.Writer, "pages/builder.html",
templates.Args{ | |
100 "Builder": result, | |
101 }) | |
102 case err == errNotAuth: | |
103 common.ErrorPage(c, http.StatusUnauthorized, err.Error()) | |
104 case notFound: | |
105 common.ErrorPage(c, http.StatusNotFound, err.Error()) | |
106 default: // err != nil | |
107 common.ErrorPage(c, http.StatusInternalServerError, err.Error()) | |
108 } | |
109 return | |
110 } | |
OLD | NEW |