Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 // 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) | 39 // that builder will be removed from list of results. |
| 40 // If no name is specified (ie the user hits a url /console/<project>), the | |
| 41 // default console for that project (named "default") will be looked up. | |
|
estaab
2016/08/18 23:19:37
Should we 302 redirect to the actual console url s
Ryan Tseng
2016/08/18 23:55:30
Hm okay. In that case i'll name it something nice
| |
| 42 func getConsoleDef(c context.Context, project, name string) (*config.Console, er ror) { | |
| 43 » if name == "" { | |
| 44 » » name = "default" | |
| 45 » } | |
| 46 » cs, err := settings.GetConsole(c, project, name) | |
| 38 if err != nil { | 47 if err != nil { |
| 39 return nil, err | 48 return nil, err |
| 40 } | 49 } |
| 50 // TODO(hinoka): Remove builders that the user does not have access to. | |
| 51 return cs, nil | |
| 52 } | |
| 53 | |
| 54 func console(c context.Context, project, name string) (*resp.Console, error) { | |
| 55 tStart := clock.Now(c) | |
| 56 def, err := getConsoleDef(c, project, name) | |
| 57 if err != nil { | |
| 58 return nil, err | |
| 59 } | |
| 60 commits, err := git.GetCommits(c, def.RepoURL, def.Branch, 25) | |
| 61 if err != nil { | |
| 62 return nil, err | |
| 63 } | |
| 41 tGitiles := clock.Now(c) | 64 tGitiles := clock.Now(c) |
| 42 log.Debugf(c, "Loading commits took %s.", tGitiles.Sub(tStart)) | 65 log.Debugf(c, "Loading commits took %s.", tGitiles.Sub(tStart)) |
| 43 commitNames := make([]string, len(commits)) | 66 commitNames := make([]string, len(commits)) |
| 44 for i, commit := range commits { | 67 for i, commit := range commits { |
| 45 commitNames[i] = commit.Revision | 68 commitNames[i] = commit.Revision |
| 46 } | 69 } |
| 47 | 70 |
| 48 // HACK(hinoka): This only supports buildbot.... | 71 // HACK(hinoka): This only supports buildbot.... |
| 49 builders := make([]resp.BuilderRef, len(def.Builders)) | 72 builders := make([]resp.BuilderRef, len(def.Builders)) |
| 50 for i, b := range def.Builders { | 73 for i, b := range def.Builders { |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 66 } | 89 } |
| 67 | 90 |
| 68 cs := &resp.Console{ | 91 cs := &resp.Console{ |
| 69 Name: def.Name, | 92 Name: def.Name, |
| 70 Commit: ccb, | 93 Commit: ccb, |
| 71 BuilderRef: builders, | 94 BuilderRef: builders, |
| 72 } | 95 } |
| 73 | 96 |
| 74 return cs, nil | 97 return cs, nil |
| 75 } | 98 } |
| OLD | NEW |