go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/milo/frontend/view_build_legacy.go (about) 1 // Copyright 2018 The LUCI Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (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 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package frontend 16 17 import ( 18 "fmt" 19 "net/http" 20 "strings" 21 22 "github.com/julienschmidt/httprouter" 23 24 buildbucketpb "go.chromium.org/luci/buildbucket/proto" 25 "go.chromium.org/luci/logdog/common/types" 26 "go.chromium.org/luci/server/router" 27 "go.chromium.org/luci/server/templates" 28 29 "go.chromium.org/luci/milo/frontend/ui" 30 "go.chromium.org/luci/milo/internal/buildsource/rawpresentation" 31 "go.chromium.org/luci/milo/internal/buildsource/swarming" 32 ) 33 34 func handleSwarmingBuild(c *router.Context) error { 35 host := c.Request.FormValue("server") 36 taskID := c.Params.ByName("id") 37 38 // Redirect to build page if possible. 39 switch buildID, ldURL, err := swarming.RedirectsFromTask(c.Request.Context(), host, taskID); { 40 case err != nil: 41 return err 42 case buildID != 0: 43 u := *c.Request.URL 44 u.Path = fmt.Sprintf("/b/%d", buildID) 45 http.Redirect(c.Writer, c.Request, u.String(), http.StatusFound) 46 return nil 47 case ldURL != "": 48 u := *c.Request.URL 49 u.Path = fmt.Sprintf("/raw/build/%s", ldURL) 50 http.Redirect(c.Writer, c.Request, u.String(), http.StatusFound) 51 return nil 52 } 53 54 build, err := swarming.GetBuild(c.Request.Context(), host, taskID) 55 return renderBuildLegacy(c, build, false, err) 56 } 57 58 func handleRawPresentationBuild(c *router.Context) error { 59 legacyBuild, build, err := rawpresentation.GetBuild( 60 c.Request.Context(), 61 c.Params.ByName("logdog_host"), 62 c.Params.ByName("project"), 63 types.StreamPath(strings.Trim(c.Params.ByName("path"), "/"))) 64 if build != nil { 65 return renderBuild(c, build, false, err) 66 } 67 return renderBuildLegacy(c, legacyBuild, false, err) 68 } 69 70 // renderBuildLegacy is a shortcut for rendering build or returning err if it is not 71 // nil. Also calls build.Fix(). 72 func renderBuildLegacy(c *router.Context, build *ui.MiloBuildLegacy, renderTimeline bool, err error) error { 73 if err != nil { 74 return err 75 } 76 77 build.StepDisplayPref = getStepDisplayPrefCookie(c) 78 build.ShowDebugLogsPref = getShowDebugLogsPrefCookie(c) 79 build.Fix(c.Request.Context()) 80 81 templates.MustRender(c.Request.Context(), c.Writer, "pages/build_legacy.html", templates.Args{ 82 "Build": build, 83 }) 84 return nil 85 } 86 87 // makeBuild partially populates a buildbucketpb.Build. Currently it attempts to 88 // make available .Builder.Project, .Builder.Bucket, and .Builder.Builder. 89 func makeBuild(params httprouter.Params, build *ui.MiloBuildLegacy) *buildbucketpb.Build { 90 // NOTE: on led builds, some of these params may not be populated. 91 return &buildbucketpb.Build{ 92 Builder: &buildbucketpb.BuilderID{ 93 Project: params.ByName("project"), // equivalent build.Trigger.Project 94 Bucket: params.ByName("bucket"), // way to get from ui.MiloBuildLegacy so don't need params here? 95 Builder: params.ByName("builder"), // build.Summary.ParentLabel.Label 96 }, 97 } 98 }