First pass at private repos

Signed-off-by: Joel Longtine <joel@longtine.io>
This commit is contained in:
Joel Longtine 2021-12-06 15:30:38 -07:00
parent e7f1649fe6
commit 870410be51
2 changed files with 69 additions and 0 deletions

View File

@ -29,6 +29,8 @@ func newRequire(repoName, versionConstraint string) (*Require, error) {
return parseGithubRepoName(repoName, versionConstraint)
case strings.HasPrefix(repoName, stdlib.ModuleName):
return parseDaggerRepoName(repoName, versionConstraint)
case strings.Contains(repoName, ".git"):
return parseGitRepoName(repoName, versionConstraint)
default:
return nil, fmt.Errorf("repo name does not match suported providers")
}
@ -74,6 +76,27 @@ func parseDaggerRepoName(repoName, versionConstraint string) (*Require, error) {
}, 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 {
return fmt.Sprintf("%s@%s", r.fullPath(), r.version)
}

View File

@ -94,6 +94,52 @@ func TestParseArgument(t *testing.T) {
version: "26a1d46d1b3c",
},
},
{
name: "Unspecified provider without folder",
in: "dagger.io/dagger/universe.git@main",
want: &Require{
repo: "dagger.io/dagger/universe.git",
path: "",
version: "main",
},
},
{
name: "Unspecified provider without folder",
in: "dagger.io/dagger/universe.git/stdlib/alpha.dagger.io/dagger@v0.1.0",
want: &Require{
repo: "dagger.io/dagger/universe.git",
path: "/stdlib/alpha.dagger.io/dagger",
version: "v0.1.0",
},
},
{
name: "Unspecified provider without folder",
in: "dagger.io/dagger/universe.git/stdlib@v5",
want: &Require{
repo: "dagger.io/dagger/universe.git",
path: "/stdlib",
version: "v5",
},
},
{
name: "Unspecified provider without folder",
in: "dagger.io/dagger/universe.git",
want: &Require{
repo: "dagger.io/dagger/universe.git",
path: "",
version: "",
},
},
{
name: "Unspecified provider without folder",
in: "dagger.io/dagger/universe.git/stdlib/alpha.dagger.io/dagger",
want: &Require{
repo: "dagger.io/dagger/universe.git",
path: "/stdlib/alpha.dagger.io/dagger",
version: "",
},
},
// TODO: Add more tests for ports!
}
for _, c := range cases {