work on generic Clone()
This commit is contained in:
parent
dea10e2150
commit
34a10367c5
35
clone.go
35
clone.go
|
@ -214,3 +214,38 @@ func findGoImport(url string) (string, error) {
|
||||||
|
|
||||||
return newurl, nil
|
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)
|
||||||
|
}
|
||||||
|
|
22
http.go
22
http.go
|
@ -41,7 +41,7 @@ func (f *Forge) HttpPost(url string, data []byte) ([]byte, error) {
|
||||||
return body, nil
|
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"
|
url := forgeURL + "lookup"
|
||||||
|
|
||||||
for repo := range check.IterByFullPath() {
|
for repo := range check.IterByFullPath() {
|
||||||
|
@ -52,3 +52,23 @@ func (f *Forge) LookupPB(check *gitpb.Repos) (*gitpb.Repos, error) {
|
||||||
|
|
||||||
return check.SubmitReposPB(url)
|
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)
|
||||||
|
}
|
||||||
|
|
|
@ -182,7 +182,7 @@ func (f *Forge) printRepoToTable(repo *gitpb.Repo, sizes []int, full bool) {
|
||||||
var chort string = repo.GetCurrentBranchVersion()
|
var chort string = repo.GetCurrentBranchVersion()
|
||||||
var cname string = repo.GetCurrentBranchName()
|
var cname string = repo.GetCurrentBranchName()
|
||||||
|
|
||||||
var gopath string = repo.GetGoPath()
|
var gopath string = repo.GetNamespace()
|
||||||
var rtype string = repo.GetRepoType()
|
var rtype string = repo.GetRepoType()
|
||||||
|
|
||||||
// ctime := repo.Tags.GetAge(mhort)
|
// ctime := repo.Tags.GetAge(mhort)
|
||||||
|
|
Loading…
Reference in New Issue