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

Side by Side Diff: milo/frontend/view_console.go

Issue 2978293002: [milo] Add an (uncached) method to get console rows. (Closed)
Patch Set: 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
OLDNEW
1 // Copyright 2017 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 frontend 15 package frontend
16 16
17 import ( 17 import (
18 "encoding/hex"
18 "fmt" 19 "fmt"
19 "net/http" 20 "net/http"
20 "strings" 21 "strings"
21 22
22 "golang.org/x/net/context" 23 "golang.org/x/net/context"
23 24
24 "github.com/luci/luci-go/common/api/gitiles"
25 "github.com/luci/luci-go/common/clock" 25 "github.com/luci/luci-go/common/clock"
26 "github.com/luci/luci-go/common/errors" 26 "github.com/luci/luci-go/common/errors"
27 "github.com/luci/luci-go/common/logging" 27 "github.com/luci/luci-go/common/logging"
28 "github.com/luci/luci-go/server/router" 28 "github.com/luci/luci-go/server/router"
29 "github.com/luci/luci-go/server/templates" 29 "github.com/luci/luci-go/server/templates"
30 30
31 "github.com/luci/luci-go/milo/api/config" 31 "github.com/luci/luci-go/milo/api/config"
32 "github.com/luci/luci-go/milo/api/resp" 32 "github.com/luci/luci-go/milo/api/resp"
33 "github.com/luci/luci-go/milo/buildsource"
33 "github.com/luci/luci-go/milo/common" 34 "github.com/luci/luci-go/milo/common"
34 "github.com/luci/luci-go/milo/common/model" 35 "github.com/luci/luci-go/milo/common/model"
36 "github.com/luci/luci-go/milo/git"
35 ) 37 )
36 38
37 // Returns results of build[commit_index][builder_index]
38 func getConsoleBuilds(
39 c context.Context, builders []resp.BuilderRef, commits []string) (
40 [][]*model.BuildSummary, error) {
41
42 panic("Nothing to see here, check back later.")
43 }
44
45 // getConsoleDef finds the console definition as defined by any project. 39 // getConsoleDef finds the console definition as defined by any project.
46 // If the user is not a reader of the project, this will return a 404. 40 // If the user is not a reader of the project, this will return a 404.
47 // TODO(hinoka): If the user is not a reader of any of of the builders returned, 41 // TODO(hinoka): If the user is not a reader of any of of the builders returned,
48 // that builder will be removed from list of results. 42 // that builder will be removed from list of results.
49 func getConsoleDef(c context.Context, project, name string) (*config.Console, er ror) { 43 func getConsoleDef(c context.Context, project, name string) (*config.Console, er ror) {
50 cs, err := common.GetConsole(c, project, name) 44 cs, err := common.GetConsole(c, project, name)
51 if err != nil { 45 if err != nil {
52 return nil, err 46 return nil, err
53 } 47 }
54 // TODO(hinoka): Remove builders that the user does not have access to. 48 // TODO(hinoka): Remove builders that the user does not have access to.
(...skipping 11 matching lines...) Expand all
66 } 60 }
67 return cb 61 return cb
68 } 62 }
69 63
70 func console(c context.Context, project, name string) (*resp.Console, error) { 64 func console(c context.Context, project, name string) (*resp.Console, error) {
71 tStart := clock.Now(c) 65 tStart := clock.Now(c)
72 def, err := getConsoleDef(c, project, name) 66 def, err := getConsoleDef(c, project, name)
73 if err != nil { 67 if err != nil {
74 return nil, err 68 return nil, err
75 } 69 }
76 » commits, err := getCommits(c, def.RepoURL, def.Branch, 25) 70 » commitInfo, err := git.GetHistory(c, def.RepoURL, def.Branch, 25)
77 if err != nil { 71 if err != nil {
78 return nil, err 72 return nil, err
79 } 73 }
80 tGitiles := clock.Now(c) 74 tGitiles := clock.Now(c)
81 logging.Debugf(c, "Loading commits took %s.", tGitiles.Sub(tStart)) 75 logging.Debugf(c, "Loading commits took %s.", tGitiles.Sub(tStart))
82 » commitNames := make([]string, len(commits)) 76 » commitNames := make([]string, len(commitInfo.Commits))
83 » commitLinks := make([]*resp.Link, len(commits)) 77 » commitLinks := make([]*resp.Link, len(commitInfo.Commits))
84 » for i, commit := range commits { 78 » for i, commit := range commitInfo.Commits {
85 » » commitNames[i] = commit.Revision.Label 79 » » commitS := hex.EncodeToString(commit.Hash)
86 » » commitLinks[i] = commit.Revision 80 » » commitNames[i] = commitS
81 » » commitLinks[i] = resp.NewLink(commitS, def.RepoURL+"/+/"+commitS )
87 } 82 }
88 83
89 // HACK(hinoka): This only supports buildbot.... 84 // HACK(hinoka): This only supports buildbot....
Ryan Tseng 2017/07/19 08:07:58 no longer~
iannucci 2017/07/20 00:14:56 Done.
85 builderNames := make([]string, len(def.Builders))
90 builders := make([]resp.BuilderRef, len(def.Builders)) 86 builders := make([]resp.BuilderRef, len(def.Builders))
91 for i, b := range def.Builders { 87 for i, b := range def.Builders {
88 builderNames[i] = b.Name
92 builders[i] = resp.BuilderRef{ 89 builders[i] = resp.BuilderRef{
93 b.Name, strings.Split(b.Category, "|"), b.ShortName, 90 b.Name, strings.Split(b.Category, "|"), b.ShortName,
94 } 91 }
95 } 92 }
96 » cb, err := getConsoleBuilds(c, builders, commitNames) 93 » cb, err := buildsource.GetBuildSummariesForConsole(c, project, def, comm itNames, builderNames)
97 tConsole := clock.Now(c) 94 tConsole := clock.Now(c)
98 logging.Debugf(c, "Loading the console took a total of %s.", tConsole.Su b(tGitiles)) 95 logging.Debugf(c, "Loading the console took a total of %s.", tConsole.Su b(tGitiles))
99 if err != nil { 96 if err != nil {
100 return nil, err 97 return nil, err
101 } 98 }
102 » ccb := make([]resp.CommitBuild, len(commits)) 99 » ccb := make([]resp.CommitBuild, len(commitNames))
103 for i, commit := range commitLinks { 100 for i, commit := range commitLinks {
104 // TODO(hinoka): Not like this 101 // TODO(hinoka): Not like this
105 ccb[i].Commit = resp.Commit{Revision: commit} 102 ccb[i].Commit = resp.Commit{Revision: commit}
106 ccb[i].Build = summaryToConsole(cb[i]) 103 ccb[i].Build = summaryToConsole(cb[i])
107 } 104 }
108 105
109 cs := &resp.Console{ 106 cs := &resp.Console{
110 Name: def.Name, 107 Name: def.Name,
111 Commit: ccb, 108 Commit: ccb,
112 BuilderRef: builders, 109 BuilderRef: builders,
113 } 110 }
114 111
115 return cs, nil 112 return cs, nil
116 } 113 }
117 114
118 func getCommits(c context.Context, repoURL, treeish string, limit int) ([]resp.C ommit, error) {
119 commits, err := gitiles.Log(c, repoURL, treeish, limit)
120 if err != nil {
121 return nil, err
122 }
123 result := make([]resp.Commit, len(commits))
124 for i, log := range commits {
125 result[i] = resp.Commit{
126 AuthorName: log.Author.Name,
127 AuthorEmail: log.Author.Email,
128 Repo: repoURL,
129 Revision: resp.NewLink(log.Commit, repoURL+"/+/"+log. Commit),
130 Description: log.Message,
131 Title: strings.SplitN(log.Message, "\n", 2)[0],
132 // TODO(hinoka): Fill in the rest of resp.Commit and add those details
133 // in the html.
134 }
135 }
136 return result, nil
137 }
138
139 // ConsoleHandler renders the console page. 115 // ConsoleHandler renders the console page.
140 func ConsoleHandler(c *router.Context) { 116 func ConsoleHandler(c *router.Context) {
141 project := c.Params.ByName("project") 117 project := c.Params.ByName("project")
142 if project == "" { 118 if project == "" {
143 ErrorHandler(c, errors.New("Missing Project", common.CodeParamet erError)) 119 ErrorHandler(c, errors.New("Missing Project", common.CodeParamet erError))
144 return 120 return
145 } 121 }
146 name := c.Params.ByName("name") 122 name := c.Params.ByName("name")
147 123
148 result, err := console(c.Context, project, name) 124 result, err := console(c.Context, project, name)
149 if err != nil { 125 if err != nil {
150 ErrorHandler(c, err) 126 ErrorHandler(c, err)
151 return 127 return
152 } 128 }
153 129
154 templates.MustRender(c.Context, c.Writer, "pages/console.html", template s.Args{ 130 templates.MustRender(c.Context, c.Writer, "pages/console.html", template s.Args{
155 "Console": result, 131 "Console": result,
156 }) 132 })
157 } 133 }
158 134
159 // ConsoleMainHandler is a redirect handler that redirects the user to the main 135 // ConsoleMainHandler is a redirect handler that redirects the user to the main
160 // console for a particular project. 136 // console for a particular project.
161 func ConsoleMainHandler(ctx *router.Context) { 137 func ConsoleMainHandler(ctx *router.Context) {
162 w, r, p := ctx.Writer, ctx.Request, ctx.Params 138 w, r, p := ctx.Writer, ctx.Request, ctx.Params
163 proj := p.ByName("project") 139 proj := p.ByName("project")
164 http.Redirect(w, r, fmt.Sprintf("/console/%s/main", proj), http.StatusMo vedPermanently) 140 http.Redirect(w, r, fmt.Sprintf("/console/%s/main", proj), http.StatusMo vedPermanently)
165 return 141 return
166 } 142 }
OLDNEW
« milo/common/model/build_summary.go ('K') | « milo/common/model/build_summary.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698