Chromium Code Reviews| Index: appengine/cmd/milo/console/console.go |
| diff --git a/appengine/cmd/milo/console/console.go b/appengine/cmd/milo/console/console.go |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..54b6ec00809d165712b6f5f7cd771e2c2a677499 |
| --- /dev/null |
| +++ b/appengine/cmd/milo/console/console.go |
| @@ -0,0 +1,82 @@ |
| +// Copyright 2016 The LUCI Authors. All rights reserved. |
| +// Use of this source code is governed under the Apache License, Version 2.0 |
| +// that can be found in the LICENSE file. |
| + |
| +package console |
| + |
| +import ( |
| + "fmt" |
| + "strings" |
| + |
| + "github.com/luci/luci-go/appengine/cmd/milo/buildbot" |
| + "github.com/luci/luci-go/appengine/cmd/milo/git" |
| + "github.com/luci/luci-go/appengine/cmd/milo/resp" |
| + "github.com/luci/luci-go/common/clock" |
| + log "github.com/luci/luci-go/common/logging" |
| + "golang.org/x/net/context" |
| +) |
| + |
| +func resolveBuilders(c context.Context, builderSpec []string) []resp.BuilderRef { |
|
estaab
2016/08/04 23:21:24
what's the format of builderSpec? Should this be a
hinoka
2016/08/05 00:10:42
Oops dead code...
|
| + result := []resp.BuilderRef{} |
| + for _, spec := range builderSpec { |
| + j := strings.SplitN(spec, "/", 2) |
| + result = append(result, resp.BuilderRef{ |
| + Module: j[0], |
| + Name: j[1], |
| + }) |
| + } |
| + return result |
| +} |
| + |
| +// Returns results of build[commit_index][builder_index] |
| +func GetConsoleBuilds( |
| + c context.Context, module string, |
| + builders []resp.BuilderRef, commits []string) ( |
| + [][]*resp.ConsoleBuild, error) { |
| + |
| + switch module { |
| + case "buildbot": |
| + return buildbot.GetConsoleBuilds(c, builders, commits) |
| + //case "buildbucket": |
|
estaab
2016/08/04 23:21:24
remove commented code
hinoka
2016/08/05 00:10:42
Done.
|
| + // return buildbucket.getConsoleBuilds(c, builders, commits) |
| + default: |
| + panic(fmt.Errorf("Unrecognized module %s", module)) |
| + } |
| +} |
| + |
| +func console(c context.Context, def *ConsoleDef) (*resp.Console, error) { |
|
estaab
2016/08/04 23:21:24
How much of this do you want to keep? I want to kn
hinoka
2016/08/05 00:10:42
Parts I'm keeping:
* Interface between console/con
|
| + tStart := clock.Now(c) |
| + // Lookup Commits. For this hack, we're just gonna hardcode src.git |
| + commits, err := git.GetCommits(c, def.Repository, def.Branch) |
| + if err != nil { |
| + return nil, err |
| + } |
| + tGerrit := clock.Now(c) |
|
nodir
2016/08/04 23:13:13
it is gitiles, not gerrit
hinoka
2016/08/05 00:10:42
Done.
|
| + log.Debugf(c, "Loading commits took %s.", tGerrit.Sub(tStart)) |
| + commitNames := make([]string, len(commits)) |
| + for i, commit := range commits { |
| + commitNames[i] = commit.Revision |
| + } |
| + |
| + // HACK(hinoka): This only supports buildbot.... |
| + cb, err := GetConsoleBuilds(c, "buildbot", def.Builders, commitNames) |
| + tConsole := clock.Now(c) |
| + log.Debugf(c, "Loading the console took a total of %s.", tConsole.Sub(tGerrit)) |
| + if err != nil { |
| + return nil, err |
| + } |
| + ccb := make([]resp.CommitBuild, len(commits)) |
| + for i, commit := range commitNames { |
| + // TODO(hinoka): Not like this |
| + ccb[i].Commit = resp.Commit{Revision: commit} |
| + ccb[i].Build = cb[i] |
| + } |
| + |
| + cs := &resp.Console{ |
| + Name: def.Name, |
| + Commit: ccb, |
| + BuilderRef: def.Builders, |
| + } |
| + |
| + return cs, nil |
| +} |