| OLD | NEW |
| 1 // Copyright 2017 The LUCI Authors. | 1 // Copyright 2017 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 frontend | 15 package frontend |
| 16 | 16 |
| 17 import ( | 17 import ( |
| 18 "encoding/hex" | 18 "encoding/hex" |
| 19 "fmt" | 19 "fmt" |
| 20 "html/template" | 20 "html/template" |
| 21 "net/http" | 21 "net/http" |
| 22 "strings" | |
| 23 | 22 |
| 24 "golang.org/x/net/context" | 23 "golang.org/x/net/context" |
| 25 | 24 |
| 26 "github.com/luci/luci-go/common/clock" | 25 "github.com/luci/luci-go/common/clock" |
| 27 "github.com/luci/luci-go/common/errors" | 26 "github.com/luci/luci-go/common/errors" |
| 28 "github.com/luci/luci-go/common/logging" | 27 "github.com/luci/luci-go/common/logging" |
| 29 "github.com/luci/luci-go/common/proto/google" | 28 "github.com/luci/luci-go/common/proto/google" |
| 30 "github.com/luci/luci-go/server/router" | 29 "github.com/luci/luci-go/server/router" |
| 31 "github.com/luci/luci-go/server/templates" | 30 "github.com/luci/luci-go/server/templates" |
| 32 | 31 |
| 33 "github.com/luci/luci-go/milo/api/config" | |
| 34 "github.com/luci/luci-go/milo/api/resp" | 32 "github.com/luci/luci-go/milo/api/resp" |
| 35 "github.com/luci/luci-go/milo/buildsource" | 33 "github.com/luci/luci-go/milo/buildsource" |
| 36 "github.com/luci/luci-go/milo/common" | 34 "github.com/luci/luci-go/milo/common" |
| 37 "github.com/luci/luci-go/milo/common/model" | 35 "github.com/luci/luci-go/milo/common/model" |
| 38 "github.com/luci/luci-go/milo/git" | 36 "github.com/luci/luci-go/milo/git" |
| 39 ) | 37 ) |
| 40 | 38 |
| 41 // getConsoleDef finds the console definition as defined by any project. | 39 // getConsoleDef finds the console definition as defined by any project. |
| 42 // If the user is not a reader of the project, this will return a 404. | 40 // If the user is not a reader of the project, this will return a 404. |
| 43 // TODO(hinoka): If the user is not a reader of any of of the builders returned, | 41 // TODO(hinoka): If the user is not a reader of any of of the builders returned, |
| 44 // that builder will be removed from list of results. | 42 // that builder will be removed from list of results. |
| 45 func getConsoleDef(c context.Context, project, name string) (*config.Console, er
ror) { | 43 func getConsoleDef(c context.Context, project, name string) (*common.Console, er
ror) { |
| 46 cs, err := common.GetConsole(c, project, name) | 44 cs, err := common.GetConsole(c, project, name) |
| 47 if err != nil { | 45 if err != nil { |
| 48 return nil, err | 46 return nil, err |
| 49 } | 47 } |
| 50 // TODO(hinoka): Remove builders that the user does not have access to. | 48 // TODO(hinoka): Remove builders that the user does not have access to. |
| 51 return cs, nil | 49 return cs, nil |
| 52 } | 50 } |
| 53 | 51 |
| 54 func console(c context.Context, project, name string) (*resp.Console, error) { | 52 func console(c context.Context, project, name string) (*resp.Console, error) { |
| 55 tStart := clock.Now(c) | 53 tStart := clock.Now(c) |
| 56 def, err := getConsoleDef(c, project, name) | 54 def, err := getConsoleDef(c, project, name) |
| 57 if err != nil { | 55 if err != nil { |
| 58 return nil, err | 56 return nil, err |
| 59 } | 57 } |
| 60 » commitInfo, err := git.GetHistory(c, def.RepoURL, def.Branch, 25) | 58 » commitInfo, err := git.GetHistory(c, def.RepoURL, def.Ref, 25) |
| 61 if err != nil { | 59 if err != nil { |
| 62 return nil, err | 60 return nil, err |
| 63 } | 61 } |
| 64 tGitiles := clock.Now(c) | 62 tGitiles := clock.Now(c) |
| 65 logging.Debugf(c, "Loading commits took %s.", tGitiles.Sub(tStart)) | 63 logging.Debugf(c, "Loading commits took %s.", tGitiles.Sub(tStart)) |
| 66 | 64 |
| 67 builderNames := make([]string, len(def.Builders)) | 65 builderNames := make([]string, len(def.Builders)) |
| 68 builders := make([]resp.BuilderRef, len(def.Builders)) | 66 builders := make([]resp.BuilderRef, len(def.Builders)) |
| 69 for i, b := range def.Builders { | 67 for i, b := range def.Builders { |
| 70 » » builderNames[i] = b.Name | 68 » » builderNames[i] = b |
| 71 » » builders[i].Name = b.Name | 69 » » builders[i].Name = b |
| 72 » » builders[i].Category = strings.Split(b.Category, "|") | 70 » » // TODO(hinoka): Add Categories and ShortNames back in. |
| 73 » » builders[i].ShortName = b.ShortName | |
| 74 } | 71 } |
| 75 | 72 |
| 76 commitNames := make([]string, len(commitInfo.Commits)) | 73 commitNames := make([]string, len(commitInfo.Commits)) |
| 77 for i, commit := range commitInfo.Commits { | 74 for i, commit := range commitInfo.Commits { |
| 78 commitNames[i] = hex.EncodeToString(commit.Hash) | 75 commitNames[i] = hex.EncodeToString(commit.Hash) |
| 79 } | 76 } |
| 80 rows, err := buildsource.GetConsoleRows(c, project, def, commitNames, bu
ilderNames) | 77 rows, err := buildsource.GetConsoleRows(c, project, def, commitNames, bu
ilderNames) |
| 81 tConsole := clock.Now(c) | 78 tConsole := clock.Now(c) |
| 82 logging.Debugf(c, "Loading the console took a total of %s.", tConsole.Su
b(tGitiles)) | 79 logging.Debugf(c, "Loading the console took a total of %s.", tConsole.Su
b(tGitiles)) |
| 83 if err != nil { | 80 if err != nil { |
| 84 return nil, err | 81 return nil, err |
| 85 } | 82 } |
| 86 | 83 |
| 87 ccb := make([]resp.CommitBuild, len(commitInfo.Commits)) | 84 ccb := make([]resp.CommitBuild, len(commitInfo.Commits)) |
| 88 for row, commit := range commitInfo.Commits { | 85 for row, commit := range commitInfo.Commits { |
| 89 ccb[row].Build = make([]*model.BuildSummary, len(builders)) | 86 ccb[row].Build = make([]*model.BuildSummary, len(builders)) |
| 90 ccb[row].Commit = resp.Commit{ | 87 ccb[row].Commit = resp.Commit{ |
| 91 AuthorName: commit.AuthorName, | 88 AuthorName: commit.AuthorName, |
| 92 AuthorEmail: commit.AuthorEmail, | 89 AuthorEmail: commit.AuthorEmail, |
| 93 CommitTime: google.TimeFromProto(commit.CommitTime), | 90 CommitTime: google.TimeFromProto(commit.CommitTime), |
| 94 Repo: def.RepoURL, | 91 Repo: def.RepoURL, |
| 95 » » » Branch: def.Branch, | 92 » » » Branch: def.Ref, // TODO(hinoka): Actually this doe
sn't match, change branch to ref. |
| 96 Description: commit.Msg, | 93 Description: commit.Msg, |
| 97 Revision: resp.NewLink(commitNames[row], def.RepoURL+
"/+/"+commitNames[row]), | 94 Revision: resp.NewLink(commitNames[row], def.RepoURL+
"/+/"+commitNames[row]), |
| 98 } | 95 } |
| 99 | 96 |
| 100 for col, b := range builders { | 97 for col, b := range builders { |
| 101 name := buildsource.BuilderID(b.Name) | 98 name := buildsource.BuilderID(b.Name) |
| 102 if summaries := rows[row].Builds[name]; len(summaries) >
0 { | 99 if summaries := rows[row].Builds[name]; len(summaries) >
0 { |
| 103 ccb[row].Build[col] = summaries[0] | 100 ccb[row].Build[col] = summaries[0] |
| 104 } | 101 } |
| 105 } | 102 } |
| 106 } | 103 } |
| 107 | 104 |
| 108 return &resp.Console{ | 105 return &resp.Console{ |
| 109 » » Name: def.Name, | 106 » » Name: def.ID, |
| 110 Commit: ccb, | 107 Commit: ccb, |
| 111 BuilderRef: builders, | 108 BuilderRef: builders, |
| 112 }, nil | 109 }, nil |
| 113 } | 110 } |
| 114 | 111 |
| 115 // consoleRenderer is a wrapper around Console to provide additional methods. | 112 // consoleRenderer is a wrapper around Console to provide additional methods. |
| 116 type consoleRenderer struct { | 113 type consoleRenderer struct { |
| 117 *resp.Console | 114 *resp.Console |
| 118 } | 115 } |
| 119 | 116 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 } | 192 } |
| 196 | 193 |
| 197 // ConsoleMainHandler is a redirect handler that redirects the user to the main | 194 // ConsoleMainHandler is a redirect handler that redirects the user to the main |
| 198 // console for a particular project. | 195 // console for a particular project. |
| 199 func ConsoleMainHandler(ctx *router.Context) { | 196 func ConsoleMainHandler(ctx *router.Context) { |
| 200 w, r, p := ctx.Writer, ctx.Request, ctx.Params | 197 w, r, p := ctx.Writer, ctx.Request, ctx.Params |
| 201 proj := p.ByName("project") | 198 proj := p.ByName("project") |
| 202 http.Redirect(w, r, fmt.Sprintf("/console/%s/main", proj), http.StatusMo
vedPermanently) | 199 http.Redirect(w, r, fmt.Sprintf("/console/%s/main", proj), http.StatusMo
vedPermanently) |
| 203 return | 200 return |
| 204 } | 201 } |
| OLD | NEW |