1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-08 03:31:59 +02:00

Merge remote-tracking branch 'origin/master'

This commit is contained in:
Carlos Alexandro Becker 2021-09-06 14:24:40 -03:00
commit 38dd86a215
No known key found for this signature in database
GPG Key ID: E61E2F7DC14AB940
2 changed files with 36 additions and 3 deletions

View File

@ -2,6 +2,7 @@ package git
import (
"fmt"
"net/url"
"os"
"os/exec"
"strconv"
@ -82,10 +83,20 @@ func getGitInfo() (context.GitInfo, error) {
if err != nil {
return context.GitInfo{}, fmt.Errorf("couldn't get commit date: %w", err)
}
url, err := getURL()
gitURL, err := getURL()
if err != nil {
return context.GitInfo{}, fmt.Errorf("couldn't get remote URL: %w", err)
}
if strings.HasPrefix(gitURL, "https://") {
u, err := url.Parse(gitURL)
if err != nil {
return context.GitInfo{}, fmt.Errorf("couldn't parse remote URL: %w", err)
}
u.User = nil
gitURL = u.String()
}
tag, err := getTag()
if err != nil {
return context.GitInfo{
@ -94,7 +105,7 @@ func getGitInfo() (context.GitInfo, error) {
FullCommit: full,
ShortCommit: short,
CommitDate: date,
URL: url,
URL: gitURL,
CurrentTag: "v0.0.0",
}, ErrNoTag
}
@ -105,7 +116,7 @@ func getGitInfo() (context.GitInfo, error) {
FullCommit: full,
ShortCommit: short,
CommitDate: date,
URL: url,
URL: gitURL,
}, nil
}

View File

@ -115,6 +115,28 @@ func TestDirty(t *testing.T) {
})
}
func TestRemoteURLContainsWithUsernameAndToken(t *testing.T) {
testlib.Mktmp(t)
testlib.GitInit(t)
testlib.GitRemoteAdd(t, "https://gitlab-ci-token:SyYhsAghYFTvMoxw7GAg@gitlab.private.com/platform/base/poc/kink.git/releases/tag/v0.1.4")
testlib.GitAdd(t)
testlib.GitCommit(t, "commit2")
testlib.GitTag(t, "v0.0.1")
ctx := context.New(config.Project{})
require.NoError(t, Pipe{}.Run(ctx))
}
func TestRemoteURLContainsWithUsernameAndTokenWithInvalidURL(t *testing.T) {
testlib.Mktmp(t)
testlib.GitInit(t)
testlib.GitRemoteAdd(t, "https://gitlab-ci-token:SyYhsAghYFTvMoxw7GAggitlab.com/platform/base/poc/kink.git/releases/tag/v0.1.4")
testlib.GitAdd(t)
testlib.GitCommit(t, "commit2")
testlib.GitTag(t, "v0.0.1")
ctx := context.New(config.Project{})
require.Error(t, Pipe{}.Run(ctx))
}
func TestShallowClone(t *testing.T) {
folder := testlib.Mktmp(t)
require.NoError(