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.
This commit is contained in:
Stanislav Nikitin 2020-02-08 12:04:20 +05:00
parent 47ba507e05
commit 3e4df90945
No known key found for this signature in database
GPG Key ID: 106900B32F8192EE
2 changed files with 16 additions and 0 deletions

View File

@ -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"

View File

@ -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.