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

Side by Side 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: Rebase fix 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 unified diff | Download patch
OLDNEW
(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 func resolveBuilders(c context.Context, builderSpec []string) []resp.BuilderRef {
20 result := []resp.BuilderRef{}
21 for _, spec := range builderSpec {
22 j := strings.SplitN(spec, "/", 2)
23 result = append(result, resp.BuilderRef{
24 Module: j[0],
25 Name: j[1],
26 })
27 }
28 return result
29 }
30
31 // Returns results of build[commit_index][builder_index]
32 func GetConsoleBuilds(
33 c context.Context, module string,
34 builders []resp.BuilderRef, commits []string) (
35 [][]*resp.ConsoleBuild, error) {
36
37 switch module {
38 case "buildbot":
39 return buildbot.GetConsoleBuilds(c, builders, commits)
40 //case "buildbucket":
41 // return buildbucket.getConsoleBuilds(c, builders, commits)
42 default:
43 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
44 }
45 }
46
47 func common(current *resp.BuilderGroup, path string) int {
48 result := 0
49 g := strings.Split(current.FullPath, "|")
50 for i, s := range strings.Split(path, "|") {
51 if i < len(g) && g[i] == s {
52 result++
53 } else {
54 break
55 }
56 }
57 return result
58 }
59
60 func console(c context.Context, def *ConsoleDef) (
61 *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.
62 t1 := clock.Now(c)
63 // Lookup Commits. For this hack, we're just gonna hardcode src.git
64 commits, err := git.GetCommits(c, def.Repository, def.Branch)
65 if err != nil {
66 return nil, err
67 }
68 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.
69 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.
70 commitNames := make([]string, len(commits))
71 for i, commit := range commits {
72 commitNames[i] = commit.Revision
73 }
74
75 // HACK(hinoka): This only supports buildbot....
76 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.
77 if err != nil {
78 return nil, err
79 }
80 ccb := make([]resp.CommitBuild, len(commits))
81 for i, commit := range commitNames {
82 // TODO(hinoka): Not like this
83 ccb[i].Commit = resp.Commit{Revision: commit}
84 ccb[i].Build = cb[i]
85 }
86
87 cs := &resp.Console{
88 Name: def.Name,
89 Commit: ccb,
90 BuilderRef: def.Builders,
91 }
92
93 return cs, nil
94 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698