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)
}