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

Unified Diff: appengine/cmd/milo/console/console.go

Issue 2196453002: Milo: Console view prototype (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-go@master
Patch Set: Reviews 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 side-by-side diff with in-line comments
Download patch
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..cf727f4bc732a1f9ac277dc235362f529b02ec90
--- /dev/null
+++ b/appengine/cmd/milo/console/console.go
@@ -0,0 +1,75 @@
+// 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"
+)
+
+// 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)
+ // The case for buildbucket and dm goes here.
+ default:
+ panic(fmt.Errorf("Unrecognized module %s", module))
+ }
+}
+
+func console(c context.Context, def *ConsoleDef) (*resp.Console, error) {
+ 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, 25)
+ if err != nil {
+ return nil, err
+ }
+ tGitiles := clock.Now(c)
+ log.Debugf(c, "Loading commits took %s.", tGitiles.Sub(tStart))
+ commitNames := make([]string, len(commits))
+ for i, commit := range commits {
+ commitNames[i] = commit.Revision
+ }
+
+ // HACK(hinoka): This only supports buildbot....
+ builders := make([]resp.BuilderRef, len(def.Builders))
+ for i, b := range def.Builders {
+ builders[i] = resp.BuilderRef{
+ b.Module, b.Name, strings.Split(b.Category, "|"), b.ShortName,
+ }
+ }
+ cb, err := GetConsoleBuilds(c, "buildbot", builders, commitNames)
+ tConsole := clock.Now(c)
+ log.Debugf(c, "Loading the console took a total of %s.", tConsole.Sub(tGitiles))
+ 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: builders,
+ }
+
+ return cs, nil
+}

Powered by Google App Engine
This is Rietveld 408576698