| // Copyright 2019 The Fuchsia Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| package main |
| |
| import ( |
| "fmt" |
| "net/url" |
| "path" |
| "strings" |
| |
| buildbucketpb "go.chromium.org/luci/buildbucket/proto" |
| ) |
| |
| // Resolve a build input's integration URL. |
| func resolveIntegrationURL(buildInput *buildbucketpb.Build_Input) (*url.URL, error) { |
| var host string |
| if changes := buildInput.GetGerritChanges(); changes != nil { |
| host = strings.ReplaceAll(changes[0].GetHost(), "-review.googlesource.com", ".googlesource.com") |
| } else if gitilesCommit := buildInput.GetGitilesCommit(); gitilesCommit != nil { |
| host = gitilesCommit.GetHost() |
| } else { |
| return nil, fmt.Errorf("could not resolve host") |
| } |
| resolvedURL, err := url.Parse(host) |
| if err != nil { |
| return nil, fmt.Errorf("could not parse host as URL: %v", err) |
| } |
| resolvedURL.Path = path.Join(resolvedURL.Path, "integration") |
| return resolvedURL, nil |
| } |