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

Side by Side Diff: milo/appengine/console/console.go

Issue 2238883003: Milo: Use luci-cfg for defining projects and console view. (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-go@master
Patch Set: review Created 4 years, 4 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
« no previous file with comments | « no previous file | milo/appengine/console/html.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The LUCI Authors. All rights reserved. 1 // Copyright 2016 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0 2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file. 3 // that can be found in the LICENSE file.
4 4
5 package console 5 package console
6 6
7 import ( 7 import (
8 "fmt" 8 "fmt"
9 "net/http"
9 "strings" 10 "strings"
10 11
11 "github.com/luci/luci-go/common/clock" 12 "github.com/luci/luci-go/common/clock"
12 log "github.com/luci/luci-go/common/logging" 13 log "github.com/luci/luci-go/common/logging"
13 "github.com/luci/luci-go/milo/api/resp" 14 "github.com/luci/luci-go/milo/api/resp"
14 "github.com/luci/luci-go/milo/appengine/backend/git" 15 "github.com/luci/luci-go/milo/appengine/backend/git"
15 "github.com/luci/luci-go/milo/appengine/buildbot" 16 "github.com/luci/luci-go/milo/appengine/buildbot"
17 "github.com/luci/luci-go/milo/appengine/settings"
18 "github.com/luci/luci-go/milo/common/config"
19 "github.com/luci/luci-go/server/router"
16 "golang.org/x/net/context" 20 "golang.org/x/net/context"
17 ) 21 )
18 22
19 // Returns results of build[commit_index][builder_index] 23 // Returns results of build[commit_index][builder_index]
20 func GetConsoleBuilds( 24 func GetConsoleBuilds(
21 c context.Context, module string, 25 c context.Context, module string,
22 builders []resp.BuilderRef, commits []string) ( 26 builders []resp.BuilderRef, commits []string) (
23 [][]*resp.ConsoleBuild, error) { 27 [][]*resp.ConsoleBuild, error) {
24 28
25 switch module { 29 switch module {
26 case "buildbot": 30 case "buildbot":
27 return buildbot.GetConsoleBuilds(c, builders, commits) 31 return buildbot.GetConsoleBuilds(c, builders, commits)
28 // The case for buildbucket and dm goes here. 32 // The case for buildbucket and dm goes here.
29 default: 33 default:
30 panic(fmt.Errorf("Unrecognized module %s", module)) 34 panic(fmt.Errorf("Unrecognized module %s", module))
31 } 35 }
32 } 36 }
33 37
34 func console(c context.Context, def *ConsoleDef) (*resp.Console, error) { 38 // getConsoleDef finds the console definition as defined by any project.
35 » tStart := clock.Now(c) 39 // If the user is not a reader of the project, this will return a 404.
36 » // Lookup Commits. For this hack, we're just gonna hardcode src.git 40 // TODO(hinoka): If the user is not a reader of any of of the builders returned,
37 » commits, err := git.GetCommits(c, def.Repository, def.Branch, 25) 41 // that builder will be removed from list of results.
42 func getConsoleDef(c context.Context, project, name string) (*config.Console, er ror) {
43 » cs, err := settings.GetConsole(c, project, name)
38 if err != nil { 44 if err != nil {
39 return nil, err 45 return nil, err
40 } 46 }
47 // TODO(hinoka): Remove builders that the user does not have access to.
48 return cs, nil
49 }
50
51 // Main is a redirect handler that redirects the user to the main console for a
52 // particular project.
53 func Main(ctx *router.Context) {
54 w, r, p := ctx.Writer, ctx.Request, ctx.Params
55 proj := p.ByName("project")
56 http.Redirect(w, r, fmt.Sprintf("/console/%s/main", proj), http.StatusMo vedPermanently)
57 return
58 }
59
60 func console(c context.Context, project, name string) (*resp.Console, error) {
61 tStart := clock.Now(c)
62 def, err := getConsoleDef(c, project, name)
63 if err != nil {
64 return nil, err
65 }
66 commits, err := git.GetCommits(c, def.RepoURL, def.Branch, 25)
67 if err != nil {
68 return nil, err
69 }
41 tGitiles := clock.Now(c) 70 tGitiles := clock.Now(c)
42 log.Debugf(c, "Loading commits took %s.", tGitiles.Sub(tStart)) 71 log.Debugf(c, "Loading commits took %s.", tGitiles.Sub(tStart))
43 commitNames := make([]string, len(commits)) 72 commitNames := make([]string, len(commits))
44 for i, commit := range commits { 73 for i, commit := range commits {
45 commitNames[i] = commit.Revision 74 commitNames[i] = commit.Revision
46 } 75 }
47 76
48 // HACK(hinoka): This only supports buildbot.... 77 // HACK(hinoka): This only supports buildbot....
49 builders := make([]resp.BuilderRef, len(def.Builders)) 78 builders := make([]resp.BuilderRef, len(def.Builders))
50 for i, b := range def.Builders { 79 for i, b := range def.Builders {
(...skipping 15 matching lines...) Expand all
66 } 95 }
67 96
68 cs := &resp.Console{ 97 cs := &resp.Console{
69 Name: def.Name, 98 Name: def.Name,
70 Commit: ccb, 99 Commit: ccb,
71 BuilderRef: builders, 100 BuilderRef: builders,
72 } 101 }
73 102
74 return cs, nil 103 return cs, nil
75 } 104 }
OLDNEW
« no previous file with comments | « no previous file | milo/appengine/console/html.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698