Files
woodpecker/server/remote/common/utils.go
6543 ce07632ffd Get Netrc machine from clone url (#800) (#803)
We previously got the machine hostname for Netrc from the url of the remote, but in cases where the clone-url does not match the api url this can lead to errors.

Co-authored-by: Anbraten <anton@ju60.de>
2022-02-26 14:36:14 +01:00

26 lines
353 B
Go

package common
import (
"net"
"net/url"
"strings"
)
func ExtractHostFromCloneURL(cloneURL string) (string, error) {
u, err := url.Parse(cloneURL)
if err != nil {
return "", err
}
if !strings.Contains(u.Host, ":") {
return u.Host, nil
}
host, _, err := net.SplitHostPort(u.Host)
if err != nil {
return "", err
}
return host, nil
}