all: rename VersionInfo to ModuleInfo

This CL is pure renaming:
- internal.VersionInfo to internal.ModuleInfo
- related variables from vi to mi

Updates b/150143758.

Change-Id: I5da63a07d6f9b731016ffe92e403e5f2d9aadab7
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/673875
Reviewed-by: Julie Qiu <julieqiu@google.com>
CI-Result: Cloud Build <devtools-proctor-result-processor@system.gserviceaccount.com>
This commit is contained in:
Jonathan Amsterdam 2020-02-24 16:28:22 -05:00 коммит произвёл Julie Qiu
Родитель 30d17fecd8
Коммит 66ad1f1dbe
31 изменённых файлов: 290 добавлений и 290 удалений

Просмотреть файл

@ -39,22 +39,22 @@ type DataSource interface {
// GetPackagesInVersion returns Packages contained in the module version
// specified by modulePath and version.
GetPackagesInVersion(ctx context.Context, modulePath, version string) ([]*Package, error)
// GetPseudoVersionsForModule returns VersionInfo for all known
// GetPseudoVersionsForModule returns ModuleInfo for all known
// pseudo-versions for the module corresponding to modulePath.
GetPseudoVersionsForModule(ctx context.Context, modulePath string) ([]*VersionInfo, error)
// GetPseudoVersionsForModule returns VersionInfo for all known
GetPseudoVersionsForModule(ctx context.Context, modulePath string) ([]*ModuleInfo, error)
// GetPseudoVersionsForModule returns ModuleInfo for all known
// pseudo-versions for any module containing a package with the given import
// path.
GetPseudoVersionsForPackageSeries(ctx context.Context, pkgPath string) ([]*VersionInfo, error)
// GetTaggedVersionsForModule returns VersionInfo for all known tagged
GetPseudoVersionsForPackageSeries(ctx context.Context, pkgPath string) ([]*ModuleInfo, error)
// GetTaggedVersionsForModule returns ModuleInfo for all known tagged
// versions for the module corresponding to modulePath.
GetTaggedVersionsForModule(ctx context.Context, modulePath string) ([]*VersionInfo, error)
// GetTaggedVersionsForModule returns VersionInfo for all known tagged
GetTaggedVersionsForModule(ctx context.Context, modulePath string) ([]*ModuleInfo, error)
// GetTaggedVersionsForModule returns ModuleInfo for all known tagged
// versions for any module containing a package with the given import path.
GetTaggedVersionsForPackageSeries(ctx context.Context, pkgPath string) ([]*VersionInfo, error)
// GetVersionInfo returns the VersionInfo corresponding to modulePath and
GetTaggedVersionsForPackageSeries(ctx context.Context, pkgPath string) ([]*ModuleInfo, error)
// GetModuleInfo returns the ModuleInfo corresponding to modulePath and
// version.
GetVersionInfo(ctx context.Context, modulePath, version string) (*VersionInfo, error)
GetModuleInfo(ctx context.Context, modulePath, version string) (*ModuleInfo, error)
// IsExcluded reports whether the path is excluded from processinng.
IsExcluded(ctx context.Context, path string) (bool, error)

Просмотреть файл

@ -25,8 +25,8 @@ const (
UnknownModulePath = "unknownModulePath"
)
// VersionInfo holds metadata associated with a version.
type VersionInfo struct {
// ModuleInfo holds metadata associated with a module.
type ModuleInfo struct {
ModulePath string
Version string
CommitTime time.Time
@ -60,7 +60,7 @@ type VersionMap struct {
// Examples:
// The module paths "a/b" and "a/b/v2" both have series path "a/b".
// The module paths "gopkg.in/yaml.v1" and "gopkg.in/yaml.v2" both have series path "gopkg.in/yaml".
func (v *VersionInfo) SeriesPath() string {
func (v *ModuleInfo) SeriesPath() string {
return SeriesPathForModule(v.ModulePath)
}
@ -72,7 +72,7 @@ func SeriesPathForModule(modulePath string) string {
// A Version is a specific, reproducible build of a module.
type Version struct {
VersionInfo
ModuleInfo
Packages []*Package
// Licenses holds all licenses within this module version, including those
// that may be contained in nested subdirectories.
@ -101,13 +101,13 @@ type Package struct {
// information.
type VersionedPackage struct {
Package
VersionInfo
ModuleInfo
}
// Directory represents a folder in a module version, and all of the packages
// inside that folder.
type Directory struct {
VersionInfo
ModuleInfo
Path string
Packages []*Package
}
@ -233,8 +233,8 @@ type AlternativeModulePath struct {
//
// FieldSet bits are unique across the entire project, because some types are
// concatenations (via embedding) of others. For example, a VersionedPackage
// contains the fields of both a VersionInfo and a Package, so we can't use the
// same bits for both VersionInfo's ReadmeContents field and Package's
// contains the fields of both a ModuleInfo and a Package, so we can't use the
// same bits for both ModuleInfo's ReadmeContents field and Package's
// DocumentationHTML field.
type FieldSet int64

Просмотреть файл

@ -74,7 +74,7 @@ func TestFetchAndUpdateState_NotFound(t *testing.T) {
// Verify that the module status is recorded correctly, and that the version is in the DB.
checkStatus(http.StatusOK)
if _, err := testDB.GetVersionInfo(ctx, modulePath, version); err != nil {
if _, err := testDB.GetModuleInfo(ctx, modulePath, version); err != nil {
t.Fatal(err)
}
@ -112,7 +112,7 @@ func TestFetchAndUpdateState_NotFound(t *testing.T) {
checkStatus(http.StatusNotFound)
// The module should no longer be in the database.
if _, err := testDB.GetVersionInfo(ctx, modulePath, version); !errors.Is(err, derrors.NotFound) {
if _, err := testDB.GetModuleInfo(ctx, modulePath, version); !errors.Is(err, derrors.NotFound) {
t.Fatalf("got %v, want NotFound", err)
}
@ -151,7 +151,7 @@ func checkModuleNotFound(t *testing.T, ctx context.Context, modulePath, version
if code != wantCode || !errors.Is(err, wantErr) {
t.Fatalf("got %d, %v; want %d, Is(err, %v)", code, err, wantCode, wantErr)
}
_, err = testDB.GetVersionInfo(ctx, modulePath, version)
_, err = testDB.GetModuleInfo(ctx, modulePath, version)
if !errors.Is(err, derrors.NotFound) {
t.Fatalf("got %v, want Is(NotFound)", err)
}
@ -292,7 +292,7 @@ func TestFetchAndUpdateState_Mismatch(t *testing.T) {
if code != wantCode || !errors.Is(err, wantErr) {
t.Fatalf("got %d, %v; want %d, Is(err, derrors.AlternativeModule)", code, err, wantCode)
}
_, err = testDB.GetVersionInfo(ctx, modulePath, version)
_, err = testDB.GetModuleInfo(ctx, modulePath, version)
if !errors.Is(err, derrors.NotFound) {
t.Fatalf("got %v, want Is(NotFound)", err)
}
@ -547,7 +547,7 @@ func TestReFetch(t *testing.T) {
t.Fatalf("fetchAndInsertVersion(%q, %q, %v, %v): %v", modulePath, version, client, testDB, err)
}
want := &internal.VersionedPackage{
VersionInfo: internal.VersionInfo{
ModuleInfo: internal.ModuleInfo{
ModulePath: modulePath,
Version: version,
CommitTime: time.Date(2019, 1, 30, 0, 0, 0, 0, time.UTC),
@ -598,7 +598,7 @@ func TestFetchAndInsertVersion(t *testing.T) {
defer func() { stdlib.UseTestData = false }()
myModuleV100 := &internal.VersionedPackage{
VersionInfo: internal.VersionInfo{
ModuleInfo: internal.ModuleInfo{
ModulePath: "github.com/my/module",
Version: "v1.0.0",
CommitTime: testProxyCommitTime,
@ -652,7 +652,7 @@ func TestFetchAndInsertVersion(t *testing.T) {
version: "v1.0.0",
pkg: "nonredistributable.mod/module/bar/baz",
want: &internal.VersionedPackage{
VersionInfo: internal.VersionInfo{
ModuleInfo: internal.ModuleInfo{
ModulePath: "nonredistributable.mod/module",
Version: "v1.0.0",
CommitTime: testProxyCommitTime,
@ -684,7 +684,7 @@ func TestFetchAndInsertVersion(t *testing.T) {
version: "v1.0.0",
pkg: "nonredistributable.mod/module/foo",
want: &internal.VersionedPackage{
VersionInfo: internal.VersionInfo{
ModuleInfo: internal.ModuleInfo{
ModulePath: "nonredistributable.mod/module",
Version: "v1.0.0",
CommitTime: testProxyCommitTime,
@ -714,7 +714,7 @@ func TestFetchAndInsertVersion(t *testing.T) {
version: "v1.12.5",
pkg: "context",
want: &internal.VersionedPackage{
VersionInfo: internal.VersionInfo{
ModuleInfo: internal.ModuleInfo{
ModulePath: "std",
Version: "v1.12.5",
CommitTime: stdlib.TestCommitTime,
@ -747,7 +747,7 @@ func TestFetchAndInsertVersion(t *testing.T) {
version: "v1.12.5",
pkg: "builtin",
want: &internal.VersionedPackage{
VersionInfo: internal.VersionInfo{
ModuleInfo: internal.ModuleInfo{
ModulePath: "std",
Version: "v1.12.5",
CommitTime: stdlib.TestCommitTime,
@ -780,7 +780,7 @@ func TestFetchAndInsertVersion(t *testing.T) {
version: "v1.12.5",
pkg: "encoding/json",
want: &internal.VersionedPackage{
VersionInfo: internal.VersionInfo{
ModuleInfo: internal.ModuleInfo{
ModulePath: "std",
Version: "v1.12.5",
CommitTime: stdlib.TestCommitTime,
@ -826,7 +826,7 @@ func TestFetchAndInsertVersion(t *testing.T) {
version: "v1.0.0",
pkg: "build.constraints/module/cpu",
want: &internal.VersionedPackage{
VersionInfo: internal.VersionInfo{
ModuleInfo: internal.ModuleInfo{
ModulePath: "build.constraints/module",
Version: "v1.0.0",
CommitTime: testProxyCommitTime,
@ -867,12 +867,12 @@ func TestFetchAndInsertVersion(t *testing.T) {
t.Fatalf("fetchAndInsertVersion(%q, %q, %v, %v): %v", test.modulePath, test.version, client, testDB, err)
}
gotVersionInfo, err := testDB.GetVersionInfo(ctx, test.modulePath, test.version)
gotModuleInfo, err := testDB.GetModuleInfo(ctx, test.modulePath, test.version)
if err != nil {
t.Fatal(err)
}
if diff := cmp.Diff(test.want.VersionInfo, *gotVersionInfo, cmp.AllowUnexported(source.Info{})); diff != "" {
t.Fatalf("testDB.GetVersionInfo(ctx, %q, %q) mismatch (-want +got):\n%s", test.modulePath, test.version, diff)
if diff := cmp.Diff(test.want.ModuleInfo, *gotModuleInfo, cmp.AllowUnexported(source.Info{})); diff != "" {
t.Fatalf("testDB.GetModuleInfo(ctx, %q, %q) mismatch (-want +got):\n%s", test.modulePath, test.version, diff)
}
gotPkg, err := testDB.GetPackage(ctx, test.pkg, internal.UnknownModulePath, test.version)

Просмотреть файл

@ -155,7 +155,7 @@ func processZipFile(ctx context.Context, modulePath string, versionType version.
hasGoMod := zipContainsFilename(zipReader, path.Join(moduleVersionDir(modulePath, resolvedVersion), "go.mod"))
return &FetchResult{
Version: &internal.Version{
VersionInfo: internal.VersionInfo{
ModuleInfo: internal.ModuleInfo{
ModulePath: modulePath,
Version: resolvedVersion,
CommitTime: commitTime,

Просмотреть файл

@ -400,7 +400,7 @@ func TestFetchVersion(t *testing.T) {
modulePath := "github.com/my/module"
vers := "v1.0.0"
wantVersionInfo := internal.VersionInfo{
wantModuleInfo := internal.ModuleInfo{
ModulePath: "github.com/my/module",
Version: "v1.0.0",
CommitTime: testProxyCommitTime,
@ -411,8 +411,8 @@ func TestFetchVersion(t *testing.T) {
HasGoMod: false,
SourceInfo: source.NewGitHubInfo("https://github.com/my/module", "", "v1.0.0"),
}
wantVersionInfoGoMod := wantVersionInfo
wantVersionInfoGoMod.HasGoMod = true
wantModuleInfoGoMod := wantModuleInfo
wantModuleInfoGoMod.HasGoMod = true
wantCoverage := sample.LicenseMetadata[0].Coverage
wantLicenses := []*licenses.License{
@ -438,7 +438,7 @@ func TestFetchVersion(t *testing.T) {
"LICENSE.md": testhelper.MITLicense,
},
want: &internal.Version{
VersionInfo: wantVersionInfo,
ModuleInfo: wantModuleInfo,
Packages: []*internal.Package{
{
Path: "github.com/my/module/foo",
@ -470,7 +470,7 @@ func TestFetchVersion(t *testing.T) {
type Value int`,
},
want: &internal.Version{
VersionInfo: wantVersionInfo,
ModuleInfo: wantModuleInfo,
Packages: []*internal.Package{
{
Path: "github.com/my/module/js",
@ -498,7 +498,7 @@ func TestFetchVersion(t *testing.T) {
"LICENSE.md": testhelper.MITLicense,
},
want: &internal.Version{
VersionInfo: wantVersionInfoGoMod,
ModuleInfo: wantModuleInfoGoMod,
Packages: []*internal.Package{
{
Path: "github.com/my/module/foo",

Просмотреть файл

@ -110,32 +110,32 @@ func (s *Server) serveDirectoryPageWithDirectory(ctx context.Context, w http.Res
// the module path. However, on the package and directory view's
// "Subdirectories" tab, we do not want to include packages whose import paths
// are the same as the dirPath.
func fetchDirectoryDetails(ctx context.Context, ds internal.DataSource, dirPath string, vi *internal.VersionInfo,
func fetchDirectoryDetails(ctx context.Context, ds internal.DataSource, dirPath string, mi *internal.ModuleInfo,
licmetas []*licenses.Metadata, includeDirPath bool) (_ *Directory, err error) {
defer derrors.Wrap(&err, "s.ds.fetchDirectoryDetails(%q, %q, %q, %v)", dirPath, vi.ModulePath, vi.Version, licmetas)
defer derrors.Wrap(&err, "s.ds.fetchDirectoryDetails(%q, %q, %q, %v)", dirPath, mi.ModulePath, mi.Version, licmetas)
if includeDirPath && dirPath != vi.ModulePath && dirPath != stdlib.ModulePath {
if includeDirPath && dirPath != mi.ModulePath && dirPath != stdlib.ModulePath {
return nil, fmt.Errorf("includeDirPath can only be set to true if dirPath = modulePath: %w", derrors.InvalidArgument)
}
if dirPath == stdlib.ModulePath {
pkgs, err := ds.GetPackagesInVersion(ctx, stdlib.ModulePath, vi.Version)
pkgs, err := ds.GetPackagesInVersion(ctx, stdlib.ModulePath, mi.Version)
if err != nil {
return nil, err
}
return createDirectory(&internal.Directory{
VersionInfo: *vi,
Path: dirPath,
Packages: pkgs,
ModuleInfo: *mi,
Path: dirPath,
Packages: pkgs,
}, licmetas, includeDirPath)
}
dbDir, err := ds.GetDirectory(ctx, dirPath, vi.ModulePath, vi.Version, internal.AllFields)
dbDir, err := ds.GetDirectory(ctx, dirPath, mi.ModulePath, mi.Version, internal.AllFields)
if errors.Is(err, derrors.NotFound) {
return createDirectory(&internal.Directory{
VersionInfo: *vi,
Path: dirPath,
Packages: nil,
ModuleInfo: *mi,
Path: dirPath,
Packages: nil,
}, licmetas, includeDirPath)
}
if err != nil {
@ -161,7 +161,7 @@ func createDirectory(dbDir *internal.Directory, licmetas []*licenses.Metadata, i
if !includeDirPath && pkg.Path == dbDir.Path {
continue
}
newPkg, err := createPackage(pkg, &dbDir.VersionInfo, false)
newPkg, err := createPackage(pkg, &dbDir.ModuleInfo, false)
if err != nil {
return nil, err
}
@ -174,7 +174,7 @@ func createDirectory(dbDir *internal.Directory, licmetas []*licenses.Metadata, i
}
packages = append(packages, newPkg)
}
mod := createModule(&dbDir.VersionInfo, licmetas, false)
mod := createModule(&dbDir.ModuleInfo, licmetas, false)
sort.Slice(packages, func(i, j int) bool { return packages[i].Path < packages[j].Path })
return &Directory{

Просмотреть файл

@ -29,15 +29,15 @@ func TestFetchDirectoryDetails(t *testing.T) {
checkDirectory := func(got *Directory, dirPath, modulePath, version string, pkgPaths []string) {
t.Helper()
vi := sample.VersionInfo()
vi.ModulePath = modulePath
vi.Version = version
mi := sample.ModuleInfo()
mi.ModulePath = modulePath
mi.Version = version
var wantPkgs []*Package
for _, path := range pkgPaths {
sp := sample.Package()
sp.Path = path
pkg, err := createPackage(sp, vi, false)
pkg, err := createPackage(sp, mi, false)
if err != nil {
t.Fatal(err)
}
@ -48,12 +48,12 @@ func TestFetchDirectoryDetails(t *testing.T) {
wantPkgs = append(wantPkgs, pkg)
}
mod := createModule(vi, sample.LicenseMetadata, false)
mod := createModule(mi, sample.LicenseMetadata, false)
want := &Directory{
Module: *mod,
Path: dirPath,
Packages: wantPkgs,
URL: constructDirectoryURL(dirPath, vi.ModulePath, linkVersion(vi.Version, vi.ModulePath)),
URL: constructDirectoryURL(dirPath, mi.ModulePath, linkVersion(mi.Version, mi.ModulePath)),
}
if diff := cmp.Diff(want, got); diff != "" {
t.Errorf("fetchDirectoryDetails(ctx, %q, %q, %q) mismatch (-want +got):\n%s", dirPath, modulePath, version, diff)
@ -148,12 +148,12 @@ func TestFetchDirectoryDetails(t *testing.T) {
},
} {
t.Run(tc.name, func(t *testing.T) {
vi := sample.VersionInfo()
vi.ModulePath = tc.modulePath
vi.Version = tc.version
mi := sample.ModuleInfo()
mi.ModulePath = tc.modulePath
mi.Version = tc.version
got, err := fetchDirectoryDetails(ctx, testDB,
tc.dirPath, vi, sample.LicenseMetadata, tc.includeDirPath)
tc.dirPath, mi, sample.LicenseMetadata, tc.includeDirPath)
if err != nil {
t.Fatal(err)
}
@ -201,12 +201,12 @@ func TestFetchDirectoryDetailsInvalidArguments(t *testing.T) {
},
} {
t.Run(tc.name, func(t *testing.T) {
vi := sample.VersionInfo()
vi.ModulePath = tc.modulePath
vi.Version = tc.version
mi := sample.ModuleInfo()
mi.ModulePath = tc.modulePath
mi.Version = tc.version
got, err := fetchDirectoryDetails(ctx, testDB,
tc.dirPath, vi, sample.LicenseMetadata, tc.includeDirPath)
tc.dirPath, mi, sample.LicenseMetadata, tc.includeDirPath)
if !errors.Is(err, derrors.InvalidArgument) {
t.Fatalf("expected err; got = \n%+v, %v", got, err)
}

Просмотреть файл

@ -49,10 +49,10 @@ type Module struct {
// latestRequested indicates whether the user requested the latest
// version of the package. If so, the returned Package.URL will have the
// structure /<path> instead of /<path>@<version>.
func createPackage(pkg *internal.Package, vi *internal.VersionInfo, latestRequested bool) (_ *Package, err error) {
defer derrors.Wrap(&err, "createPackage(%v, %v)", pkg, vi)
func createPackage(pkg *internal.Package, mi *internal.ModuleInfo, latestRequested bool) (_ *Package, err error) {
defer derrors.Wrap(&err, "createPackage(%v, %v)", pkg, mi)
if pkg == nil || vi == nil {
if pkg == nil || mi == nil {
return nil, fmt.Errorf("package and version info must not be nil")
}
@ -63,7 +63,7 @@ func createPackage(pkg *internal.Package, vi *internal.VersionInfo, latestReques
}
}
m := createModule(vi, modLicenses, latestRequested)
m := createModule(mi, modLicenses, latestRequested)
urlVersion := m.LinkVersion
if latestRequested {
urlVersion = internal.LatestVersion
@ -74,8 +74,8 @@ func createPackage(pkg *internal.Package, vi *internal.VersionInfo, latestReques
IsRedistributable: pkg.IsRedistributable,
Licenses: transformLicenseMetadata(pkg.Licenses),
Module: *m,
URL: constructPackageURL(pkg.Path, vi.ModulePath, urlVersion),
LatestURL: constructPackageURL(pkg.Path, vi.ModulePath, middleware.LatestVersionPlaceholder),
URL: constructPackageURL(pkg.Path, mi.ModulePath, urlVersion),
LatestURL: constructPackageURL(pkg.Path, mi.ModulePath, middleware.LatestVersionPlaceholder),
}, nil
}
@ -85,20 +85,20 @@ func createPackage(pkg *internal.Package, vi *internal.VersionInfo, latestReques
// latestRequested indicates whether the user requested the latest
// version of the package. If so, the returned Module.URL will have the
// structure /<path> instead of /<path>@<version>.
func createModule(vi *internal.VersionInfo, licmetas []*licenses.Metadata, latestRequested bool) *Module {
urlVersion := linkVersion(vi.Version, vi.ModulePath)
func createModule(mi *internal.ModuleInfo, licmetas []*licenses.Metadata, latestRequested bool) *Module {
urlVersion := linkVersion(mi.Version, mi.ModulePath)
if latestRequested {
urlVersion = internal.LatestVersion
}
return &Module{
DisplayVersion: displayVersion(vi.Version, vi.ModulePath),
LinkVersion: linkVersion(vi.Version, vi.ModulePath),
ModulePath: vi.ModulePath,
CommitTime: elapsedTime(vi.CommitTime),
IsRedistributable: vi.IsRedistributable,
DisplayVersion: displayVersion(mi.Version, mi.ModulePath),
LinkVersion: linkVersion(mi.Version, mi.ModulePath),
ModulePath: mi.ModulePath,
CommitTime: elapsedTime(mi.CommitTime),
IsRedistributable: mi.IsRedistributable,
Licenses: transformLicenseMetadata(licmetas),
URL: constructModuleURL(vi.ModulePath, urlVersion),
LatestURL: constructModuleURL(vi.ModulePath, middleware.LatestVersionPlaceholder),
URL: constructModuleURL(mi.ModulePath, urlVersion),
LatestURL: constructModuleURL(mi.ModulePath, middleware.LatestVersionPlaceholder),
}
}

Просмотреть файл

@ -144,7 +144,7 @@ func TestCreatePackageHeader(t *testing.T) {
} {
t.Run(tc.label, func(t *testing.T) {
got, err := createPackage(&tc.pkg.Package, &tc.pkg.VersionInfo, false)
got, err := createPackage(&tc.pkg.Package, &tc.pkg.ModuleInfo, false)
if err != nil {
t.Fatal(err)
}

Просмотреть файл

@ -41,7 +41,7 @@ func fetchImportsDetails(ctx context.Context, ds internal.DataSource, pkg *inter
for _, p := range dsImports {
if stdlib.Contains(p) {
std = append(std, p)
} else if strings.HasPrefix(p+"/", pkg.VersionInfo.ModulePath+"/") {
} else if strings.HasPrefix(p+"/", pkg.ModuleInfo.ModulePath+"/") {
moduleImports = append(moduleImports, p)
} else {
externalImports = append(externalImports, p)
@ -49,7 +49,7 @@ func fetchImportsDetails(ctx context.Context, ds internal.DataSource, pkg *inter
}
return &ImportsDetails{
ModulePath: pkg.VersionInfo.ModulePath,
ModulePath: pkg.ModuleInfo.ModulePath,
ExternalImports: externalImports,
InternalImports: moduleImports,
StdLib: std,
@ -90,7 +90,7 @@ func fetchImportedByDetails(ctx context.Context, ds internal.DataSource, pkg *in
}
sections := Sections(importedBy, nextPrefixAccount)
return &ImportedByDetails{
ModulePath: pkg.VersionInfo.ModulePath,
ModulePath: pkg.ModuleInfo.ModulePath,
ImportedBy: sections,
Total: len(importedBy),
TotalIsExact: totalIsExact,

Просмотреть файл

@ -63,7 +63,7 @@ func TestFetchImportsDetails(t *testing.T) {
version.Packages[0].Path, version.Version, got, err, tc.wantDetails)
}
tc.wantDetails.ModulePath = version.VersionInfo.ModulePath
tc.wantDetails.ModulePath = version.ModuleInfo.ModulePath
if diff := cmp.Diff(tc.wantDetails, got); diff != "" {
t.Errorf("fetchImportsDetails(ctx, %q, %q) mismatch (-want +got):\n%s", version.Packages[0].Path, version.Version, diff)
}
@ -76,8 +76,8 @@ func TestFetchImportsDetails(t *testing.T) {
// version.
func firstVersionedPackage(v *internal.Version) *internal.VersionedPackage {
return &internal.VersionedPackage{
Package: *v.Packages[0],
VersionInfo: v.VersionInfo,
Package: *v.Packages[0],
ModuleInfo: v.ModuleInfo,
}
}
@ -155,7 +155,7 @@ func TestFetchImportedByDetails(t *testing.T) {
tc.pkg.Path, got, err, tc.wantDetails)
}
tc.wantDetails.ModulePath = vp.VersionInfo.ModulePath
tc.wantDetails.ModulePath = vp.ModuleInfo.ModulePath
if diff := cmp.Diff(tc.wantDetails, got); diff != "" {
t.Errorf("fetchImportedByDetails(ctx, db, %q) mismatch (-want +got):\n%s", tc.pkg.Path, diff)
}

Просмотреть файл

@ -32,10 +32,10 @@ func (s *Server) LatestVersion(ctx context.Context, packagePath, modulePath, pag
func (s *Server) latestVersion(ctx context.Context, packagePath, modulePath, pageType string) (_ string, err error) {
defer derrors.Wrap(&err, "latestVersion(ctx, %q, %q)", modulePath, packagePath)
var vi *internal.VersionInfo
var mi *internal.ModuleInfo
switch pageType {
case "mod":
vi, err = s.ds.GetVersionInfo(ctx, modulePath, internal.LatestVersion)
mi, err = s.ds.GetModuleInfo(ctx, modulePath, internal.LatestVersion)
if err != nil {
return "", err
}
@ -44,10 +44,10 @@ func (s *Server) latestVersion(ctx context.Context, packagePath, modulePath, pag
if err != nil {
return "", err
}
vi = &pkg.VersionInfo
mi = &pkg.ModuleInfo
default:
// For directories we don't have a well-defined latest version.
return "", nil
}
return linkVersion(vi.Version, modulePath), nil
return linkVersion(mi.Version, modulePath), nil
}

Просмотреть файл

@ -34,7 +34,7 @@ type LicenseMetadata struct {
// fetchPackageLicensesDetails fetches license data for the package version specified by
// path and version from the database and returns a LicensesDetails.
func fetchPackageLicensesDetails(ctx context.Context, ds internal.DataSource, pkg *internal.VersionedPackage) (*LicensesDetails, error) {
dsLicenses, err := ds.GetPackageLicenses(ctx, pkg.Path, pkg.ModulePath, pkg.VersionInfo.Version)
dsLicenses, err := ds.GetPackageLicenses(ctx, pkg.Path, pkg.ModulePath, pkg.ModuleInfo.Version)
if err != nil {
return nil, err
}

Просмотреть файл

@ -53,9 +53,9 @@ func (s *Server) serveModulePage(w http.ResponseWriter, r *http.Request, moduleP
// a. We don't know anything about this module: just serve a 404
// b. We have valid versions for this module path, but `version` isn't
// one of them. Serve a 404 but recommend the other versions.
vi, err := s.ds.GetVersionInfo(ctx, modulePath, version)
mi, err := s.ds.GetModuleInfo(ctx, modulePath, version)
if err == nil {
s.serveModulePageWithModule(ctx, w, r, vi, version)
s.serveModulePageWithModule(ctx, w, r, mi, version)
return
}
if !errors.Is(err, derrors.NotFound) {
@ -63,7 +63,7 @@ func (s *Server) serveModulePage(w http.ResponseWriter, r *http.Request, moduleP
return
}
if version != internal.LatestVersion {
if _, err := s.ds.GetVersionInfo(ctx, modulePath, internal.LatestVersion); err != nil {
if _, err := s.ds.GetModuleInfo(ctx, modulePath, internal.LatestVersion); err != nil {
log.Errorf(ctx, "error checking for latest module: %v", err)
} else {
epage := &errorPage{
@ -80,15 +80,15 @@ func (s *Server) serveModulePage(w http.ResponseWriter, r *http.Request, moduleP
s.servePathNotFoundErrorPage(w, r, "module")
}
func (s *Server) serveModulePageWithModule(ctx context.Context, w http.ResponseWriter, r *http.Request, vi *internal.VersionInfo, requestedVersion string) {
licenses, err := s.ds.GetModuleLicenses(ctx, vi.ModulePath, vi.Version)
func (s *Server) serveModulePageWithModule(ctx context.Context, w http.ResponseWriter, r *http.Request, mi *internal.ModuleInfo, requestedVersion string) {
licenses, err := s.ds.GetModuleLicenses(ctx, mi.ModulePath, mi.Version)
if err != nil {
log.Errorf(ctx, "error getting module licenses: %v", err)
s.serveErrorPage(w, r, http.StatusInternalServerError, nil)
return
}
modHeader := createModule(vi, licensesToMetadatas(licenses), requestedVersion == internal.LatestVersion)
modHeader := createModule(mi, licensesToMetadatas(licenses), requestedVersion == internal.LatestVersion)
tab := r.FormValue("tab")
settings, ok := moduleTabLookup[tab]
if !ok {
@ -99,7 +99,7 @@ func (s *Server) serveModulePageWithModule(ctx context.Context, w http.ResponseW
var details interface{}
if canShowDetails {
var err error
details, err = fetchDetailsForModule(ctx, r, tab, s.ds, vi, licenses)
details, err = fetchDetailsForModule(ctx, r, tab, s.ds, mi, licenses)
if err != nil {
log.Errorf(ctx, "error fetching page for %q: %v", tab, err)
s.serveErrorPage(w, r, http.StatusInternalServerError, nil)
@ -107,8 +107,8 @@ func (s *Server) serveModulePageWithModule(ctx context.Context, w http.ResponseW
}
}
page := &DetailsPage{
basePage: newBasePage(r, moduleHTMLTitle(vi.ModulePath)),
Title: moduleTitle(vi.ModulePath),
basePage: newBasePage(r, moduleHTMLTitle(mi.ModulePath)),
Title: moduleTitle(mi.ModulePath),
Settings: settings,
Header: modHeader,
BreadcrumbPath: breadcrumbPath(modHeader.ModulePath, modHeader.ModulePath, modHeader.LinkVersion),

Просмотреть файл

@ -34,29 +34,29 @@ type OverviewDetails struct {
// versionedLinks says whether the constructed URLs should have versions.
// constructOverviewDetails uses the given version to construct an OverviewDetails.
func constructOverviewDetails(vi *internal.VersionInfo, isRedistributable bool, versionedLinks bool) *OverviewDetails {
func constructOverviewDetails(mi *internal.ModuleInfo, isRedistributable bool, versionedLinks bool) *OverviewDetails {
var lv string
if versionedLinks {
lv = linkVersion(vi.Version, vi.ModulePath)
lv = linkVersion(mi.Version, mi.ModulePath)
} else {
lv = internal.LatestVersion
}
overview := &OverviewDetails{
ModulePath: vi.ModulePath,
ModuleURL: constructModuleURL(vi.ModulePath, lv),
RepositoryURL: vi.SourceInfo.RepoURL(),
ModulePath: mi.ModulePath,
ModuleURL: constructModuleURL(mi.ModulePath, lv),
RepositoryURL: mi.SourceInfo.RepoURL(),
Redistributable: isRedistributable,
}
if overview.Redistributable {
overview.ReadMeSource = fileSource(vi.ModulePath, vi.Version, vi.ReadmeFilePath)
overview.ReadMe = readmeHTML(vi)
overview.ReadMeSource = fileSource(mi.ModulePath, mi.Version, mi.ReadmeFilePath)
overview.ReadMe = readmeHTML(mi)
}
return overview
}
// constructPackageOverviewDetails uses data for the given package to return an OverviewDetails.
func constructPackageOverviewDetails(pkg *internal.VersionedPackage, versionedLinks bool) *OverviewDetails {
od := constructOverviewDetails(&pkg.VersionInfo, pkg.Package.IsRedistributable, versionedLinks)
od := constructOverviewDetails(&pkg.ModuleInfo, pkg.Package.IsRedistributable, versionedLinks)
od.PackageSourceURL = pkg.SourceInfo.DirectoryURL(packageSubdir(pkg.Path, pkg.ModulePath))
if !pkg.Package.IsRedistributable {
od.Redistributable = false
@ -79,12 +79,12 @@ func packageSubdir(pkgPath, modulePath string) string {
// readmeHTML sanitizes readmeContents based on bluemondy.UGCPolicy and returns
// a template.HTML. If readmeFilePath indicates that this is a markdown file,
// it will also render the markdown contents using blackfriday.
func readmeHTML(vi *internal.VersionInfo) template.HTML {
if len(vi.ReadmeContents) == 0 {
func readmeHTML(mi *internal.ModuleInfo) template.HTML {
if len(mi.ReadmeContents) == 0 {
return ""
}
if !isMarkdown(vi.ReadmeFilePath) {
return template.HTML(fmt.Sprintf(`<pre class="readme">%s</pre>`, html.EscapeString(string(vi.ReadmeContents))))
if !isMarkdown(mi.ReadmeFilePath) {
return template.HTML(fmt.Sprintf(`<pre class="readme">%s</pre>`, html.EscapeString(string(mi.ReadmeContents))))
}
// bluemonday.UGCPolicy allows a broad selection of HTML elements and
@ -104,10 +104,10 @@ func readmeHTML(vi *internal.VersionInfo) template.HTML {
// Render HTML similar to blackfriday.Run(), but here we implement a custom
// Walk function in order to modify image paths in the rendered HTML.
b := &bytes.Buffer{}
rootNode := parser.Parse([]byte(vi.ReadmeContents))
rootNode := parser.Parse([]byte(mi.ReadmeContents))
rootNode.Walk(func(node *blackfriday.Node, entering bool) blackfriday.WalkStatus {
if node.Type == blackfriday.Image || node.Type == blackfriday.Link {
translateRelativeLink(node, vi)
translateRelativeLink(node, mi)
}
return renderer.RenderNode(b, node, entering)
})
@ -128,7 +128,7 @@ func isMarkdown(filename string) bool {
// image files inside the repository. As the discovery site doesn't host the
// full repository content, in order for the image to render, we need to
// convert the relative path to an absolute URL to a hosted image.
func translateRelativeLink(node *blackfriday.Node, vi *internal.VersionInfo) {
func translateRelativeLink(node *blackfriday.Node, mi *internal.ModuleInfo) {
destURL, err := url.Parse(string(node.LinkData.Destination))
if err != nil || destURL.IsAbs() {
return
@ -139,12 +139,12 @@ func translateRelativeLink(node *blackfriday.Node, vi *internal.VersionInfo) {
return
}
// Paths are relative to the README location.
destPath := path.Join(path.Dir(vi.ReadmeFilePath), path.Clean(destURL.Path))
destPath := path.Join(path.Dir(mi.ReadmeFilePath), path.Clean(destURL.Path))
var newURL string
if node.Type == blackfriday.Image {
newURL = vi.SourceInfo.RawURL(destPath)
newURL = mi.SourceInfo.RawURL(destPath)
} else {
newURL = vi.SourceInfo.FileURL(destPath)
newURL = mi.SourceInfo.FileURL(destPath)
}
if newURL != "" {
node.LinkData.Destination = []byte(newURL)

Просмотреть файл

@ -45,7 +45,7 @@ func TestFetchOverviewDetails(t *testing.T) {
t.Fatal(err)
}
got := constructOverviewDetails(&tc.version.VersionInfo, true, true)
got := constructOverviewDetails(&tc.version.ModuleInfo, true, true)
if diff := cmp.Diff(tc.wantDetails, got); diff != "" {
t.Errorf("constructOverviewDetails(%q, %q) mismatch (-want +got):\n%s", tc.version.Packages[0].Path, tc.version.Version, diff)
}
@ -54,12 +54,12 @@ func TestFetchOverviewDetails(t *testing.T) {
func TestReadmeHTML(t *testing.T) {
testCases := []struct {
name string
vi *internal.VersionInfo
mi *internal.ModuleInfo
want template.HTML
}{
{
name: "valid markdown readme",
vi: &internal.VersionInfo{
mi: &internal.ModuleInfo{
ReadmeFilePath: "README.md",
ReadmeContents: "This package collects pithy sayings.\n\n" +
"It's part of a demonstration of\n" +
@ -71,7 +71,7 @@ func TestReadmeHTML(t *testing.T) {
},
{
name: "valid markdown readme with alternative case and extension",
vi: &internal.VersionInfo{
mi: &internal.ModuleInfo{
ReadmeFilePath: "README.MARKDOWN",
ReadmeContents: "This package collects pithy sayings.\n\n" +
"It's part of a demonstration of\n" +
@ -83,7 +83,7 @@ func TestReadmeHTML(t *testing.T) {
},
{
name: "not markdown readme",
vi: &internal.VersionInfo{
mi: &internal.ModuleInfo{
ReadmeFilePath: "README.rst",
ReadmeContents: "This package collects pithy sayings.\n\n" +
"It's part of a demonstration of\n" +
@ -93,12 +93,12 @@ func TestReadmeHTML(t *testing.T) {
},
{
name: "empty readme",
vi: &internal.VersionInfo{},
mi: &internal.ModuleInfo{},
want: "",
},
{
name: "sanitized readme",
vi: &internal.VersionInfo{
mi: &internal.ModuleInfo{
ReadmeFilePath: "README",
ReadmeContents: `<a onblur="alert(secret)" href="http://www.google.com">Google</a>`,
},
@ -106,7 +106,7 @@ func TestReadmeHTML(t *testing.T) {
},
{
name: "relative image markdown is made absolute for GitHub",
vi: &internal.VersionInfo{
mi: &internal.ModuleInfo{
ReadmeFilePath: "README.md",
ReadmeContents: "![Go logo](doc/logo.png)",
SourceInfo: source.NewGitHubInfo("http://github.com/golang/go", "", "master"),
@ -115,7 +115,7 @@ func TestReadmeHTML(t *testing.T) {
},
{
name: "relative image markdown is made absolute for GitLab",
vi: &internal.VersionInfo{
mi: &internal.ModuleInfo{
ReadmeFilePath: "README.md",
ReadmeContents: "![Gitaly benchmark timings.](doc/img/rugged-new-timings.png)",
SourceInfo: source.NewGitLabInfo("http://gitlab.com/gitlab-org/gitaly", "", "v1.0.0"),
@ -124,7 +124,7 @@ func TestReadmeHTML(t *testing.T) {
},
{
name: "relative image markdown is left alone for unknown origins",
vi: &internal.VersionInfo{
mi: &internal.ModuleInfo{
ReadmeFilePath: "README.md",
ReadmeContents: "![Go logo](doc/logo.png)",
},
@ -132,7 +132,7 @@ func TestReadmeHTML(t *testing.T) {
},
{
name: "module versions are referenced in relative images",
vi: &internal.VersionInfo{
mi: &internal.ModuleInfo{
ReadmeFilePath: "README.md",
ReadmeContents: "![Hugo logo](doc/logo.png)",
Version: "v0.56.3",
@ -143,7 +143,7 @@ func TestReadmeHTML(t *testing.T) {
},
{
name: "image URLs relative to README directory",
vi: &internal.VersionInfo{
mi: &internal.ModuleInfo{
ReadmeFilePath: "dir/sub/README.md",
ReadmeContents: "![alt](img/thing.png)",
Version: "v1.2.3",
@ -154,7 +154,7 @@ func TestReadmeHTML(t *testing.T) {
},
{
name: "non-image links relative to README directory",
vi: &internal.VersionInfo{
mi: &internal.ModuleInfo{
ReadmeFilePath: "dir/sub/README.md",
ReadmeContents: "[something](doc/thing.md)",
Version: "v1.2.3",
@ -166,9 +166,9 @@ func TestReadmeHTML(t *testing.T) {
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
got := readmeHTML(tc.vi)
got := readmeHTML(tc.mi)
if diff := cmp.Diff(tc.want, got); diff != "" {
t.Errorf("readmeHTML(%v) mismatch (-want +got):\n%s", tc.vi, diff)
t.Errorf("readmeHTML(%v) mismatch (-want +got):\n%s", tc.mi, diff)
}
})
}

Просмотреть файл

@ -106,7 +106,7 @@ func (s *Server) servePackagePage(w http.ResponseWriter, r *http.Request, pkgPat
func (s *Server) servePackagePageWithPackage(ctx context.Context, w http.ResponseWriter, r *http.Request, pkg *internal.VersionedPackage, requestedVersion string) {
pkgHeader, err := createPackage(&pkg.Package, &pkg.VersionInfo, requestedVersion == internal.LatestVersion)
pkgHeader, err := createPackage(&pkg.Package, &pkg.ModuleInfo, requestedVersion == internal.LatestVersion)
if err != nil {
log.Errorf(ctx, "error creating package header for %s@%s: %v", pkg.Path, pkg.Version, err)
s.serveErrorPage(w, r, http.StatusInternalServerError, nil)

Просмотреть файл

@ -142,9 +142,9 @@ func searchRequestRedirectPath(ctx context.Context, ds internal.DataSource, quer
return ""
}
vi, err := ds.GetVersionInfo(ctx, requestedPath, internal.LatestVersion)
mi, err := ds.GetModuleInfo(ctx, requestedPath, internal.LatestVersion)
if err == nil {
return fmt.Sprintf("/mod/%s", vi.ModulePath)
return fmt.Sprintf("/mod/%s", mi.ModulePath)
} else if !errors.Is(err, derrors.NotFound) {
log.Errorf(ctx, "error getting module for %s: %v", requestedPath, err)
return ""

Просмотреть файл

@ -24,7 +24,7 @@ func TestFetchSearchPage(t *testing.T) {
var (
now = sample.NowTruncated()
versionFoo = &internal.Version{
VersionInfo: internal.VersionInfo{
ModuleInfo: internal.ModuleInfo{
ModulePath: "github.com/mod/foo",
Version: "v1.0.0",
ReadmeContents: "readme",
@ -43,7 +43,7 @@ func TestFetchSearchPage(t *testing.T) {
},
}
versionBar = &internal.Version{
VersionInfo: internal.VersionInfo{
ModuleInfo: internal.ModuleInfo{
ModulePath: "github.com/mod/bar",
Version: "v1.0.0",
ReadmeContents: "readme",

Просмотреть файл

@ -148,7 +148,7 @@ func fetchDetailsForPackage(ctx context.Context, r *http.Request, tab string, ds
case "versions":
return fetchPackageVersionsDetails(ctx, ds, pkg)
case "subdirectories":
return fetchDirectoryDetails(ctx, ds, pkg.Path, &pkg.VersionInfo, pkg.Licenses, false)
return fetchDirectoryDetails(ctx, ds, pkg.Path, &pkg.ModuleInfo, pkg.Licenses, false)
case "imports":
return fetchImportsDetails(ctx, ds, pkg)
case "importedby":
@ -167,17 +167,17 @@ func urlIsVersioned(url *url.URL) bool {
// fetchDetailsForModule returns tab details by delegating to the correct detail
// handler.
func fetchDetailsForModule(ctx context.Context, r *http.Request, tab string, ds internal.DataSource, vi *internal.VersionInfo, licenses []*licenses.License) (interface{}, error) {
func fetchDetailsForModule(ctx context.Context, r *http.Request, tab string, ds internal.DataSource, mi *internal.ModuleInfo, licenses []*licenses.License) (interface{}, error) {
switch tab {
case "packages":
return fetchDirectoryDetails(ctx, ds, vi.ModulePath, vi, licensesToMetadatas(licenses), true)
return fetchDirectoryDetails(ctx, ds, mi.ModulePath, mi, licensesToMetadatas(licenses), true)
case "licenses":
return &LicensesDetails{Licenses: transformLicenses(vi.ModulePath, vi.Version, licenses)}, nil
return &LicensesDetails{Licenses: transformLicenses(mi.ModulePath, mi.Version, licenses)}, nil
case "versions":
return fetchModuleVersionsDetails(ctx, ds, vi)
return fetchModuleVersionsDetails(ctx, ds, mi)
case "overview":
// TODO(b/138448402): implement remaining module views.
return constructOverviewDetails(vi, vi.IsRedistributable, urlIsVersioned(r.URL)), nil
return constructOverviewDetails(mi, mi.IsRedistributable, urlIsVersioned(r.URL)), nil
}
return nil, fmt.Errorf("BUG: unable to fetch details: unknown tab %q", tab)
}
@ -187,7 +187,7 @@ func fetchDetailsForModule(ctx context.Context, r *http.Request, tab string, ds
func constructDetailsForDirectory(r *http.Request, tab string, dir *internal.Directory, licenses []*licenses.License) (interface{}, error) {
switch tab {
case "overview":
return constructOverviewDetails(&dir.VersionInfo, dir.VersionInfo.IsRedistributable, urlIsVersioned(r.URL)), nil
return constructOverviewDetails(&dir.ModuleInfo, dir.ModuleInfo.IsRedistributable, urlIsVersioned(r.URL)), nil
case "subdirectories":
// Ideally we would just use fetchDirectoryDetails here so that it
// follows the same code path as fetchDetailsForModule and

Просмотреть файл

@ -56,23 +56,23 @@ type VersionSummary struct {
// fetchModuleVersionsDetails builds a version hierarchy for module versions
// with the same series path as the given version.
func fetchModuleVersionsDetails(ctx context.Context, ds internal.DataSource, vi *internal.VersionInfo) (*VersionsDetails, error) {
versions, err := ds.GetTaggedVersionsForModule(ctx, vi.ModulePath)
func fetchModuleVersionsDetails(ctx context.Context, ds internal.DataSource, mi *internal.ModuleInfo) (*VersionsDetails, error) {
versions, err := ds.GetTaggedVersionsForModule(ctx, mi.ModulePath)
if err != nil {
return nil, err
}
// If no tagged versions of the module are found, fetch pseudo-versions
// instead.
if len(versions) == 0 {
versions, err = ds.GetPseudoVersionsForModule(ctx, vi.ModulePath)
versions, err = ds.GetPseudoVersionsForModule(ctx, mi.ModulePath)
if err != nil {
return nil, err
}
}
linkify := func(v *internal.VersionInfo) string {
linkify := func(v *internal.ModuleInfo) string {
return constructModuleURL(v.ModulePath, linkVersion(v.Version, v.ModulePath))
}
return buildVersionDetails(vi.ModulePath, versions, linkify), nil
return buildVersionDetails(mi.ModulePath, versions, linkify), nil
}
// fetchPackageVersionsDetails builds a version hierarchy for all module
@ -92,7 +92,7 @@ func fetchPackageVersionsDetails(ctx context.Context, ds internal.DataSource, pk
}
}
var filteredVersions []*internal.VersionInfo
var filteredVersions []*internal.ModuleInfo
// TODO(rfindley): remove this filtering, as it should not be necessary and
// is probably a relic of earlier version query implementations.
for _, v := range versions {
@ -103,22 +103,22 @@ func fetchPackageVersionsDetails(ctx context.Context, ds internal.DataSource, pk
}
}
linkify := func(vi *internal.VersionInfo) string {
linkify := func(mi *internal.ModuleInfo) string {
// Here we have only version information, but need to construct the full
// import path of the package corresponding to this version.
var versionPath string
if vi.ModulePath == stdlib.ModulePath {
if mi.ModulePath == stdlib.ModulePath {
versionPath = pkg.Path
} else {
versionPath = pathInVersion(pkg.V1Path, vi)
versionPath = pathInVersion(pkg.V1Path, mi)
}
return constructPackageURL(versionPath, vi.ModulePath, linkVersion(vi.Version, vi.ModulePath))
return constructPackageURL(versionPath, mi.ModulePath, linkVersion(mi.Version, mi.ModulePath))
}
return buildVersionDetails(pkg.ModulePath, filteredVersions, linkify), nil
}
// pathInVersion constructs the full import path of the package corresponding
// to vi, given its v1 path. To do this, we first compute the suffix of the
// to mi, given its v1 path. To do this, we first compute the suffix of the
// package path in the given module series, and then append it to the real
// (versioned) module path.
//
@ -129,18 +129,18 @@ func fetchPackageVersionsDetails(ctx context.Context, ds internal.DataSource, pk
// 3) Join with the versioned module path foo.com/bar/v2 to get
// foo.com/bar/v2/baz.
// ...being careful about slashes along the way.
func pathInVersion(v1Path string, vi *internal.VersionInfo) string {
suffix := strings.TrimPrefix(strings.TrimPrefix(v1Path, vi.SeriesPath()), "/")
func pathInVersion(v1Path string, mi *internal.ModuleInfo) string {
suffix := strings.TrimPrefix(strings.TrimPrefix(v1Path, mi.SeriesPath()), "/")
if suffix == "" {
return vi.ModulePath
return mi.ModulePath
}
return path.Join(vi.ModulePath, suffix)
return path.Join(mi.ModulePath, suffix)
}
// buildVersionDetails constructs the version hierarchy to be rendered on the
// versions tab, organizing major versions into those that have the same module
// path as the package version under consideration, and those that don't.
func buildVersionDetails(currentModulePath string, versions []*internal.VersionInfo, linkify func(v *internal.VersionInfo) string) *VersionsDetails {
func buildVersionDetails(currentModulePath string, versions []*internal.ModuleInfo, linkify func(v *internal.ModuleInfo) string) *VersionsDetails {
// Pre-sort versions to ensure they are in descending semver order.
sort.Slice(versions, func(i, j int) bool {
return semver.Compare(versions[i].Version, versions[j].Version) > 0
@ -188,16 +188,16 @@ func buildVersionDetails(currentModulePath string, versions []*internal.VersionI
majorTree.forEach(func(_ string, minorTree *versionTree) {
patches := []*VersionSummary{}
minorTree.forEach(func(_ string, patchTree *versionTree) {
vi := patchTree.versionInfo
fmtVersion := displayVersion(vi.Version, vi.ModulePath)
ttversion := vi.Version
if vi.ModulePath == stdlib.ModulePath {
mi := patchTree.versionInfo
fmtVersion := displayVersion(mi.Version, mi.ModulePath)
ttversion := mi.Version
if mi.ModulePath == stdlib.ModulePath {
ttversion = fmtVersion // tooltips will show the Go tag
}
patches = append(patches, &VersionSummary{
TooltipVersion: ttversion,
Link: linkify(vi),
CommitTime: elapsedTime(vi.CommitTime),
Link: linkify(mi),
CommitTime: elapsedTime(mi.CommitTime),
DisplayVersion: fmtVersion,
})
})
@ -228,19 +228,19 @@ type versionTree struct {
// seen tracks the order in which new keys are added.
seen []string
// A tree can hold either a nested subtree or a VersionInfo. When building
// A tree can hold either a nested subtree or a ModuleInfo. When building
// VersionDetails, it has the following hierarchy
// modulePath
// major
// majorMinor
// fullVersion
subTrees map[string]*versionTree
versionInfo *internal.VersionInfo
versionInfo *internal.ModuleInfo
}
// push adds a new version to the version hierarchy, if it doesn't already
// exist.
func (t *versionTree) push(v *internal.VersionInfo, path ...string) {
func (t *versionTree) push(v *internal.ModuleInfo, path ...string) {
if len(path) == 0 {
t.versionInfo = v
return

Просмотреть файл

@ -61,11 +61,11 @@ func TestFetchModuleVersionDetails(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), testTimeout)
defer cancel()
info1 := sample.VersionInfo()
info1 := sample.ModuleInfo()
info1.ModulePath = modulePath1
info1.Version = "v1.2.1"
info2 := sample.VersionInfo()
info2 := sample.ModuleInfo()
info2.ModulePath = modulePath2
info2.Version = "v2.2.1-alpha.1"
@ -77,7 +77,7 @@ func TestFetchModuleVersionDetails(t *testing.T) {
for _, tc := range []struct {
name string
info *internal.VersionInfo
info *internal.ModuleInfo
versions []*internal.Version
wantDetails *VersionsDetails
}{
@ -375,11 +375,11 @@ func TestPathInVersion(t *testing.T) {
}
for _, test := range tests {
vi := sample.VersionInfo()
vi.ModulePath = test.modulePath
if got := pathInVersion(test.v1Path, vi); got != test.want {
t.Errorf("pathInVersion(%q, VersionInfo{...ModulePath:%q}) = %s, want %v",
test.v1Path, vi.ModulePath, got, test.want)
mi := sample.ModuleInfo()
mi.ModulePath = test.modulePath
if got := pathInVersion(test.v1Path, mi); got != test.want {
t.Errorf("pathInVersion(%q, ModuleInfo{...ModulePath:%q}) = %s, want %v",
test.v1Path, mi.ModulePath, got, test.want)
}
}
}

Просмотреть файл

@ -73,21 +73,21 @@ func (db *DB) GetPackagesInVersion(ctx context.Context, modulePath, version stri
// GetTaggedVersionsForPackageSeries returns a list of tagged versions sorted in
// descending semver order. This list includes tagged versions of packages that
// have the same v1path.
func (db *DB) GetTaggedVersionsForPackageSeries(ctx context.Context, pkgPath string) ([]*internal.VersionInfo, error) {
func (db *DB) GetTaggedVersionsForPackageSeries(ctx context.Context, pkgPath string) ([]*internal.ModuleInfo, error) {
return getPackageVersions(ctx, db, pkgPath, []version.Type{version.TypeRelease, version.TypePrerelease})
}
// GetPseudoVersionsForPackageSeries returns the 10 most recent from a list of
// pseudo-versions sorted in descending semver order. This list includes
// pseudo-versions of packages that have the same v1path.
func (db *DB) GetPseudoVersionsForPackageSeries(ctx context.Context, pkgPath string) ([]*internal.VersionInfo, error) {
func (db *DB) GetPseudoVersionsForPackageSeries(ctx context.Context, pkgPath string) ([]*internal.ModuleInfo, error) {
return getPackageVersions(ctx, db, pkgPath, []version.Type{version.TypePseudo})
}
// getPackageVersions returns a list of versions sorted in descending semver
// order. The version types included in the list are specified by a list of
// VersionTypes.
func getPackageVersions(ctx context.Context, db *DB, pkgPath string, versionTypes []version.Type) (_ []*internal.VersionInfo, err error) {
func getPackageVersions(ctx context.Context, db *DB, pkgPath string, versionTypes []version.Type) (_ []*internal.ModuleInfo, err error) {
defer derrors.Wrap(&err, "DB.getPackageVersions(ctx, db, %q, %v)", pkgPath, versionTypes)
baseQuery := `
@ -126,13 +126,13 @@ func getPackageVersions(ctx context.Context, db *DB, pkgPath string, versionType
}
defer rows.Close()
var versionHistory []*internal.VersionInfo
var versionHistory []*internal.ModuleInfo
for rows.Next() {
var vi internal.VersionInfo
if err := rows.Scan(&vi.ModulePath, &vi.Version, &vi.CommitTime); err != nil {
var mi internal.ModuleInfo
if err := rows.Scan(&mi.ModulePath, &mi.Version, &mi.CommitTime); err != nil {
return nil, fmt.Errorf("row.Scan(): %v", err)
}
versionHistory = append(versionHistory, &vi)
versionHistory = append(versionHistory, &mi)
}
if err := rows.Err(); err != nil {
@ -154,20 +154,20 @@ func versionTypeExpr(vts []version.Type) string {
// GetTaggedVersionsForModule returns a list of tagged versions sorted in
// descending semver order.
func (db *DB) GetTaggedVersionsForModule(ctx context.Context, modulePath string) ([]*internal.VersionInfo, error) {
func (db *DB) GetTaggedVersionsForModule(ctx context.Context, modulePath string) ([]*internal.ModuleInfo, error) {
return getModuleVersions(ctx, db, modulePath, []version.Type{version.TypeRelease, version.TypePrerelease})
}
// GetPseudoVersionsForModule returns the 10 most recent from a list of
// pseudo-versions sorted in descending semver order.
func (db *DB) GetPseudoVersionsForModule(ctx context.Context, modulePath string) ([]*internal.VersionInfo, error) {
func (db *DB) GetPseudoVersionsForModule(ctx context.Context, modulePath string) ([]*internal.ModuleInfo, error) {
return getModuleVersions(ctx, db, modulePath, []version.Type{version.TypePseudo})
}
// getModuleVersions returns a list of versions sorted in descending semver
// order. The version types included in the list are specified by a list of
// VersionTypes.
func getModuleVersions(ctx context.Context, db *DB, modulePath string, versionTypes []version.Type) (_ []*internal.VersionInfo, err error) {
func getModuleVersions(ctx context.Context, db *DB, modulePath string, versionTypes []version.Type) (_ []*internal.ModuleInfo, err error) {
// TODO(b/139530312): get information for parent modules.
defer derrors.Wrap(&err, "getModuleVersions(ctx, db, %q, %v)", modulePath, versionTypes)
@ -189,13 +189,13 @@ func getModuleVersions(ctx context.Context, db *DB, modulePath string, versionTy
queryEnd = `LIMIT 10;`
}
query := fmt.Sprintf(baseQuery, versionTypeExpr(versionTypes), queryEnd)
var vinfos []*internal.VersionInfo
var vinfos []*internal.ModuleInfo
collect := func(rows *sql.Rows) error {
var vi internal.VersionInfo
if err := rows.Scan(&vi.ModulePath, &vi.Version, &vi.CommitTime); err != nil {
var mi internal.ModuleInfo
if err := rows.Scan(&mi.ModulePath, &mi.Version, &mi.CommitTime); err != nil {
return err
}
vinfos = append(vinfos, &vi)
vinfos = append(vinfos, &mi)
return nil
}
if err := db.db.RunQuery(ctx, query, collect, internal.SeriesPathForModule(modulePath)); err != nil {
@ -421,10 +421,10 @@ func compareLicenses(i, j *licenses.Metadata) bool {
return i.FilePath < j.FilePath
}
// GetVersionInfo fetches a Version from the database with the primary key
// GetModuleInfo fetches a Version from the database with the primary key
// (module_path, version).
func (db *DB) GetVersionInfo(ctx context.Context, modulePath string, version string) (_ *internal.VersionInfo, err error) {
defer derrors.Wrap(&err, "GetVersionInfo(ctx, %q, %q)", modulePath, version)
func (db *DB) GetModuleInfo(ctx context.Context, modulePath string, version string) (_ *internal.ModuleInfo, err error) {
defer derrors.Wrap(&err, "GetModuleInfo(ctx, %q, %q)", modulePath, version)
query := `
SELECT
@ -458,28 +458,28 @@ func (db *DB) GetVersionInfo(ctx context.Context, modulePath string, version str
}
var (
vi internal.VersionInfo
mi internal.ModuleInfo
hasGoMod sql.NullBool
)
row := db.db.QueryRow(ctx, query, args...)
if err := row.Scan(&vi.ModulePath, &vi.Version, &vi.CommitTime,
database.NullIsEmpty(&vi.ReadmeFilePath), database.NullIsEmpty(&vi.ReadmeContents), &vi.VersionType,
jsonbScanner{&vi.SourceInfo}, &vi.IsRedistributable, &hasGoMod); err != nil {
if err := row.Scan(&mi.ModulePath, &mi.Version, &mi.CommitTime,
database.NullIsEmpty(&mi.ReadmeFilePath), database.NullIsEmpty(&mi.ReadmeContents), &mi.VersionType,
jsonbScanner{&mi.SourceInfo}, &mi.IsRedistributable, &hasGoMod); err != nil {
if err == sql.ErrNoRows {
return nil, fmt.Errorf("module version %s@%s: %w", modulePath, version, derrors.NotFound)
}
return nil, fmt.Errorf("row.Scan(): %v", err)
}
setHasGoMod(&vi, hasGoMod)
return &vi, nil
setHasGoMod(&mi, hasGoMod)
return &mi, nil
}
func setHasGoMod(vi *internal.VersionInfo, nb sql.NullBool) {
func setHasGoMod(mi *internal.ModuleInfo, nb sql.NullBool) {
// The safe default value for HasGoMod is true, because search will penalize modules that don't have one.
// This is temporary: when has_go_mod is fully populated, we'll make it NOT NULL.
vi.HasGoMod = true
mi.HasGoMod = true
if nb.Valid {
vi.HasGoMod = nb.Bool
mi.HasGoMod = nb.Bool
}
}

Просмотреть файл

@ -77,7 +77,7 @@ func TestPostgres_GetVersionInfo_Latest(t *testing.T) {
}
}
gotVI, err := testDB.GetVersionInfo(ctx, tc.path, internal.LatestVersion)
gotVI, err := testDB.GetModuleInfo(ctx, tc.path, internal.LatestVersion)
if err != nil {
if tc.wantErr == nil {
t.Fatalf("got unexpected error %v", err)
@ -90,7 +90,7 @@ func TestPostgres_GetVersionInfo_Latest(t *testing.T) {
if tc.wantIndex >= len(tc.versions) {
t.Fatal("wantIndex too large")
}
wantVI := &tc.versions[tc.wantIndex].VersionInfo
wantVI := &tc.versions[tc.wantIndex].ModuleInfo
if diff := cmp.Diff(wantVI, gotVI, cmpopts.EquateEmpty(), cmp.AllowUnexported(source.Info{})); diff != "" {
t.Errorf("mismatch (-want +got):\n%s", diff)
}
@ -227,7 +227,7 @@ func TestPostgres_GetTaggedAndPseudoVersions(t *testing.T) {
name, path, modulePath string
numPseudo int
versions []*internal.Version
wantTaggedVersions []*internal.VersionInfo
wantTaggedVersions []*internal.ModuleInfo
}{
{
name: "want_releases_and_prereleases_only",
@ -235,7 +235,7 @@ func TestPostgres_GetTaggedAndPseudoVersions(t *testing.T) {
modulePath: modulePath1,
numPseudo: 12,
versions: testVersions,
wantTaggedVersions: []*internal.VersionInfo{
wantTaggedVersions: []*internal.ModuleInfo{
{
ModulePath: modulePath2,
Version: "v2.1.0",
@ -275,7 +275,7 @@ func TestPostgres_GetTaggedAndPseudoVersions(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
defer ResetTestDB(testDB, t)
var wantPseudoVersions []*internal.VersionInfo
var wantPseudoVersions []*internal.ModuleInfo
for i := 0; i < tc.numPseudo; i++ {
pseudo := fmt.Sprintf("v0.0.0-201806111833%02d-d8887717615a", i+1)
@ -290,7 +290,7 @@ func TestPostgres_GetTaggedAndPseudoVersions(t *testing.T) {
// GetPseudoVersions should only return the 10 most recent pseudo versions,
// if there are more than 10 in the database
if i < 10 {
wantPseudoVersions = append(wantPseudoVersions, &internal.VersionInfo{
wantPseudoVersions = append(wantPseudoVersions, &internal.ModuleInfo{
ModulePath: modulePath1,
Version: fmt.Sprintf("v0.0.0-201806111833%02d-d8887717615a", tc.numPseudo-i),
CommitTime: sample.CommitTime,

Просмотреть файл

@ -72,7 +72,7 @@ func (db *DB) GetDirectory(ctx context.Context, dirPath, modulePath, version str
var (
packages []*internal.Package
vi = internal.VersionInfo{ReadmeContents: internal.StringFieldMissing}
mi = internal.ModuleInfo{ReadmeContents: internal.StringFieldMissing}
)
collect := func(rows *sql.Rows) error {
var (
@ -95,23 +95,23 @@ func (db *DB) GetDirectory(ctx context.Context, dirPath, modulePath, version str
&pkg.IsRedistributable,
&pkg.GOOS,
&pkg.GOARCH,
&vi.Version,
&vi.ModulePath,
database.NullIsEmpty(&vi.ReadmeFilePath))
&mi.Version,
&mi.ModulePath,
database.NullIsEmpty(&mi.ReadmeFilePath))
if fields&internal.WithReadmeContents != 0 {
scanArgs = append(scanArgs, database.NullIsEmpty(&vi.ReadmeContents))
scanArgs = append(scanArgs, database.NullIsEmpty(&mi.ReadmeContents))
}
var hasGoMod sql.NullBool
scanArgs = append(scanArgs,
&vi.CommitTime,
&vi.VersionType,
jsonbScanner{&vi.SourceInfo},
&vi.IsRedistributable,
&mi.CommitTime,
&mi.VersionType,
jsonbScanner{&mi.SourceInfo},
&mi.IsRedistributable,
&hasGoMod)
if err := rows.Scan(scanArgs...); err != nil {
return fmt.Errorf("row.Scan(): %v", err)
}
setHasGoMod(&vi, hasGoMod)
setHasGoMod(&mi, hasGoMod)
lics, err := zipLicenseMetadata(licenseTypes, licensePaths)
if err != nil {
return err
@ -130,9 +130,9 @@ func (db *DB) GetDirectory(ctx context.Context, dirPath, modulePath, version str
return packages[i].Path < packages[j].Path
})
return &internal.Directory{
Path: dirPath,
VersionInfo: vi,
Packages: packages,
Path: dirPath,
ModuleInfo: mi,
Packages: packages,
}, nil
}

Просмотреть файл

@ -263,9 +263,9 @@ func TestGetDirectory(t *testing.T) {
t.Fatal(err)
}
vi := sample.VersionInfo()
vi.ModulePath = tc.wantModulePath
vi.Version = tc.wantVersion
mi := sample.ModuleInfo()
mi.ModulePath = tc.wantModulePath
mi.Version = tc.wantVersion
var wantPackages []*internal.Package
for _, path := range tc.wantPkgPaths {
@ -279,9 +279,9 @@ func TestGetDirectory(t *testing.T) {
})
wantDirectory := &internal.Directory{
VersionInfo: *vi,
Packages: wantPackages,
Path: tc.dirPath,
ModuleInfo: *mi,
Packages: wantPackages,
Path: tc.dirPath,
}
opts := []cmp.Option{
cmpopts.EquateEmpty(),

Просмотреть файл

@ -161,18 +161,18 @@ func TestPostgres_ReadAndWriteVersionAndPackages(t *testing.T) {
t.Errorf("second insert error: %v, want write error: %v", err, tc.wantWriteErr)
}
got, err := testDB.GetVersionInfo(ctx, tc.wantModulePath, tc.wantVersion)
got, err := testDB.GetModuleInfo(ctx, tc.wantModulePath, tc.wantVersion)
if tc.wantReadErr != (err != nil) {
t.Fatalf("error: got %v, want read error: %t", err, tc.wantReadErr)
}
if !tc.wantReadErr && got == nil {
t.Fatalf("testDB.GetVersionInfo(ctx, %q, %q) = %v, want %v", tc.wantModulePath, tc.wantVersion, got, tc.version)
t.Fatalf("testDB.GetModuleInfo(ctx, %q, %q) = %v, want %v", tc.wantModulePath, tc.wantVersion, got, tc.version)
}
if tc.version != nil {
if diff := cmp.Diff(&tc.version.VersionInfo, got, cmp.AllowUnexported(source.Info{})); !tc.wantReadErr && diff != "" {
t.Errorf("testDB.GetVersionInfo(ctx, %q, %q) mismatch (-want +got):\n%s", tc.wantModulePath, tc.wantVersion, diff)
if diff := cmp.Diff(&tc.version.ModuleInfo, got, cmp.AllowUnexported(source.Info{})); !tc.wantReadErr && diff != "" {
t.Errorf("testDB.GetModuleInfo(ctx, %q, %q) mismatch (-want +got):\n%s", tc.wantModulePath, tc.wantVersion, diff)
}
}
@ -188,8 +188,8 @@ func TestPostgres_ReadAndWriteVersionAndPackages(t *testing.T) {
}
wantPkg := tc.version.Packages[0]
if gotPkg.VersionInfo.Version != tc.version.Version {
t.Errorf("testDB.GetPackage(ctx, %q, %q) version.version = %v, want %v", tc.wantPkgPath, tc.wantVersion, gotPkg.VersionInfo.Version, tc.version.Version)
if gotPkg.ModuleInfo.Version != tc.version.Version {
t.Errorf("testDB.GetPackage(ctx, %q, %q) version.version = %v, want %v", tc.wantPkgPath, tc.wantVersion, gotPkg.ModuleInfo.Version, tc.version.Version)
}
opts := cmp.Options{
@ -206,7 +206,7 @@ func TestPostgres_ReadAndWriteVersionAndPackages(t *testing.T) {
func TestPostgres_ReadAndWriteVersionOtherColumns(t *testing.T) {
// Verify that InsertVersion correctly populates the columns in the versions
// table that are not in the VersionInfo struct.
// table that are not in the ModuleInfo struct.
defer ResetTestDB(testDB, t)
ctx := context.Background()
@ -252,13 +252,13 @@ func TestPostgres_DeleteVersion(t *testing.T) {
if err := testDB.InsertVersion(ctx, v); err != nil {
t.Fatal(err)
}
if _, err := testDB.GetVersionInfo(ctx, v.ModulePath, v.Version); err != nil {
if _, err := testDB.GetModuleInfo(ctx, v.ModulePath, v.Version); err != nil {
t.Fatal(err)
}
if err := testDB.DeleteVersion(ctx, nil, v.ModulePath, v.Version); err != nil {
t.Fatal(err)
}
if _, err := testDB.GetVersionInfo(ctx, v.ModulePath, v.Version); !errors.Is(err, derrors.NotFound) {
if _, err := testDB.GetModuleInfo(ctx, v.ModulePath, v.Version); !errors.Is(err, derrors.NotFound) {
t.Errorf("got %v, want NotFound", err)
}
}

Просмотреть файл

@ -141,7 +141,7 @@ func (db *DB) GetPackage(ctx context.Context, pkgPath, modulePath, version strin
&pkg.V1Path, pq.Array(&licenseTypes), pq.Array(&licensePaths), &pkg.Package.IsRedistributable,
database.NullIsEmpty(&pkg.DocumentationHTML), &pkg.GOOS, &pkg.GOARCH, &pkg.Version,
&pkg.CommitTime, database.NullIsEmpty(&pkg.ReadmeFilePath), database.NullIsEmpty(&pkg.ReadmeContents),
&pkg.ModulePath, &pkg.VersionType, jsonbScanner{&pkg.SourceInfo}, &pkg.VersionInfo.IsRedistributable,
&pkg.ModulePath, &pkg.VersionType, jsonbScanner{&pkg.SourceInfo}, &pkg.ModuleInfo.IsRedistributable,
&hasGoMod)
if err != nil {
if err == sql.ErrNoRows {
@ -149,7 +149,7 @@ func (db *DB) GetPackage(ctx context.Context, pkgPath, modulePath, version strin
}
return nil, fmt.Errorf("row.Scan(): %v", err)
}
setHasGoMod(&pkg.VersionInfo, hasGoMod)
setHasGoMod(&pkg.ModuleInfo, hasGoMod)
lics, err := zipLicenseMetadata(licenseTypes, licensePaths)
if err != nil {
return nil, err

Просмотреть файл

@ -79,9 +79,9 @@ func (ds *DataSource) GetDirectory(ctx context.Context, dirPath, modulePath, ver
return nil, err
}
return &internal.Directory{
Path: dirPath,
VersionInfo: v.VersionInfo,
Packages: v.Packages,
Path: dirPath,
ModuleInfo: v.ModuleInfo,
Packages: v.Packages,
}, nil
}
@ -174,7 +174,7 @@ func (ds *DataSource) GetPackagesInVersion(ctx context.Context, modulePath, vers
// GetPseudoVersionsForModule returns versions from the the proxy /list
// endpoint, if they are pseudoversions. Otherwise, it returns an empty slice.
func (ds *DataSource) GetPseudoVersionsForModule(ctx context.Context, modulePath string) (_ []*internal.VersionInfo, err error) {
func (ds *DataSource) GetPseudoVersionsForModule(ctx context.Context, modulePath string) (_ []*internal.ModuleInfo, err error) {
defer derrors.Wrap(&err, "GetPseudoVersionsForModule(%q)", modulePath)
return ds.listModuleVersions(ctx, modulePath, true)
}
@ -182,14 +182,14 @@ func (ds *DataSource) GetPseudoVersionsForModule(ctx context.Context, modulePath
// GetPseudoVersionsForPackageSeries finds the longest module path containing
// pkgPath, and returns its versions from the proxy /list endpoint, if they are
// pseudoversions. Otherwise, it returns an empty slice.
func (ds *DataSource) GetPseudoVersionsForPackageSeries(ctx context.Context, pkgPath string) (_ []*internal.VersionInfo, err error) {
func (ds *DataSource) GetPseudoVersionsForPackageSeries(ctx context.Context, pkgPath string) (_ []*internal.ModuleInfo, err error) {
defer derrors.Wrap(&err, "GetPseudoVersionsForPackageSeries(%q)", pkgPath)
return ds.listPackageVersions(ctx, pkgPath, true)
}
// GetTaggedVersionsForModule returns versions from the the proxy /list
// endpoint, if they are tagged versions. Otherwise, it returns an empty slice.
func (ds *DataSource) GetTaggedVersionsForModule(ctx context.Context, modulePath string) (_ []*internal.VersionInfo, err error) {
func (ds *DataSource) GetTaggedVersionsForModule(ctx context.Context, modulePath string) (_ []*internal.ModuleInfo, err error) {
defer derrors.Wrap(&err, "GetTaggedVersionsForModule(%q)", modulePath)
return ds.listModuleVersions(ctx, modulePath, false)
}
@ -197,20 +197,20 @@ func (ds *DataSource) GetTaggedVersionsForModule(ctx context.Context, modulePath
// GetTaggedVersionsForPackageSeries finds the longest module path containing
// pkgPath, and returns its versions from the proxy /list endpoint, if they are
// tagged versions. Otherwise, it returns an empty slice.
func (ds *DataSource) GetTaggedVersionsForPackageSeries(ctx context.Context, pkgPath string) (_ []*internal.VersionInfo, err error) {
func (ds *DataSource) GetTaggedVersionsForPackageSeries(ctx context.Context, pkgPath string) (_ []*internal.ModuleInfo, err error) {
defer derrors.Wrap(&err, "GetTaggedVersionsForPackageSeries(%q)", pkgPath)
return ds.listPackageVersions(ctx, pkgPath, false)
}
// GetVersionInfo returns the VersionInfo as fetched from the proxy for module
// GetModuleInfo returns the ModuleInfo as fetched from the proxy for module
// version specified by modulePath and version.
func (ds *DataSource) GetVersionInfo(ctx context.Context, modulePath, version string) (_ *internal.VersionInfo, err error) {
defer derrors.Wrap(&err, "GetVersionInfo(%q, %q)", modulePath, version)
func (ds *DataSource) GetModuleInfo(ctx context.Context, modulePath, version string) (_ *internal.ModuleInfo, err error) {
defer derrors.Wrap(&err, "GetModuleInfo(%q, %q)", modulePath, version)
v, err := ds.getVersion(ctx, modulePath, version)
if err != nil {
return nil, err
}
return &v.VersionInfo, nil
return &v.ModuleInfo, nil
}
// Search is unimplemented.
@ -296,7 +296,7 @@ func (ds *DataSource) findModule(ctx context.Context, pkgPath string, version st
// calls the proxy /list endpoint to list its versions. If pseudo is true, it
// filters to pseudo versions. If pseudo is false, it filters to tagged
// versions.
func (ds *DataSource) listPackageVersions(ctx context.Context, pkgPath string, pseudo bool) (_ []*internal.VersionInfo, err error) {
func (ds *DataSource) listPackageVersions(ctx context.Context, pkgPath string, pseudo bool) (_ []*internal.ModuleInfo, err error) {
defer derrors.Wrap(&err, "listPackageVersions(%q, %t)", pkgPath, pseudo)
ds.mu.RLock()
mods := ds.packagePathToModules[pkgPath]
@ -318,13 +318,13 @@ func (ds *DataSource) listPackageVersions(ctx context.Context, pkgPath string, p
// calls the proxy /list endpoint to list its versions. If pseudo is true, it
// filters to pseudo versions. If pseudo is false, it filters to tagged
// versions.
func (ds *DataSource) listModuleVersions(ctx context.Context, modulePath string, pseudo bool) (_ []*internal.VersionInfo, err error) {
func (ds *DataSource) listModuleVersions(ctx context.Context, modulePath string, pseudo bool) (_ []*internal.ModuleInfo, err error) {
defer derrors.Wrap(&err, "listModuleVersions(%q, %t)", modulePath, pseudo)
versions, err := ds.proxyClient.ListVersions(ctx, modulePath)
if err != nil {
return nil, err
}
var vis []*internal.VersionInfo
var vis []*internal.ModuleInfo
ds.mu.RLock()
defer ds.mu.RUnlock()
for _, vers := range versions {
@ -335,13 +335,13 @@ func (ds *DataSource) listModuleVersions(ctx context.Context, modulePath string,
continue
}
if v, ok := ds.versionCache[versionKey{modulePath, vers}]; ok {
vis = append(vis, &v.version.VersionInfo)
vis = append(vis, &v.version.ModuleInfo)
} else {
// In this case we can't produce s VersionInfo without fully processing
// In this case we can't produce s ModuleInfo without fully processing
// the module zip, so we instead append a stub. We could further query
// for this version's /info endpoint to get commit time, but that is
// deferred as a potential future enhancement.
vis = append(vis, &internal.VersionInfo{
vis = append(vis, &internal.ModuleInfo{
ModulePath: modulePath,
Version: vers,
})
@ -394,8 +394,8 @@ func packageFromVersion(pkgPath string, v *internal.Version) (_ *internal.Versio
for _, p := range v.Packages {
if p.Path == pkgPath {
return &internal.VersionedPackage{
Package: *p,
VersionInfo: v.VersionInfo,
Package: *p,
ModuleInfo: v.ModuleInfo,
}, nil
}
}

Просмотреть файл

@ -52,7 +52,7 @@ var (
GOOS: "linux",
GOARCH: "amd64",
}
wantVersionInfo = internal.VersionInfo{
wantModuleInfo = internal.ModuleInfo{
ModulePath: "foo.com/bar",
Version: "v1.2.0",
CommitTime: time.Date(2019, 1, 30, 0, 0, 0, 0, time.UTC),
@ -61,8 +61,8 @@ var (
HasGoMod: true,
}
wantVersionedPackage = &internal.VersionedPackage{
VersionInfo: wantVersionInfo,
Package: wantPackage,
ModuleInfo: wantModuleInfo,
Package: wantPackage,
}
cmpOpts = append([]cmp.Option{
cmpopts.IgnoreFields(internal.Package{}, "DocumentationHTML"),
@ -74,9 +74,9 @@ func TestDataSource_GetDirectory(t *testing.T) {
ctx, ds, teardown := setup(t)
defer teardown()
want := &internal.Directory{
Path: "foo.com/bar",
VersionInfo: wantVersionInfo,
Packages: []*internal.Package{&wantPackage},
Path: "foo.com/bar",
ModuleInfo: wantModuleInfo,
Packages: []*internal.Package{&wantPackage},
}
got, err := ds.GetDirectory(ctx, "foo.com/bar", internal.UnknownModulePath, "v1.2.0", internal.AllFields)
if err != nil {
@ -112,15 +112,15 @@ func TestDataSource_GetPackage_Latest(t *testing.T) {
}
}
func TestDataSource_GetVersionInfo_Latest(t *testing.T) {
func TestDataSource_GetModuleInfo_Latest(t *testing.T) {
ctx, ds, teardown := setup(t)
defer teardown()
got, err := ds.GetVersionInfo(ctx, "foo.com/bar", internal.LatestVersion)
got, err := ds.GetModuleInfo(ctx, "foo.com/bar", internal.LatestVersion)
if err != nil {
t.Fatal(err)
}
if diff := cmp.Diff(&wantVersionInfo, got, cmpOpts...); diff != "" {
t.Errorf("GetLatestVersionInfo diff (-want +got):\n%s", diff)
if diff := cmp.Diff(&wantModuleInfo, got, cmpOpts...); diff != "" {
t.Errorf("GetLatestModuleInfo diff (-want +got):\n%s", diff)
}
}
@ -182,10 +182,10 @@ func TestDataSource_GetTaggedVersionsForModule(t *testing.T) {
if err != nil {
t.Fatal(err)
}
v110 := wantVersionInfo
v110 := wantModuleInfo
v110.Version = "v1.1.0"
want := []*internal.VersionInfo{&wantVersionInfo, &v110}
ignore := cmpopts.IgnoreFields(internal.VersionInfo{}, "CommitTime", "VersionType", "IsRedistributable", "HasGoMod")
want := []*internal.ModuleInfo{&wantModuleInfo, &v110}
ignore := cmpopts.IgnoreFields(internal.ModuleInfo{}, "CommitTime", "VersionType", "IsRedistributable", "HasGoMod")
if diff := cmp.Diff(want, got, ignore); diff != "" {
t.Errorf("GetTaggedVersionsForPackageSeries diff (-want +got):\n%s", diff)
}
@ -203,23 +203,23 @@ func TestDataSource_GetTaggedVersionsForPackageSeries(t *testing.T) {
if err != nil {
t.Fatal(err)
}
v110 := wantVersionInfo
v110 := wantModuleInfo
v110.Version = "v1.1.0"
want := []*internal.VersionInfo{&wantVersionInfo, &v110}
ignore := cmpopts.IgnoreFields(internal.VersionInfo{}, "CommitTime", "VersionType", "IsRedistributable", "HasGoMod")
want := []*internal.ModuleInfo{&wantModuleInfo, &v110}
ignore := cmpopts.IgnoreFields(internal.ModuleInfo{}, "CommitTime", "VersionType", "IsRedistributable", "HasGoMod")
if diff := cmp.Diff(want, got, ignore); diff != "" {
t.Errorf("GetTaggedVersionsForPackageSeries diff (-want +got):\n%s", diff)
}
}
func TestDataSource_GetVersionInfo(t *testing.T) {
func TestDataSource_GetModuleInfo(t *testing.T) {
ctx, ds, teardown := setup(t)
defer teardown()
got, err := ds.GetVersionInfo(ctx, "foo.com/bar", "v1.2.0")
got, err := ds.GetModuleInfo(ctx, "foo.com/bar", "v1.2.0")
if err != nil {
t.Fatal(err)
}
if diff := cmp.Diff(&wantVersionInfo, got, cmpOpts...); diff != "" {
t.Errorf("GetVersionInfo diff (-want +got):\n%s", diff)
if diff := cmp.Diff(&wantModuleInfo, got, cmpOpts...); diff != "" {
t.Errorf("GetModuleInfo diff (-want +got):\n%s", diff)
}
}

Просмотреть файл

@ -91,8 +91,8 @@ func Package() *internal.Package {
}
}
func VersionInfo() *internal.VersionInfo {
return &internal.VersionInfo{
func ModuleInfo() *internal.ModuleInfo {
return &internal.ModuleInfo{
ModulePath: ModulePath,
Version: VersionString,
ReadmeFilePath: ReadmeFilePath,
@ -107,16 +107,16 @@ func VersionInfo() *internal.VersionInfo {
func VersionedPackage() *internal.VersionedPackage {
return &internal.VersionedPackage{
VersionInfo: *VersionInfo(),
Package: *Package(),
ModuleInfo: *ModuleInfo(),
Package: *Package(),
}
}
func Version() *internal.Version {
return &internal.Version{
VersionInfo: *VersionInfo(),
Packages: []*internal.Package{Package()},
Licenses: Licenses,
ModuleInfo: *ModuleInfo(),
Packages: []*internal.Package{Package()},
Licenses: Licenses,
}
}