package main import ( "path/filepath" "regexp" ) type GitRepository struct { Owner string Repository string } type RepoID = string func (repo *GitRepository) ID() RepoID { return "~" + repo.Owner + "/" + repo.Repository + ".git" } func ParseGitRepositoryID(id RepoID) (repo *GitRepository, ok bool) { re := regexp.MustCompile(`^~([0-9a-z_.-]+)/([0-9a-z_.-]+)\.git$`) smatchs := re.FindStringSubmatch(id) if len(smatchs) != 3 { return } return &GitRepository{Owner: smatchs[1], Repository: smatchs[2],}, true } // an absolute path to the git repository's root func (repo *GitRepository) Path(repoRoot string) string { return filepath.Join(repoRoot, repo.ID()) }