| OLD | NEW |
| 1 // Copyright 2016 The LUCI Authors. | 1 // Copyright 2016 The LUCI Authors. |
| 2 // | 2 // |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
| 5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
| 6 // | 6 // |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 // | 8 // |
| 9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 // See the License for the specific language governing permissions and | 12 // See the License for the specific language governing permissions and |
| 13 // limitations under the License. | 13 // limitations under the License. |
| 14 | 14 |
| 15 package console | 15 package console |
| 16 | 16 |
| 17 import ( | 17 import ( |
| 18 "fmt" | 18 "fmt" |
| 19 "net/http" | 19 "net/http" |
| 20 "strings" | 20 "strings" |
| 21 | 21 |
| 22 "golang.org/x/net/context" | 22 "golang.org/x/net/context" |
| 23 | 23 |
| 24 "github.com/luci/luci-go/common/api/gitiles" |
| 24 "github.com/luci/luci-go/common/clock" | 25 "github.com/luci/luci-go/common/clock" |
| 25 "github.com/luci/luci-go/common/logging" | 26 "github.com/luci/luci-go/common/logging" |
| 26 "github.com/luci/luci-go/milo/api/config" | 27 "github.com/luci/luci-go/milo/api/config" |
| 27 "github.com/luci/luci-go/milo/api/resp" | 28 "github.com/luci/luci-go/milo/api/resp" |
| 28 "github.com/luci/luci-go/milo/common" | 29 "github.com/luci/luci-go/milo/common" |
| 29 "github.com/luci/luci-go/milo/common/gitiles" | |
| 30 "github.com/luci/luci-go/milo/common/model" | 30 "github.com/luci/luci-go/milo/common/model" |
| 31 "github.com/luci/luci-go/server/router" | 31 "github.com/luci/luci-go/server/router" |
| 32 ) | 32 ) |
| 33 | 33 |
| 34 // Returns results of build[commit_index][builder_index] | 34 // Returns results of build[commit_index][builder_index] |
| 35 func GetConsoleBuilds( | 35 func GetConsoleBuilds( |
| 36 c context.Context, builders []resp.BuilderRef, commits []string) ( | 36 c context.Context, builders []resp.BuilderRef, commits []string) ( |
| 37 [][]*model.BuildSummary, error) { | 37 [][]*model.BuildSummary, error) { |
| 38 | 38 |
| 39 panic("Nothing to see here, check back later.") | 39 panic("Nothing to see here, check back later.") |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 } | 72 } |
| 73 return cb | 73 return cb |
| 74 } | 74 } |
| 75 | 75 |
| 76 func console(c context.Context, project, name string) (*resp.Console, error) { | 76 func console(c context.Context, project, name string) (*resp.Console, error) { |
| 77 tStart := clock.Now(c) | 77 tStart := clock.Now(c) |
| 78 def, err := getConsoleDef(c, project, name) | 78 def, err := getConsoleDef(c, project, name) |
| 79 if err != nil { | 79 if err != nil { |
| 80 return nil, err | 80 return nil, err |
| 81 } | 81 } |
| 82 » commits, err := gitiles.GetCommits(c, def.RepoURL, def.Branch, 25) | 82 » commits, err := getCommits(c, def.RepoURL, def.Branch, 25) |
| 83 if err != nil { | 83 if err != nil { |
| 84 return nil, err | 84 return nil, err |
| 85 } | 85 } |
| 86 tGitiles := clock.Now(c) | 86 tGitiles := clock.Now(c) |
| 87 logging.Debugf(c, "Loading commits took %s.", tGitiles.Sub(tStart)) | 87 logging.Debugf(c, "Loading commits took %s.", tGitiles.Sub(tStart)) |
| 88 commitNames := make([]string, len(commits)) | 88 commitNames := make([]string, len(commits)) |
| 89 commitLinks := make([]*resp.Link, len(commits)) | 89 commitLinks := make([]*resp.Link, len(commits)) |
| 90 for i, commit := range commits { | 90 for i, commit := range commits { |
| 91 commitNames[i] = commit.Revision.Label | 91 commitNames[i] = commit.Revision.Label |
| 92 commitLinks[i] = commit.Revision | 92 commitLinks[i] = commit.Revision |
| (...skipping 20 matching lines...) Expand all Loading... |
| 113 } | 113 } |
| 114 | 114 |
| 115 cs := &resp.Console{ | 115 cs := &resp.Console{ |
| 116 Name: def.Name, | 116 Name: def.Name, |
| 117 Commit: ccb, | 117 Commit: ccb, |
| 118 BuilderRef: builders, | 118 BuilderRef: builders, |
| 119 } | 119 } |
| 120 | 120 |
| 121 return cs, nil | 121 return cs, nil |
| 122 } | 122 } |
| 123 |
| 124 func getCommits(c context.Context, repoURL, treeish string, limit int) ([]resp.C
ommit, error) { |
| 125 commits, err := gitiles.Log(c, repoURL, treeish, limit) |
| 126 if err != nil { |
| 127 return nil, err |
| 128 } |
| 129 result := make([]resp.Commit, len(commits)) |
| 130 for i, log := range commits { |
| 131 result[i] = resp.Commit{ |
| 132 AuthorName: log.Author.Name, |
| 133 AuthorEmail: log.Author.Email, |
| 134 Repo: repoURL, |
| 135 Revision: resp.NewLink(log.Commit, repoURL+"/+/"+log.
Commit), |
| 136 Description: log.Message, |
| 137 Title: strings.SplitN(log.Message, "\n", 2)[0], |
| 138 // TODO(hinoka): Fill in the rest of resp.Commit and add
those details |
| 139 // in the html. |
| 140 } |
| 141 } |
| 142 return result, nil |
| 143 } |
| OLD | NEW |