diff options
Diffstat (limited to 'clone.go')
| -rw-r--r-- | clone.go | 35 |
1 files changed, 35 insertions, 0 deletions
@@ -214,3 +214,38 @@ func findGoImport(url string) (string, error) { return newurl, nil } + +// GetNamesapce removes http://, https://, and .git suffix from the given URL if present. +func GetNamespace(url string) string { + // Trim protocol prefix + if strings.HasPrefix(url, "http://") { + url = strings.TrimPrefix(url, "http://") + } else if strings.HasPrefix(url, "https://") { + url = strings.TrimPrefix(url, "https://") + } + + // Trim trailing .git + url = strings.TrimSuffix(url, ".git") + + return url +} + +func (f *Forge) Clone(url string) (*gitpb.Repo, error) { + ns := GetNamespace(url) + if ns == url { + return nil, errors.New("todo: forgepb.Clone() fix url parsing") + } + + // + // returns repo if namespace already exists + if repo := f.Repos.FindByNamespace(ns); repo != nil { + log.Info("FindByNamespace() worked = ", ns) + return repo, nil + } + + if repo, _ := f.urlClone(ns, url); repo != nil { + return repo, nil + } + + return nil, errors.New("todo: forgepb.Clone() url failed " + url) +} |
