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

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: Actually add an endpoint 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 "strings" 9 "strings"
10 10
11 "github.com/luci/luci-go/common/clock" 11 "github.com/luci/luci-go/common/clock"
12 log "github.com/luci/luci-go/common/logging" 12 log "github.com/luci/luci-go/common/logging"
13 "github.com/luci/luci-go/milo/api/resp" 13 "github.com/luci/luci-go/milo/api/resp"
14 "github.com/luci/luci-go/milo/appengine/backend/git" 14 "github.com/luci/luci-go/milo/appengine/backend/git"
15 "github.com/luci/luci-go/milo/appengine/buildbot" 15 "github.com/luci/luci-go/milo/appengine/buildbot"
16 "github.com/luci/luci-go/milo/appengine/settings"
17 "github.com/luci/luci-go/milo/common/config"
16 "golang.org/x/net/context" 18 "golang.org/x/net/context"
17 ) 19 )
18 20
19 // Returns results of build[commit_index][builder_index] 21 // Returns results of build[commit_index][builder_index]
20 func GetConsoleBuilds( 22 func GetConsoleBuilds(
21 c context.Context, module string, 23 c context.Context, module string,
22 builders []resp.BuilderRef, commits []string) ( 24 builders []resp.BuilderRef, commits []string) (
23 [][]*resp.ConsoleBuild, error) { 25 [][]*resp.ConsoleBuild, error) {
24 26
25 switch module { 27 switch module {
26 case "buildbot": 28 case "buildbot":
27 return buildbot.GetConsoleBuilds(c, builders, commits) 29 return buildbot.GetConsoleBuilds(c, builders, commits)
28 // The case for buildbucket and dm goes here. 30 // The case for buildbucket and dm goes here.
29 default: 31 default:
30 panic(fmt.Errorf("Unrecognized module %s", module)) 32 panic(fmt.Errorf("Unrecognized module %s", module))
31 } 33 }
32 } 34 }
33 35
34 func console(c context.Context, def *ConsoleDef) (*resp.Console, error) { 36 // getConsoleDef finds the console definition as defined by any project.
35 » tStart := clock.Now(c) 37 // 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 38 // If the user is not a reader of any of of the builders returned,
estaab 2016/08/18 15:51:46 Can you move the TODO up here so it's clear that i
Ryan Tseng 2016/08/18 18:12:45 Done.
37 » commits, err := git.GetCommits(c, def.Repository, def.Branch, 25) 39 // that builder will be removed from list of results.
40 func getConsoleDef(c context.Context, project, name string) (*config.Console, er ror) {
41 » if name == "" {
42 » » name = "default"
estaab 2016/08/18 15:51:46 Can you mention something about this? What is the
Ryan Tseng 2016/08/18 18:12:45 Done.
43 » }
44 » cs, err := settings.GetConsole(c, project, name)
38 if err != nil { 45 if err != nil {
39 return nil, err 46 return nil, err
40 } 47 }
48 // TODO(hinoka): Remove builders that the user does not have access to.
49 return cs, nil
50 }
51
52 func console(c context.Context, project, name string) (*resp.Console, error) {
53 tStart := clock.Now(c)
54 def, err := getConsoleDef(c, project, name)
55 if err != nil {
56 return nil, err
57 }
58 commits, err := git.GetCommits(c, def.RepoURL, def.Branch, 25)
59 if err != nil {
60 return nil, err
61 }
41 tGitiles := clock.Now(c) 62 tGitiles := clock.Now(c)
42 log.Debugf(c, "Loading commits took %s.", tGitiles.Sub(tStart)) 63 log.Debugf(c, "Loading commits took %s.", tGitiles.Sub(tStart))
43 commitNames := make([]string, len(commits)) 64 commitNames := make([]string, len(commits))
44 for i, commit := range commits { 65 for i, commit := range commits {
45 commitNames[i] = commit.Revision 66 commitNames[i] = commit.Revision
46 } 67 }
47 68
48 // HACK(hinoka): This only supports buildbot.... 69 // HACK(hinoka): This only supports buildbot....
49 builders := make([]resp.BuilderRef, len(def.Builders)) 70 builders := make([]resp.BuilderRef, len(def.Builders))
50 for i, b := range def.Builders { 71 for i, b := range def.Builders {
(...skipping 15 matching lines...) Expand all
66 } 87 }
67 88
68 cs := &resp.Console{ 89 cs := &resp.Console{
69 Name: def.Name, 90 Name: def.Name,
70 Commit: ccb, 91 Commit: ccb,
71 BuilderRef: builders, 92 BuilderRef: builders,
72 } 93 }
73 94
74 return cs, nil 95 return cs, nil
75 } 96 }
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