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

Side by Side Diff: milo/appengine/swarming/html.go

Issue 2748073006: Milo Refactor: Remove theme support (Closed)
Patch Set: Fix tests Created 3 years, 9 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
1 // Copyright 2015 The LUCI Authors. All rights reserved. 1 // Copyright 2015 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0 2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file. 3 // that can be found in the LICENSE file.
4 4
5 package swarming 5 package swarming
6 6
7 import ( 7 import (
8 "net/http" 8 "net/http"
9 "os" 9 "os"
10 10
11 "github.com/julienschmidt/httprouter" 11 "github.com/julienschmidt/httprouter"
12 "golang.org/x/net/context" 12 "golang.org/x/net/context"
13 "google.golang.org/api/googleapi" 13 "google.golang.org/api/googleapi"
14 14
15 "github.com/luci/luci-go/milo/appengine/settings"
16 "github.com/luci/luci-go/milo/common/miloerror" 15 "github.com/luci/luci-go/milo/common/miloerror"
17 "github.com/luci/luci-go/server/templates" 16 "github.com/luci/luci-go/server/templates"
18 ) 17 )
19 18
20 const ( 19 const (
21 defaultSwarmingServer = "chromium-swarm.appspot.com" 20 defaultSwarmingServer = "chromium-swarm.appspot.com"
22 defaultSwarmingDevServer = "chromium-swarm-dev.appspot.com" 21 defaultSwarmingDevServer = "chromium-swarm-dev.appspot.com"
23 ) 22 )
24 23
25 func getSwarmingHost(r *http.Request) string { 24 func getSwarmingHost(r *http.Request) string {
(...skipping 17 matching lines...) Expand all
43 return newProdService(c, host) 42 return newProdService(c, host)
44 43
45 default: 44 default:
46 return nil, &miloerror.Error{ 45 return nil, &miloerror.Error{
47 Message: "unregistered Swarming host", 46 Message: "unregistered Swarming host",
48 Code: http.StatusNotFound, 47 Code: http.StatusNotFound,
49 } 48 }
50 } 49 }
51 } 50 }
52 51
53 // Log is for fetching logs from swarming.
54 type Log struct{}
55
56 // Build is for deciphering recipe builds from swarming based off of logs. 52 // Build is for deciphering recipe builds from swarming based off of logs.
57 type Build struct { 53 type Build struct {
58 // bl is the buildLoader to use. A zero value is suitable for production , but 54 // bl is the buildLoader to use. A zero value is suitable for production , but
59 // this can be overridden for testing. 55 // this can be overridden for testing.
60 bl buildLoader 56 bl buildLoader
61 } 57 }
62 58
63 // GetTemplateName for Log returns the template name for log pages. 59 // LogHandler writes the build log to the given response writer.
64 func (l Log) GetTemplateName(t settings.Theme) string { 60 func LogHandler(c context.Context, r *http.Request, p httprouter.Params) (*templ ates.Args, error) {
65 » return "log.html"
66 }
67
68 // Render writes the build log to the given response writer.
69 func (l Log) Render(c context.Context, r *http.Request, p httprouter.Params) (*t emplates.Args, error) {
70 id := p.ByName("id") 61 id := p.ByName("id")
71 if id == "" { 62 if id == "" {
72 return nil, &miloerror.Error{ 63 return nil, &miloerror.Error{
73 Message: "No id", 64 Message: "No id",
74 Code: http.StatusBadRequest, 65 Code: http.StatusBadRequest,
75 } 66 }
76 } 67 }
77 logname := p.ByName("logname") 68 logname := p.ByName("logname")
78 if logname == "" { 69 if logname == "" {
79 return nil, &miloerror.Error{ 70 return nil, &miloerror.Error{
(...skipping 12 matching lines...) Expand all
92 return nil, convertErr(err) 83 return nil, convertErr(err)
93 } 84 }
94 85
95 args := &templates.Args{ 86 args := &templates.Args{
96 "Log": log, 87 "Log": log,
97 "Closed": closed, 88 "Closed": closed,
98 } 89 }
99 return args, nil 90 return args, nil
100 } 91 }
101 92
102 // GetTemplateName for Build returns the template name for build pages. 93 func BuildHandler(c context.Context, r *http.Request, p httprouter.Params) (*tem plates.Args, error) {
103 func (b Build) GetTemplateName(t settings.Theme) string { 94 » return (Build{}).handler(c, r, p)
104 » return "build.html"
105 } 95 }
106 96
107 // Render renders both the build page and the log. 97 // Render renders both the build page and the log.
108 func (b Build) Render(c context.Context, r *http.Request, p httprouter.Params) ( *templates.Args, error) { 98 func (b Build) handler(c context.Context, r *http.Request, p httprouter.Params) (*templates.Args, error) {
109 // Get the swarming ID 99 // Get the swarming ID
110 id := p.ByName("id") 100 id := p.ByName("id")
111 if id == "" { 101 if id == "" {
112 return nil, &miloerror.Error{ 102 return nil, &miloerror.Error{
113 Message: "No id", 103 Message: "No id",
114 Code: http.StatusBadRequest, 104 Code: http.StatusBadRequest,
115 } 105 }
116 } 106 }
117 107
118 sf, err := getSwarmingService(c, getSwarmingHost(r)) 108 sf, err := getSwarmingService(c, getSwarmingHost(r))
(...skipping 24 matching lines...) Expand all
143 } 133 }
144 134
145 // isAPINotFound returns true if err is a HTTP 404 API response. 135 // isAPINotFound returns true if err is a HTTP 404 API response.
146 func isAPINotFound(err error) bool { 136 func isAPINotFound(err error) bool {
147 if apiErr, ok := err.(*googleapi.Error); ok && apiErr.Code == http.Statu sNotFound { 137 if apiErr, ok := err.(*googleapi.Error); ok && apiErr.Code == http.Statu sNotFound {
148 return true 138 return true
149 } 139 }
150 140
151 return false 141 return false
152 } 142 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698