Skip to content

Commit e731d94

Browse files
authored
Consider username and password in repo urls (#162)
Signed-off-by: Reinhard Naegele <[email protected]>
1 parent f53c402 commit e731d94

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

pkg/tool/account.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424

2525
type AccountValidator struct{}
2626

27-
var repoDomainPattern = regexp.MustCompile("(?:https://|git@)([^/:]+)")
27+
var repoDomainPattern = regexp.MustCompile("(?:https://(?:[^@:]+:[^@:]+@)?|git@)([^/:]+)")
2828

2929
func (v AccountValidator) Validate(repoURL string, account string) error {
3030
domain, err := parseOutGitRepoDomain(repoURL)

pkg/tool/account_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,13 @@ func TestParseOutGitDomain(t *testing.T) {
1616
}{
1717
{"GitHub SSH", "[email protected]:foo/bar", "github.com", nil},
1818
{"GitHub HTTPS", "https://github.com/foo/bar", "github.com", nil},
19+
{"GitHub HTTPS with username/password", "https://foo:[email protected]/foo/bar", "github.com", nil},
1920
{"Gitlab SSH", "[email protected]:foo/bar", "gitlab.com", nil},
2021
{"Gitlab HTTPS", "https://gitlab.com/foo/bar", "gitlab.com", nil},
22+
{"Gitlab HTTPS with username/password", "https://gitlab-ci-token:[email protected]/foo/bar", "gitlab.com", nil},
2123
{"Bitbucket SSH", "[email protected]:foo/bar", "bitbucket.com", nil},
2224
{"Bitbucket HTTPS", "https://bitbucket.com/foo/bar", "bitbucket.com", nil},
25+
{"Bitbucket HTTPS with username/password", "https://user:[email protected]/foo/bar", "bitbucket.com", nil},
2326
{"Invalid", "foo/bar", "", fmt.Errorf("Could not parse git repository domain for 'foo/bar'")},
2427
}
2528

0 commit comments

Comments
 (0)