diff options
| author | Jeff Carr <[email protected]> | 2025-07-07 18:52:02 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-07-07 18:52:02 -0500 |
| commit | 34a10367c5b425dd998d8fcc33f94428044c7599 (patch) | |
| tree | e51d212480a7ba9096bf4bb6e258046c210c3d3c /clone.go | |
| parent | dea10e2150ca2d879a9ef30f136698217a0415b2 (diff) | |
work on generic Clone()v0.0.111
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) +} |
