| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. |
| 4 |
| 5 package console |
| 6 |
| 7 import ( |
| 8 "fmt" |
| 9 "strings" |
| 10 |
| 11 "github.com/luci/luci-go/appengine/cmd/milo/buildbot" |
| 12 "github.com/luci/luci-go/appengine/cmd/milo/git" |
| 13 "github.com/luci/luci-go/appengine/cmd/milo/resp" |
| 14 "github.com/luci/luci-go/common/clock" |
| 15 log "github.com/luci/luci-go/common/logging" |
| 16 "golang.org/x/net/context" |
| 17 ) |
| 18 |
| 19 // Returns results of build[commit_index][builder_index] |
| 20 func GetConsoleBuilds( |
| 21 c context.Context, module string, |
| 22 builders []resp.BuilderRef, commits []string) ( |
| 23 [][]*resp.ConsoleBuild, error) { |
| 24 |
| 25 switch module { |
| 26 case "buildbot": |
| 27 return buildbot.GetConsoleBuilds(c, builders, commits) |
| 28 // The case for buildbucket and dm goes here. |
| 29 default: |
| 30 panic(fmt.Errorf("Unrecognized module %s", module)) |
| 31 } |
| 32 } |
| 33 |
| 34 func console(c context.Context, def *ConsoleDef) (*resp.Console, error) { |
| 35 tStart := clock.Now(c) |
| 36 // Lookup Commits. For this hack, we're just gonna hardcode src.git |
| 37 commits, err := git.GetCommits(c, def.Repository, def.Branch, 25) |
| 38 if err != nil { |
| 39 return nil, err |
| 40 } |
| 41 tGitiles := clock.Now(c) |
| 42 log.Debugf(c, "Loading commits took %s.", tGitiles.Sub(tStart)) |
| 43 commitNames := make([]string, len(commits)) |
| 44 for i, commit := range commits { |
| 45 commitNames[i] = commit.Revision |
| 46 } |
| 47 |
| 48 // HACK(hinoka): This only supports buildbot.... |
| 49 builders := make([]resp.BuilderRef, len(def.Builders)) |
| 50 for i, b := range def.Builders { |
| 51 builders[i] = resp.BuilderRef{ |
| 52 b.Module, b.Name, strings.Split(b.Category, "|"), b.Shor
tName, |
| 53 } |
| 54 } |
| 55 cb, err := GetConsoleBuilds(c, "buildbot", builders, commitNames) |
| 56 tConsole := clock.Now(c) |
| 57 log.Debugf(c, "Loading the console took a total of %s.", tConsole.Sub(tG
itiles)) |
| 58 if err != nil { |
| 59 return nil, err |
| 60 } |
| 61 ccb := make([]resp.CommitBuild, len(commits)) |
| 62 for i, commit := range commitNames { |
| 63 // TODO(hinoka): Not like this |
| 64 ccb[i].Commit = resp.Commit{Revision: commit} |
| 65 ccb[i].Build = cb[i] |
| 66 } |
| 67 |
| 68 cs := &resp.Console{ |
| 69 Name: def.Name, |
| 70 Commit: ccb, |
| 71 BuilderRef: builders, |
| 72 } |
| 73 |
| 74 return cs, nil |
| 75 } |
| OLD | NEW |