diff --git a/Dockerfile b/Dockerfile index 1f8825bd..8016ff3c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,9 +2,9 @@ FROM alpine:3.17.0 # Install tini to ensure docker waits for uplift to finish before terminating RUN apk add --no-cache \ - git=2.36.2-r0 \ - tini=0.19.0-r0 \ - gnupg=2.2.35-r4 + git=2.38.1-r0 \ + tini=0.19.0-r1 \ + gnupg=2.2.40-r0 COPY uplift /usr/local/bin diff --git a/internal/git/utils.go b/internal/git/utils.go index 223687c7..a0471b87 100644 --- a/internal/git/utils.go +++ b/internal/git/utils.go @@ -159,13 +159,6 @@ func Remote() (Repository, error) { // Sanitise any SSH based URL to ensure it is parseable rem = strings.TrimPrefix(rem, "git@") rem = strings.Replace(rem, ":", "/", 1) - } else if strings.HasPrefix(rem, "http") { - // Strip any credentials from the URL to ensure it is parseable - if tkn := strings.Index(rem, "@"); tkn > -1 { - rem = rem[tkn+1:] - } else { - rem = rem[strings.Index(rem, "//")+2:] - } } u, err := url.Parse(rem) @@ -175,15 +168,24 @@ func Remote() (Repository, error) { // Split into parts p := strings.Split(u.Path, "/") + if len(p) < 3 { - return Repository{}, fmt.Errorf("malformed repository URL: %s", remURL) + // This could be a custom Git server that doesn't follow the expected pattern. + // Don't fail, but return the raw origin for custom parsing + return Repository{Origin: origin}, nil + } + + // If the repository has a HTTP(S) origin, the host will have been correctly identified + host := u.Host + if host == "" { + // For other schemes, assume the host is contained within the first part + host = p[0] } - host := p[0] owner := p[1] name := p[len(p)-1] path := strings.Join(p[1:], "/") - if strings.Contains(p[0], "codecommit") { + if strings.Contains(host, "codecommit") { // No concept of an owner with CodeCommit repositories owner = "" path = name diff --git a/internal/git/utils_test.go b/internal/git/utils_test.go index efa01503..eb3e7349 100644 --- a/internal/git/utils_test.go +++ b/internal/git/utils_test.go @@ -208,6 +208,18 @@ func TestRemote(t *testing.T) { repo: "testing10", path: "testing10", }, + { + name: "CustomGitServerSchemeWithPort", + cloneURL: "http://172.24.100.14:7990/owner/nested/testing11.git", + host: "172.24.100.14:7990", + owner: "owner", + repo: "testing11", + path: "owner/nested/testing11", + }, + { + name: "LocalRunningGitServer", + cloneURL: "http://localhost:8000/testing12.git", + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -260,14 +272,6 @@ func TestRemote_NoRemoteSet(t *testing.T) { require.Error(t, err) } -func TestRemote_MalformedURL(t *testing.T) { - InitRepo(t) - RemoteOrigin(t, "whizzbang.com/repository") - - _, err := Remote() - require.EqualError(t, err, "malformed repository URL: whizzbang.com/repository") -} - func TestAllTags(t *testing.T) { InitRepo(t)