feat: subgroups (#91)

Several code-hosters like GitLab allow to have subgroups. These were previously not suppported because we weren't able to tell if something was a subgroup or a subdir.

By letting users specify the `.git` part of the http string as well, this now work for all protocol, including https.
This commit is contained in:
Dominik Süß 2020-03-17 17:45:34 +01:00 committed by GitHub
parent cd5e2945d2
commit 74a7f9775e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 1 deletions

View file

@ -106,6 +106,7 @@ const (
gitSSHExp = `ssh://git@(?P<host>.+)/(?P<user>.+)/(?P<repo>.+).git`
gitSCPExp = `^git@(?P<host>.+):(?P<user>.+)/(?P<repo>.+).git`
// The long ugly pattern for ${host} here is a generic pattern for "valid URL with zero or more subdomains and a valid TLD"
gitHTTPSSubgroup = `(?P<host>[a-zA-Z0-9][a-zA-Z0-9-\.]{1,61}[a-zA-Z0-9]\.[a-zA-Z]{2,})/(?P<user>[-_a-zA-Z0-9/]+)/(?P<repo>[-_a-zA-Z0-9]+)\.git`
gitHTTPSExp = `(?P<host>[a-zA-Z0-9][a-zA-Z0-9-\.]{1,61}[a-zA-Z0-9]\.[a-zA-Z]{2,})/(?P<user>[-_a-zA-Z0-9]+)/(?P<repo>[-_a-zA-Z0-9]+)`
)
@ -130,6 +131,9 @@ func parseGit(uri string) *Dependency {
case reMatch(gitSCPExp, uri):
gs, version = match(uri, gitSCPExp)
gs.Scheme = GitSchemeSSH
case reMatch(gitHTTPSSubgroup, uri):
gs, version = match(uri, gitHTTPSSubgroup)
gs.Scheme = GitSchemeHTTPS
case reMatch(gitHTTPSExp, uri):
gs, version = match(uri, gitHTTPSExp)
gs.Scheme = GitSchemeHTTPS

View file

@ -169,6 +169,40 @@ func TestParseGit(t *testing.T) {
},
wantRemote: "https://git.example.com/foo/bar",
},
{
name: "ValidGitSubgroups",
uri: "example.com/group/subgroup/repository.git",
want: &Dependency{
Version: "master",
Source: Source{
GitSource: &Git{
Scheme: GitSchemeHTTPS,
Host: "example.com",
User: "group/subgroup",
Repo: "repository",
Subdir: "",
},
},
},
wantRemote: "https://example.com/group/subgroup/repository",
},
{
name: "ValidGitSubgroupSubDir",
uri: "example.com/group/subgroup/repository.git/subdir",
want: &Dependency{
Version: "master",
Source: Source{
GitSource: &Git{
Scheme: GitSchemeHTTPS,
Host: "example.com",
User: "group/subgroup",
Repo: "repository",
Subdir: "/subdir",
},
},
},
wantRemote: "https://example.com/group/subgroup/repository",
},
}
for _, c := range tests {