From 3e4df909458c0ed54e334641fbf32e2385759d1f Mon Sep 17 00:00:00 2001 From: "Stanislav N. aka pztrn" Date: Sat, 8 Feb 2020 12:04:20 +0500 Subject: [PATCH] Cut out versioning from dependency name if it was found in last element of path. E.g. "github.com/user/repo/v2" will became "github.com/user/repo". This is needed for getting go-import/go-source data. --- parsers/golang/dep.go | 8 ++++++++ parsers/golang/modules.go | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/parsers/golang/dep.go b/parsers/golang/dep.go index 85a3f39..0d80f6e 100644 --- a/parsers/golang/dep.go +++ b/parsers/golang/dep.go @@ -83,6 +83,14 @@ func (gp *golangParser) getDependenciesFromDep(pkgPath string) []*structs.Depend Version: dep.Version, } + // Name is used in URLs composing, so we should get rid of + // possible versioning from it, which will occur if dependency + // supports both go modules and other dependency managers. + depName := strings.Split(dependency.Name, "/") + if strings.HasPrefix(depName[len(depName)-1], "v") && len(depName[len(depName)-1]) == 2 { + dependency.Name = strings.Join(depName[:len(depName)-1], "/") + } + // If branch is empty - assume master. if dependency.VCS.Branch == "" { dependency.VCS.Branch = "master" diff --git a/parsers/golang/modules.go b/parsers/golang/modules.go index 11ee1e0..2a33701 100644 --- a/parsers/golang/modules.go +++ b/parsers/golang/modules.go @@ -93,6 +93,14 @@ func (gp *golangParser) getDependenciesFromModules(pkgPath string) []*structs.De Version: version, } + // Name is used in URLs composing, so we should get rid of + // possible versioning from it, which will occur if dependency + // supports both go modules and other dependency managers. + depName := strings.Split(dependency.Name, "/") + if strings.HasPrefix(depName[len(depName)-1], "v") && len(depName[len(depName)-1]) == 2 { + dependency.Name = strings.Join(depName[:len(depName)-1], "/") + } + deps = append(deps, dependency) // Mark dependency as processed.