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

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

Issue 2982183002: Milo: Store console defs as their own entities (Closed)
Patch Set: tests 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,
(...skipping 10 matching lines...) Expand all
21 21
22 "golang.org/x/net/context" 22 "golang.org/x/net/context"
23 23
24 "github.com/luci/luci-go/common/api/gitiles" 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"
32 "github.com/luci/luci-go/milo/api/resp" 31 "github.com/luci/luci-go/milo/api/resp"
33 "github.com/luci/luci-go/milo/common" 32 "github.com/luci/luci-go/milo/common"
34 "github.com/luci/luci-go/milo/common/model" 33 "github.com/luci/luci-go/milo/common/model"
35 ) 34 )
36 35
37 // Returns results of build[commit_index][builder_index] 36 // Returns results of build[commit_index][builder_index]
38 func getConsoleBuilds( 37 func getConsoleBuilds(
39 c context.Context, builders []resp.BuilderRef, commits []string) ( 38 c context.Context, builders []resp.BuilderRef, commits []string) (
40 [][]*model.BuildSummary, error) { 39 [][]*model.BuildSummary, error) {
41 40
42 panic("Nothing to see here, check back later.") 41 panic("Nothing to see here, check back later.")
43 } 42 }
44 43
45 // getConsoleDef finds the console definition as defined by any project. 44 // 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. 45 // 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, 46 // 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. 47 // that builder will be removed from list of results.
49 func getConsoleDef(c context.Context, project, name string) (*config.Console, er ror) { 48 func getConsoleDef(c context.Context, project, name string) (*common.Console, er ror) {
50 cs, err := common.GetConsole(c, project, name) 49 cs, err := common.GetConsole(c, project, name)
51 if err != nil { 50 if err != nil {
52 return nil, err 51 return nil, err
53 } 52 }
54 // TODO(hinoka): Remove builders that the user does not have access to. 53 // TODO(hinoka): Remove builders that the user does not have access to.
55 return cs, nil 54 return cs, nil
56 } 55 }
57 56
58 func summaryToConsole(bs []*model.BuildSummary) []*resp.ConsoleBuild { 57 func summaryToConsole(bs []*model.BuildSummary) []*resp.ConsoleBuild {
59 cb := make([]*resp.ConsoleBuild, 0, len(bs)) 58 cb := make([]*resp.ConsoleBuild, 0, len(bs))
60 for _, b := range bs { 59 for _, b := range bs {
61 cb = append(cb, &resp.ConsoleBuild{ 60 cb = append(cb, &resp.ConsoleBuild{
62 // TODO(hinoka): This should link to the actual build. 61 // TODO(hinoka): This should link to the actual build.
63 Link: resp.NewLink(b.BuildKey.String(), "#"), 62 Link: resp.NewLink(b.BuildKey.String(), "#"),
64 Status: b.Summary.Status, 63 Status: b.Summary.Status,
65 }) 64 })
66 } 65 }
67 return cb 66 return cb
68 } 67 }
69 68
70 func console(c context.Context, project, name string) (*resp.Console, error) { 69 func console(c context.Context, project, name string) (*resp.Console, error) {
71 tStart := clock.Now(c) 70 tStart := clock.Now(c)
72 def, err := getConsoleDef(c, project, name) 71 def, err := getConsoleDef(c, project, name)
73 if err != nil { 72 if err != nil {
74 return nil, err 73 return nil, err
75 } 74 }
76 » commits, err := getCommits(c, def.RepoURL, def.Branch, 25) 75 » commits, err := getCommits(c, def.RepoURL, def.Ref, 25)
77 if err != nil { 76 if err != nil {
78 return nil, err 77 return nil, err
79 } 78 }
80 tGitiles := clock.Now(c) 79 tGitiles := clock.Now(c)
81 logging.Debugf(c, "Loading commits took %s.", tGitiles.Sub(tStart)) 80 logging.Debugf(c, "Loading commits took %s.", tGitiles.Sub(tStart))
82 commitNames := make([]string, len(commits)) 81 commitNames := make([]string, len(commits))
83 commitLinks := make([]*resp.Link, len(commits)) 82 commitLinks := make([]*resp.Link, len(commits))
84 for i, commit := range commits { 83 for i, commit := range commits {
85 commitNames[i] = commit.Revision.Label 84 commitNames[i] = commit.Revision.Label
86 commitLinks[i] = commit.Revision 85 commitLinks[i] = commit.Revision
87 } 86 }
88 87
89 // HACK(hinoka): This only supports buildbot.... 88 // HACK(hinoka): This only supports buildbot....
90 builders := make([]resp.BuilderRef, len(def.Builders)) 89 builders := make([]resp.BuilderRef, len(def.Builders))
91 for i, b := range def.Builders { 90 for i, b := range def.Builders {
92 » » builders[i] = resp.BuilderRef{ 91 » » builders[i] = resp.BuilderRef{Name: b}
93 » » » b.Name, strings.Split(b.Category, "|"), b.ShortName,
94 » » }
95 } 92 }
96 cb, err := getConsoleBuilds(c, builders, commitNames) 93 cb, err := getConsoleBuilds(c, builders, commitNames)
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(commits))
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.ID,
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) { 115 func getCommits(c context.Context, repoURL, treeish string, limit int) ([]resp.C ommit, error) {
119 commits, err := gitiles.Log(c, repoURL, treeish, limit) 116 commits, err := gitiles.Log(c, repoURL, treeish, limit)
120 if err != nil { 117 if err != nil {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 } 154 }
158 155
159 // ConsoleMainHandler is a redirect handler that redirects the user to the main 156 // ConsoleMainHandler is a redirect handler that redirects the user to the main
160 // console for a particular project. 157 // console for a particular project.
161 func ConsoleMainHandler(ctx *router.Context) { 158 func ConsoleMainHandler(ctx *router.Context) {
162 w, r, p := ctx.Writer, ctx.Request, ctx.Params 159 w, r, p := ctx.Writer, ctx.Request, ctx.Params
163 proj := p.ByName("project") 160 proj := p.ByName("project")
164 http.Redirect(w, r, fmt.Sprintf("/console/%s/main", proj), http.StatusMo vedPermanently) 161 http.Redirect(w, r, fmt.Sprintf("/console/%s/main", proj), http.StatusMo vedPermanently)
165 return 162 return
166 } 163 }
OLDNEW
« milo/buildsource/buildbot/pubsub_test.go ('K') | « milo/frontend/view_config.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698