Merge pull request #1186 from jlongtine/jl/mod-private-repos

dagger mod with private repos
This commit is contained in:
Sam Alba 2021-12-14 15:59:29 -08:00 committed by GitHub
commit 8b33923ca5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 78 additions and 0 deletions

View File

@ -29,6 +29,8 @@ func newRequire(repoName, versionConstraint string) (*Require, error) {
return parseGithubRepoName(repoName, versionConstraint) return parseGithubRepoName(repoName, versionConstraint)
case strings.HasPrefix(repoName, stdlib.ModuleName): case strings.HasPrefix(repoName, stdlib.ModuleName):
return parseDaggerRepoName(repoName, versionConstraint) return parseDaggerRepoName(repoName, versionConstraint)
case strings.Contains(repoName, ".git"):
return parseGitRepoName(repoName, versionConstraint)
default: default:
return nil, fmt.Errorf("repo name does not match suported providers") return nil, fmt.Errorf("repo name does not match suported providers")
} }
@ -74,6 +76,27 @@ func parseDaggerRepoName(repoName, versionConstraint string) (*Require, error) {
}, nil }, nil
} }
// TODO: Get real URL regex
var gitRepoNameRegex = regexp.MustCompile(`^([a-zA-Z0-9_.-]+\.[a-zA-Z0-9]+(?::\d*)?/[a-zA-Z0-9_.-/]+?\.git)([a-zA-Z0-9/_.-]*)?@?([0-9a-zA-Z.-]*)`)
func parseGitRepoName(repoName, versionConstraint string) (*Require, error) {
repoMatches := gitRepoNameRegex.FindStringSubmatch(repoName)
if len(repoMatches) < 3 {
return nil, fmt.Errorf("issue when parsing git repo")
}
return &Require{
repo: repoMatches[1],
path: repoMatches[2],
version: repoMatches[3],
versionConstraint: versionConstraint,
cloneRepo: repoMatches[1],
clonePath: repoMatches[2],
}, nil
}
func (r *Require) String() string { func (r *Require) String() string {
return fmt.Sprintf("%s@%s", r.fullPath(), r.version) return fmt.Sprintf("%s@%s", r.fullPath(), r.version)
} }

View File

@ -94,6 +94,61 @@ func TestParseArgument(t *testing.T) {
version: "26a1d46d1b3c", version: "26a1d46d1b3c",
}, },
}, },
{
name: "Custom git provider without folder",
in: "git.blocklayer.com/dagger/universe.git@main",
want: &Require{
repo: "git.blocklayer.com/dagger/universe.git",
path: "",
version: "main",
},
},
{
name: "Custom git provider with folder and version",
in: "git.blocklayer.com/dagger/universe.git/stdlib/alpha.dagger.io/dagger@v0.1.0",
want: &Require{
repo: "git.blocklayer.com/dagger/universe.git",
path: "/stdlib/alpha.dagger.io/dagger",
version: "v0.1.0",
},
},
{
name: "Custom git provider with folder and version",
in: "git.blocklayer.com/dagger/universe.git/stdlib@v5",
want: &Require{
repo: "git.blocklayer.com/dagger/universe.git",
path: "/stdlib",
version: "v5",
},
},
{
name: "Custom git provider without folder",
in: "git.blocklayer.com/dagger/universe.git",
want: &Require{
repo: "git.blocklayer.com/dagger/universe.git",
path: "",
version: "",
},
},
{
name: "Custom git provider with folder, no version",
in: "git.blocklayer.com/dagger/universe.git/stdlib/alpha.dagger.io/dagger",
want: &Require{
repo: "git.blocklayer.com/dagger/universe.git",
path: "/stdlib/alpha.dagger.io/dagger",
version: "",
},
},
{
name: "Custom git provider with custom port, folder, and version",
in: "git.blocklayer.com:7999/ops/dagger.git/stuff/here@v5",
want: &Require{
repo: "git.blocklayer.com:7999/ops/dagger.git",
path: "/stuff/here",
version: "v5",
},
},
// TODO: Add more tests for ports!
} }
for _, c := range cases { for _, c := range cases {