| OLD | NEW |
| 1 // Copyright 2016 The LUCI Authors. | 1 // Copyright 2017 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 console | 15 package frontend |
| 16 | 16 |
| 17 import ( | 17 import ( |
| 18 "fmt" | 18 "fmt" |
| 19 "net/http" | 19 "net/http" |
| 20 "strings" | 20 "strings" |
| 21 | 21 |
| 22 "golang.org/x/net/context" | 22 "golang.org/x/net/context" |
| 23 | 23 |
| 24 "github.com/luci/luci-go/common/clock" | 24 "github.com/luci/luci-go/common/clock" |
| 25 "github.com/luci/luci-go/common/errors" |
| 25 "github.com/luci/luci-go/common/logging" | 26 "github.com/luci/luci-go/common/logging" |
| 27 "github.com/luci/luci-go/server/router" |
| 28 "github.com/luci/luci-go/server/templates" |
| 29 |
| 26 "github.com/luci/luci-go/milo/api/config" | 30 "github.com/luci/luci-go/milo/api/config" |
| 27 "github.com/luci/luci-go/milo/api/resp" | 31 "github.com/luci/luci-go/milo/api/resp" |
| 28 "github.com/luci/luci-go/milo/common" | 32 "github.com/luci/luci-go/milo/common" |
| 29 "github.com/luci/luci-go/milo/common/gitiles" | 33 "github.com/luci/luci-go/milo/common/gitiles" |
| 30 "github.com/luci/luci-go/milo/common/model" | 34 "github.com/luci/luci-go/milo/common/model" |
| 31 "github.com/luci/luci-go/server/router" | |
| 32 ) | 35 ) |
| 33 | 36 |
| 34 // Returns results of build[commit_index][builder_index] | 37 // Returns results of build[commit_index][builder_index] |
| 35 func GetConsoleBuilds( | 38 func getConsoleBuilds( |
| 36 c context.Context, builders []resp.BuilderRef, commits []string) ( | 39 c context.Context, builders []resp.BuilderRef, commits []string) ( |
| 37 [][]*model.BuildSummary, error) { | 40 [][]*model.BuildSummary, error) { |
| 38 | 41 |
| 39 panic("Nothing to see here, check back later.") | 42 panic("Nothing to see here, check back later.") |
| 40 } | 43 } |
| 41 | 44 |
| 42 // getConsoleDef finds the console definition as defined by any project. | 45 // getConsoleDef finds the console definition as defined by any project. |
| 43 // If the user is not a reader of the project, this will return a 404. | 46 // If the user is not a reader of the project, this will return a 404. |
| 44 // TODO(hinoka): If the user is not a reader of any of of the builders returned, | 47 // TODO(hinoka): If the user is not a reader of any of of the builders returned, |
| 45 // that builder will be removed from list of results. | 48 // that builder will be removed from list of results. |
| 46 func getConsoleDef(c context.Context, project, name string) (*config.Console, er
ror) { | 49 func getConsoleDef(c context.Context, project, name string) (*config.Console, er
ror) { |
| 47 cs, err := common.GetConsole(c, project, name) | 50 cs, err := common.GetConsole(c, project, name) |
| 48 if err != nil { | 51 if err != nil { |
| 49 return nil, err | 52 return nil, err |
| 50 } | 53 } |
| 51 // TODO(hinoka): Remove builders that the user does not have access to. | 54 // TODO(hinoka): Remove builders that the user does not have access to. |
| 52 return cs, nil | 55 return cs, nil |
| 53 } | 56 } |
| 54 | 57 |
| 55 // Main is a redirect handler that redirects the user to the main console for a | |
| 56 // particular project. | |
| 57 func Main(ctx *router.Context) { | |
| 58 w, r, p := ctx.Writer, ctx.Request, ctx.Params | |
| 59 proj := p.ByName("project") | |
| 60 http.Redirect(w, r, fmt.Sprintf("/console/%s/main", proj), http.StatusMo
vedPermanently) | |
| 61 return | |
| 62 } | |
| 63 | |
| 64 func summaryToConsole(bs []*model.BuildSummary) []*resp.ConsoleBuild { | 58 func summaryToConsole(bs []*model.BuildSummary) []*resp.ConsoleBuild { |
| 65 cb := make([]*resp.ConsoleBuild, 0, len(bs)) | 59 cb := make([]*resp.ConsoleBuild, 0, len(bs)) |
| 66 for _, b := range bs { | 60 for _, b := range bs { |
| 67 cb = append(cb, &resp.ConsoleBuild{ | 61 cb = append(cb, &resp.ConsoleBuild{ |
| 68 // TODO(hinoka): This should link to the actual build. | 62 // TODO(hinoka): This should link to the actual build. |
| 69 Link: resp.NewLink(b.BuildKey.String(), "#"), | 63 Link: resp.NewLink(b.BuildKey.String(), "#"), |
| 70 Status: b.Summary.Status, | 64 Status: b.Summary.Status, |
| 71 }) | 65 }) |
| 72 } | 66 } |
| 73 return cb | 67 return cb |
| (...skipping 18 matching lines...) Expand all Loading... |
| 92 commitLinks[i] = commit.Revision | 86 commitLinks[i] = commit.Revision |
| 93 } | 87 } |
| 94 | 88 |
| 95 // HACK(hinoka): This only supports buildbot.... | 89 // HACK(hinoka): This only supports buildbot.... |
| 96 builders := make([]resp.BuilderRef, len(def.Builders)) | 90 builders := make([]resp.BuilderRef, len(def.Builders)) |
| 97 for i, b := range def.Builders { | 91 for i, b := range def.Builders { |
| 98 builders[i] = resp.BuilderRef{ | 92 builders[i] = resp.BuilderRef{ |
| 99 b.Name, strings.Split(b.Category, "|"), b.ShortName, | 93 b.Name, strings.Split(b.Category, "|"), b.ShortName, |
| 100 } | 94 } |
| 101 } | 95 } |
| 102 » cb, err := GetConsoleBuilds(c, builders, commitNames) | 96 » cb, err := getConsoleBuilds(c, builders, commitNames) |
| 103 tConsole := clock.Now(c) | 97 tConsole := clock.Now(c) |
| 104 logging.Debugf(c, "Loading the console took a total of %s.", tConsole.Su
b(tGitiles)) | 98 logging.Debugf(c, "Loading the console took a total of %s.", tConsole.Su
b(tGitiles)) |
| 105 if err != nil { | 99 if err != nil { |
| 106 return nil, err | 100 return nil, err |
| 107 } | 101 } |
| 108 ccb := make([]resp.CommitBuild, len(commits)) | 102 ccb := make([]resp.CommitBuild, len(commits)) |
| 109 for i, commit := range commitLinks { | 103 for i, commit := range commitLinks { |
| 110 // TODO(hinoka): Not like this | 104 // TODO(hinoka): Not like this |
| 111 ccb[i].Commit = resp.Commit{Revision: commit} | 105 ccb[i].Commit = resp.Commit{Revision: commit} |
| 112 ccb[i].Build = summaryToConsole(cb[i]) | 106 ccb[i].Build = summaryToConsole(cb[i]) |
| 113 } | 107 } |
| 114 | 108 |
| 115 cs := &resp.Console{ | 109 cs := &resp.Console{ |
| 116 Name: def.Name, | 110 Name: def.Name, |
| 117 Commit: ccb, | 111 Commit: ccb, |
| 118 BuilderRef: builders, | 112 BuilderRef: builders, |
| 119 } | 113 } |
| 120 | 114 |
| 121 return cs, nil | 115 return cs, nil |
| 122 } | 116 } |
| 117 |
| 118 // ConsoleHandler renders the console page. |
| 119 func ConsoleHandler(c *router.Context) { |
| 120 project := c.Params.ByName("project") |
| 121 if project == "" { |
| 122 ErrorHandler(c, errors.New("Missing Project", common.CodeParamet
erError)) |
| 123 return |
| 124 } |
| 125 name := c.Params.ByName("name") |
| 126 |
| 127 result, err := console(c.Context, project, name) |
| 128 if err != nil { |
| 129 ErrorHandler(c, err) |
| 130 return |
| 131 } |
| 132 |
| 133 templates.MustRender(c.Context, c.Writer, "pages/console.html", template
s.Args{ |
| 134 "Console": result, |
| 135 }) |
| 136 } |
| 137 |
| 138 // ConsoleMainHandler is a redirect handler that redirects the user to the main |
| 139 // console for a particular project. |
| 140 func ConsoleMainHandler(ctx *router.Context) { |
| 141 w, r, p := ctx.Writer, ctx.Request, ctx.Params |
| 142 proj := p.ByName("project") |
| 143 http.Redirect(w, r, fmt.Sprintf("/console/%s/main", proj), http.StatusMo
vedPermanently) |
| 144 return |
| 145 } |
| OLD | NEW |