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..29460ea50a04ec2eef5e271b2dd88e844a610974 |
| --- /dev/null |
| +++ b/appengine/cmd/milo/console/console.go |
| @@ -0,0 +1,94 @@ |
| +// 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 { |
| + 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": |
| + // return buildbucket.getConsoleBuilds(c, builders, commits) |
| + default: |
| + panic(fmt.Errorf("Unrecognized module %s", module)) |
|
nodir
2016/08/03 20:26:17
a panic kinda implies that the caller really knows
hinoka
2016/08/03 21:55:39
The idea of this function is to map strings to lin
|
| + } |
| +} |
| + |
| +func common(current *resp.BuilderGroup, path string) int { |
| + result := 0 |
| + g := strings.Split(current.FullPath, "|") |
| + for i, s := range strings.Split(path, "|") { |
| + if i < len(g) && g[i] == s { |
| + result++ |
| + } else { |
| + break |
| + } |
| + } |
| + return result |
| +} |
| + |
| +func console(c context.Context, def *ConsoleDef) ( |
| + *resp.Console, error) { |
|
nodir
2016/08/03 20:26:17
i think it would fit prev line
hinoka
2016/08/03 21:55:40
Done.
|
| + t1 := 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 |
| + } |
| + t2 := clock.Now(c) |
|
nodir
2016/08/03 20:26:17
please give more meaning full names to t variables
hinoka
2016/08/03 21:55:40
Done.
|
| + log.Debugf(c, fmt.Sprintf("Gerrit took %f seconds.", t2.Sub(t1).Seconds())) |
|
nodir
2016/08/03 20:26:17
use native representation of durations:
took %s",
nodir
2016/08/03 20:26:17
s/Gerrit/Loading commits/
nodir
2016/08/03 20:26:17
log.Debugf accepts a format string, so no need for
hinoka
2016/08/03 21:55:40
Done.
|
| + 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) |
|
nodir
2016/08/03 20:26:17
time it?
hinoka
2016/08/03 21:55:40
Done.
|
| + 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 |
| +} |