summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-07-07 18:52:02 -0500
committerJeff Carr <[email protected]>2025-07-07 18:52:02 -0500
commit34a10367c5b425dd998d8fcc33f94428044c7599 (patch)
treee51d212480a7ba9096bf4bb6e258046c210c3d3c
parentdea10e2150ca2d879a9ef30f136698217a0415b2 (diff)
work on generic Clone()v0.0.111
-rw-r--r--clone.go35
-rw-r--r--http.go22
-rw-r--r--humanTable.go2
3 files changed, 57 insertions, 2 deletions
diff --git a/clone.go b/clone.go
index b825234..ed9f044 100644
--- a/clone.go
+++ b/clone.go
@@ -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)
+}
diff --git a/http.go b/http.go
index 33f50bf..fb65080 100644
--- a/http.go
+++ b/http.go
@@ -41,7 +41,7 @@ func (f *Forge) HttpPost(url string, data []byte) ([]byte, error) {
return body, nil
}
-func (f *Forge) LookupPB(check *gitpb.Repos) (*gitpb.Repos, error) {
+func (f *Forge) LookupPBorig(check *gitpb.Repos) (*gitpb.Repos, error) {
url := forgeURL + "lookup"
for repo := range check.IterByFullPath() {
@@ -52,3 +52,23 @@ func (f *Forge) LookupPB(check *gitpb.Repos) (*gitpb.Repos, error) {
return check.SubmitReposPB(url)
}
+
+func (f *Forge) LookupPB(check *gitpb.Repos) (*gitpb.Repos, error) {
+ url := forgeURL + "lookup"
+
+ queryPB := gitpb.NewRepos()
+
+ for repo := range check.IterByFullPath() {
+ ns := repo.Namespace
+ if ns == "" {
+ ns = repo.GoInfo.GoPath
+ }
+
+ newr := new(gitpb.Repo)
+ newr.Namespace = ns
+
+ queryPB.AppendByNamespace(newr)
+ }
+
+ return queryPB.SubmitReposPB(url)
+}
diff --git a/humanTable.go b/humanTable.go
index 7e5465e..98437dd 100644
--- a/humanTable.go
+++ b/humanTable.go
@@ -182,7 +182,7 @@ func (f *Forge) printRepoToTable(repo *gitpb.Repo, sizes []int, full bool) {
var chort string = repo.GetCurrentBranchVersion()
var cname string = repo.GetCurrentBranchName()
- var gopath string = repo.GetGoPath()
+ var gopath string = repo.GetNamespace()
var rtype string = repo.GetRepoType()
// ctime := repo.Tags.GetAge(mhort)