Skip to content

Commit

Permalink
Add specific regex for azure devops
Browse files Browse the repository at this point in the history
  • Loading branch information
tehho committed Jul 13, 2020
1 parent 7042bdb commit 3328eaa
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
15 changes: 11 additions & 4 deletions spec/v1/deps/git.go
Expand Up @@ -22,8 +22,9 @@ import (
)

const (
GitSchemeSSH = "ssh://git@"
GitSchemeHTTPS = "https://"
GitSchemeSSH = "ssh://git@"
GitSchemeHTTPS = "https://"
GitSchemeHTTPSAzureDevops = "https://dev.azure.com"
)

// Git holds all required information for cloning a package from git
Expand Down Expand Up @@ -90,8 +91,9 @@ func (gs *Git) LegacyName() string {
}

var gitProtoFmts = map[string]string{
GitSchemeSSH: GitSchemeSSH + "%s/%s/%s.git",
GitSchemeHTTPS: GitSchemeHTTPS + "%s/%s/%s.git",
GitSchemeSSH: GitSchemeSSH + "%s/%s/%s.git",
GitSchemeHTTPS: GitSchemeHTTPS + "%s/%s/%s.git",
GitSchemeHTTPSAzureDevops: GitSchemeHTTPS + "%s/%s/%s",
}

// Remote returns a remote string that can be passed to git
Expand All @@ -108,6 +110,8 @@ const (
// 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/\.\s]+)/(?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\.]+)`

gitAzureDevopsHTTPSExp = `(?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/\-\.\s]+/_git)/(?P<repo>[-_a-zA-Z0-9\.]+)`
)

var (
Expand All @@ -131,6 +135,9 @@ func parseGit(uri string) *Dependency {
case reMatch(gitSCPExp, uri):
gs, version = match(uri, gitSCPExp)
gs.Scheme = GitSchemeSSH
case reMatch(gitAzureDevopsHTTPSExp, uri):
gs, version = match(uri, gitAzureDevopsHTTPSExp)
gs.Scheme = GitSchemeHTTPSAzureDevops
case reMatch(gitHTTPSSubgroup, uri):
gs, version = match(uri, gitHTTPSSubgroup)
gs.Scheme = GitSchemeHTTPS
Expand Down
14 changes: 7 additions & 7 deletions spec/v1/deps/git_test.go
Expand Up @@ -221,21 +221,21 @@ func TestParseGit(t *testing.T) {
wantRemote: "https://example.com/group/subgroup/repository.git",
},
{
name: "ValidGitSubgroupWithSpace",
uri: "example.com/group/sub group/repository.git/subdir",
name: "ValidGitAzureDevops",
uri: "https://organization@dev.azure.com/organization/project/_git/repository",
want: &Dependency{
Version: "master",
Source: Source{
GitSource: &Git{
Scheme: GitSchemeHTTPS,
Host: "example.com",
User: "group/sub group",
Scheme: GitSchemeHTTPSAzureDevops,
Host: "dev.azure.com",
User: "organization/project/_git",
Repo: "repository",
Subdir: "/subdir",
Subdir: "",
},
},
},
wantRemote: "https://example.com/group/sub group/repository.git",
wantRemote: "https://dev.azure.com/organization/project/_git/repository",
},
}

Expand Down

0 comments on commit 3328eaa

Please sign in to comment.