Skip to content

Commit

Permalink
fix: bug in handling gitlab-ci style urls (#2527)
Browse files Browse the repository at this point in the history
  • Loading branch information
drewstinnett committed Sep 28, 2021
1 parent f9cea01 commit 608d48a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
12 changes: 11 additions & 1 deletion internal/git/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,17 @@ func ExtractRepoFromURL(rawurl string) (config.Repo, error) {
// on HTTP and HTTPS URLs it will remove the http(s): prefix,
// which is ok. On SSH URLs the whole user@server will be removed,
// which is required.
s = s[strings.LastIndex(s, ":")+1:]

// If the url contains more than 1 ':' character, assume we are doing an
// http URL with a username/password in it, and normalize the URL.
// Gitlab-CI uses this type of URL
if strings.Count(s, ":") == 1 {
s = s[strings.LastIndex(s, ":")+1:]
} else {
// Handle Gitlab-ci funky URLs in the form of:
// "https://gitlab-ci-token:SOME_TOKEN@gitlab.yourcompany.com/yourgroup/yourproject.git"
s = "//" + s[strings.LastIndex(s, "@")+1:]
}

// now we can parse it with net/url
u, err := url.Parse(s)
Expand Down
1 change: 1 addition & 0 deletions internal/git/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func TestExtractRepoFromURL(t *testing.T) {
"git@custom:goreleaser/goreleaser.git",
"https://github.com/goreleaser/goreleaser.git",
"https://github.enterprise.com/goreleaser/goreleaser.git",
"https://gitlab-ci-token:SOME_TOKEN@gitlab.yourcompany.com/goreleaser/goreleaser.git",
} {
t.Run(url, func(t *testing.T) {
repo, err := git.ExtractRepoFromURL(url)
Expand Down

1 comment on commit 608d48a

@vercel
Copy link

@vercel vercel bot commented on 608d48a Sep 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.