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

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

@ -25,8 +25,8 @@ const (
UnknownModulePath = "unknownModulePath" UnknownModulePath = "unknownModulePath"
) )
// VersionInfo holds metadata associated with a version. // ModuleInfo holds metadata associated with a module.
type VersionInfo struct { type ModuleInfo struct {
ModulePath string ModulePath string
Version string Version string
CommitTime time.Time CommitTime time.Time
@ -60,7 +60,7 @@ type VersionMap struct {
// Examples: // Examples:
// The module paths "a/b" and "a/b/v2" both have series path "a/b". // 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". // 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) return SeriesPathForModule(v.ModulePath)
} }
@ -72,7 +72,7 @@ func SeriesPathForModule(modulePath string) string {
// A Version is a specific, reproducible build of a module. // A Version is a specific, reproducible build of a module.
type Version struct { type Version struct {
VersionInfo ModuleInfo
Packages []*Package Packages []*Package
// Licenses holds all licenses within this module version, including those // Licenses holds all licenses within this module version, including those
// that may be contained in nested subdirectories. // that may be contained in nested subdirectories.
@ -101,13 +101,13 @@ type Package struct {
// information. // information.
type VersionedPackage struct { type VersionedPackage struct {
Package Package
VersionInfo ModuleInfo
} }
// Directory represents a folder in a module version, and all of the packages // Directory represents a folder in a module version, and all of the packages
// inside that folder. // inside that folder.
type Directory struct { type Directory struct {
VersionInfo ModuleInfo
Path string Path string
Packages []*Package Packages []*Package
} }
@ -233,8 +233,8 @@ type AlternativeModulePath struct {
// //
// FieldSet bits are unique across the entire project, because some types are // FieldSet bits are unique across the entire project, because some types are
// concatenations (via embedding) of others. For example, a VersionedPackage // 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 // contains the fields of both a ModuleInfo and a Package, so we can't use the
// same bits for both VersionInfo's ReadmeContents field and Package's // same bits for both ModuleInfo's ReadmeContents field and Package's
// DocumentationHTML field. // DocumentationHTML field.
type FieldSet int64 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. // Verify that the module status is recorded correctly, and that the version is in the DB.
checkStatus(http.StatusOK) checkStatus(http.StatusOK)
if _, err := testDB.GetVersionInfo(ctx, modulePath, version); err != nil { if _, err := testDB.GetModuleInfo(ctx, modulePath, version); err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -112,7 +112,7 @@ func TestFetchAndUpdateState_NotFound(t *testing.T) {
checkStatus(http.StatusNotFound) checkStatus(http.StatusNotFound)
// The module should no longer be in the database. // 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) 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) { if code != wantCode || !errors.Is(err, wantErr) {
t.Fatalf("got %d, %v; want %d, Is(err, %v)", code, err, wantCode, 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) { if !errors.Is(err, derrors.NotFound) {
t.Fatalf("got %v, want Is(NotFound)", err) 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) { if code != wantCode || !errors.Is(err, wantErr) {
t.Fatalf("got %d, %v; want %d, Is(err, derrors.AlternativeModule)", code, err, wantCode) 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) { if !errors.Is(err, derrors.NotFound) {
t.Fatalf("got %v, want Is(NotFound)", err) 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) t.Fatalf("fetchAndInsertVersion(%q, %q, %v, %v): %v", modulePath, version, client, testDB, err)
} }
want := &internal.VersionedPackage{ want := &internal.VersionedPackage{
VersionInfo: internal.VersionInfo{ ModuleInfo: internal.ModuleInfo{
ModulePath: modulePath, ModulePath: modulePath,
Version: version, Version: version,
CommitTime: time.Date(2019, 1, 30, 0, 0, 0, 0, time.UTC), 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 }() defer func() { stdlib.UseTestData = false }()
myModuleV100 := &internal.VersionedPackage{ myModuleV100 := &internal.VersionedPackage{
VersionInfo: internal.VersionInfo{ ModuleInfo: internal.ModuleInfo{
ModulePath: "github.com/my/module", ModulePath: "github.com/my/module",
Version: "v1.0.0", Version: "v1.0.0",
CommitTime: testProxyCommitTime, CommitTime: testProxyCommitTime,
@ -652,7 +652,7 @@ func TestFetchAndInsertVersion(t *testing.T) {
version: "v1.0.0", version: "v1.0.0",
pkg: "nonredistributable.mod/module/bar/baz", pkg: "nonredistributable.mod/module/bar/baz",
want: &internal.VersionedPackage{ want: &internal.VersionedPackage{
VersionInfo: internal.VersionInfo{ ModuleInfo: internal.ModuleInfo{
ModulePath: "nonredistributable.mod/module", ModulePath: "nonredistributable.mod/module",
Version: "v1.0.0", Version: "v1.0.0",
CommitTime: testProxyCommitTime, CommitTime: testProxyCommitTime,
@ -684,7 +684,7 @@ func TestFetchAndInsertVersion(t *testing.T) {
version: "v1.0.0", version: "v1.0.0",
pkg: "nonredistributable.mod/module/foo", pkg: "nonredistributable.mod/module/foo",
want: &internal.VersionedPackage{ want: &internal.VersionedPackage{
VersionInfo: internal.VersionInfo{ ModuleInfo: internal.ModuleInfo{
ModulePath: "nonredistributable.mod/module", ModulePath: "nonredistributable.mod/module",
Version: "v1.0.0", Version: "v1.0.0",
CommitTime: testProxyCommitTime, CommitTime: testProxyCommitTime,
@ -714,7 +714,7 @@ func TestFetchAndInsertVersion(t *testing.T) {
version: "v1.12.5", version: "v1.12.5",
pkg: "context", pkg: "context",
want: &internal.VersionedPackage{ want: &internal.VersionedPackage{
VersionInfo: internal.VersionInfo{ ModuleInfo: internal.ModuleInfo{
ModulePath: "std", ModulePath: "std",
Version: "v1.12.5", Version: "v1.12.5",
CommitTime: stdlib.TestCommitTime, CommitTime: stdlib.TestCommitTime,
@ -747,7 +747,7 @@ func TestFetchAndInsertVersion(t *testing.T) {
version: "v1.12.5", version: "v1.12.5",
pkg: "builtin", pkg: "builtin",
want: &internal.VersionedPackage{ want: &internal.VersionedPackage{
VersionInfo: internal.VersionInfo{ ModuleInfo: internal.ModuleInfo{
ModulePath: "std", ModulePath: "std",
Version: "v1.12.5", Version: "v1.12.5",
CommitTime: stdlib.TestCommitTime, CommitTime: stdlib.TestCommitTime,
@ -780,7 +780,7 @@ func TestFetchAndInsertVersion(t *testing.T) {
version: "v1.12.5", version: "v1.12.5",
pkg: "encoding/json", pkg: "encoding/json",
want: &internal.VersionedPackage{ want: &internal.VersionedPackage{
VersionInfo: internal.VersionInfo{ ModuleInfo: internal.ModuleInfo{
ModulePath: "std", ModulePath: "std",
Version: "v1.12.5", Version: "v1.12.5",
CommitTime: stdlib.TestCommitTime, CommitTime: stdlib.TestCommitTime,
@ -826,7 +826,7 @@ func TestFetchAndInsertVersion(t *testing.T) {
version: "v1.0.0", version: "v1.0.0",
pkg: "build.constraints/module/cpu", pkg: "build.constraints/module/cpu",
want: &internal.VersionedPackage{ want: &internal.VersionedPackage{
VersionInfo: internal.VersionInfo{ ModuleInfo: internal.ModuleInfo{
ModulePath: "build.constraints/module", ModulePath: "build.constraints/module",
Version: "v1.0.0", Version: "v1.0.0",
CommitTime: testProxyCommitTime, 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) 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 { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
if diff := cmp.Diff(test.want.VersionInfo, *gotVersionInfo, cmp.AllowUnexported(source.Info{})); diff != "" { if diff := cmp.Diff(test.want.ModuleInfo, *gotModuleInfo, cmp.AllowUnexported(source.Info{})); diff != "" {
t.Fatalf("testDB.GetVersionInfo(ctx, %q, %q) mismatch (-want +got):\n%s", test.modulePath, test.version, 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) 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")) hasGoMod := zipContainsFilename(zipReader, path.Join(moduleVersionDir(modulePath, resolvedVersion), "go.mod"))
return &FetchResult{ return &FetchResult{
Version: &internal.Version{ Version: &internal.Version{
VersionInfo: internal.VersionInfo{ ModuleInfo: internal.ModuleInfo{
ModulePath: modulePath, ModulePath: modulePath,
Version: resolvedVersion, Version: resolvedVersion,
CommitTime: commitTime, CommitTime: commitTime,

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

@ -400,7 +400,7 @@ func TestFetchVersion(t *testing.T) {
modulePath := "github.com/my/module" modulePath := "github.com/my/module"
vers := "v1.0.0" vers := "v1.0.0"
wantVersionInfo := internal.VersionInfo{ wantModuleInfo := internal.ModuleInfo{
ModulePath: "github.com/my/module", ModulePath: "github.com/my/module",
Version: "v1.0.0", Version: "v1.0.0",
CommitTime: testProxyCommitTime, CommitTime: testProxyCommitTime,
@ -411,8 +411,8 @@ func TestFetchVersion(t *testing.T) {
HasGoMod: false, HasGoMod: false,
SourceInfo: source.NewGitHubInfo("https://github.com/my/module", "", "v1.0.0"), SourceInfo: source.NewGitHubInfo("https://github.com/my/module", "", "v1.0.0"),
} }
wantVersionInfoGoMod := wantVersionInfo wantModuleInfoGoMod := wantModuleInfo
wantVersionInfoGoMod.HasGoMod = true wantModuleInfoGoMod.HasGoMod = true
wantCoverage := sample.LicenseMetadata[0].Coverage wantCoverage := sample.LicenseMetadata[0].Coverage
wantLicenses := []*licenses.License{ wantLicenses := []*licenses.License{
@ -438,7 +438,7 @@ func TestFetchVersion(t *testing.T) {
"LICENSE.md": testhelper.MITLicense, "LICENSE.md": testhelper.MITLicense,
}, },
want: &internal.Version{ want: &internal.Version{
VersionInfo: wantVersionInfo, ModuleInfo: wantModuleInfo,
Packages: []*internal.Package{ Packages: []*internal.Package{
{ {
Path: "github.com/my/module/foo", Path: "github.com/my/module/foo",
@ -470,7 +470,7 @@ func TestFetchVersion(t *testing.T) {
type Value int`, type Value int`,
}, },
want: &internal.Version{ want: &internal.Version{
VersionInfo: wantVersionInfo, ModuleInfo: wantModuleInfo,
Packages: []*internal.Package{ Packages: []*internal.Package{
{ {
Path: "github.com/my/module/js", Path: "github.com/my/module/js",
@ -498,7 +498,7 @@ func TestFetchVersion(t *testing.T) {
"LICENSE.md": testhelper.MITLicense, "LICENSE.md": testhelper.MITLicense,
}, },
want: &internal.Version{ want: &internal.Version{
VersionInfo: wantVersionInfoGoMod, ModuleInfo: wantModuleInfoGoMod,
Packages: []*internal.Package{ Packages: []*internal.Package{
{ {
Path: "github.com/my/module/foo", 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 // the module path. However, on the package and directory view's
// "Subdirectories" tab, we do not want to include packages whose import paths // "Subdirectories" tab, we do not want to include packages whose import paths
// are the same as the dirPath. // 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) { 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) return nil, fmt.Errorf("includeDirPath can only be set to true if dirPath = modulePath: %w", derrors.InvalidArgument)
} }
if dirPath == stdlib.ModulePath { 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 { if err != nil {
return nil, err return nil, err
} }
return createDirectory(&internal.Directory{ return createDirectory(&internal.Directory{
VersionInfo: *vi, ModuleInfo: *mi,
Path: dirPath, Path: dirPath,
Packages: pkgs, Packages: pkgs,
}, licmetas, includeDirPath) }, 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) { if errors.Is(err, derrors.NotFound) {
return createDirectory(&internal.Directory{ return createDirectory(&internal.Directory{
VersionInfo: *vi, ModuleInfo: *mi,
Path: dirPath, Path: dirPath,
Packages: nil, Packages: nil,
}, licmetas, includeDirPath) }, licmetas, includeDirPath)
} }
if err != nil { if err != nil {
@ -161,7 +161,7 @@ func createDirectory(dbDir *internal.Directory, licmetas []*licenses.Metadata, i
if !includeDirPath && pkg.Path == dbDir.Path { if !includeDirPath && pkg.Path == dbDir.Path {
continue continue
} }
newPkg, err := createPackage(pkg, &dbDir.VersionInfo, false) newPkg, err := createPackage(pkg, &dbDir.ModuleInfo, false)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -174,7 +174,7 @@ func createDirectory(dbDir *internal.Directory, licmetas []*licenses.Metadata, i
} }
packages = append(packages, newPkg) 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 }) sort.Slice(packages, func(i, j int) bool { return packages[i].Path < packages[j].Path })
return &Directory{ return &Directory{

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

@ -29,15 +29,15 @@ func TestFetchDirectoryDetails(t *testing.T) {
checkDirectory := func(got *Directory, dirPath, modulePath, version string, pkgPaths []string) { checkDirectory := func(got *Directory, dirPath, modulePath, version string, pkgPaths []string) {
t.Helper() t.Helper()
vi := sample.VersionInfo() mi := sample.ModuleInfo()
vi.ModulePath = modulePath mi.ModulePath = modulePath
vi.Version = version mi.Version = version
var wantPkgs []*Package var wantPkgs []*Package
for _, path := range pkgPaths { for _, path := range pkgPaths {
sp := sample.Package() sp := sample.Package()
sp.Path = path sp.Path = path
pkg, err := createPackage(sp, vi, false) pkg, err := createPackage(sp, mi, false)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -48,12 +48,12 @@ func TestFetchDirectoryDetails(t *testing.T) {
wantPkgs = append(wantPkgs, pkg) wantPkgs = append(wantPkgs, pkg)
} }
mod := createModule(vi, sample.LicenseMetadata, false) mod := createModule(mi, sample.LicenseMetadata, false)
want := &Directory{ want := &Directory{
Module: *mod, Module: *mod,
Path: dirPath, Path: dirPath,
Packages: wantPkgs, 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 != "" { if diff := cmp.Diff(want, got); diff != "" {
t.Errorf("fetchDirectoryDetails(ctx, %q, %q, %q) mismatch (-want +got):\n%s", dirPath, modulePath, version, 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) { t.Run(tc.name, func(t *testing.T) {
vi := sample.VersionInfo() mi := sample.ModuleInfo()
vi.ModulePath = tc.modulePath mi.ModulePath = tc.modulePath
vi.Version = tc.version mi.Version = tc.version
got, err := fetchDirectoryDetails(ctx, testDB, got, err := fetchDirectoryDetails(ctx, testDB,
tc.dirPath, vi, sample.LicenseMetadata, tc.includeDirPath) tc.dirPath, mi, sample.LicenseMetadata, tc.includeDirPath)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -201,12 +201,12 @@ func TestFetchDirectoryDetailsInvalidArguments(t *testing.T) {
}, },
} { } {
t.Run(tc.name, func(t *testing.T) { t.Run(tc.name, func(t *testing.T) {
vi := sample.VersionInfo() mi := sample.ModuleInfo()
vi.ModulePath = tc.modulePath mi.ModulePath = tc.modulePath
vi.Version = tc.version mi.Version = tc.version
got, err := fetchDirectoryDetails(ctx, testDB, 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) { if !errors.Is(err, derrors.InvalidArgument) {
t.Fatalf("expected err; got = \n%+v, %v", got, err) 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 // latestRequested indicates whether the user requested the latest
// version of the package. If so, the returned Package.URL will have the // version of the package. If so, the returned Package.URL will have the
// structure /<path> instead of /<path>@<version>. // structure /<path> instead of /<path>@<version>.
func createPackage(pkg *internal.Package, vi *internal.VersionInfo, latestRequested bool) (_ *Package, err error) { func createPackage(pkg *internal.Package, mi *internal.ModuleInfo, latestRequested bool) (_ *Package, err error) {
defer derrors.Wrap(&err, "createPackage(%v, %v)", pkg, vi) 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") 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 urlVersion := m.LinkVersion
if latestRequested { if latestRequested {
urlVersion = internal.LatestVersion urlVersion = internal.LatestVersion
@ -74,8 +74,8 @@ func createPackage(pkg *internal.Package, vi *internal.VersionInfo, latestReques
IsRedistributable: pkg.IsRedistributable, IsRedistributable: pkg.IsRedistributable,
Licenses: transformLicenseMetadata(pkg.Licenses), Licenses: transformLicenseMetadata(pkg.Licenses),
Module: *m, Module: *m,
URL: constructPackageURL(pkg.Path, vi.ModulePath, urlVersion), URL: constructPackageURL(pkg.Path, mi.ModulePath, urlVersion),
LatestURL: constructPackageURL(pkg.Path, vi.ModulePath, middleware.LatestVersionPlaceholder), LatestURL: constructPackageURL(pkg.Path, mi.ModulePath, middleware.LatestVersionPlaceholder),
}, nil }, nil
} }
@ -85,20 +85,20 @@ func createPackage(pkg *internal.Package, vi *internal.VersionInfo, latestReques
// latestRequested indicates whether the user requested the latest // latestRequested indicates whether the user requested the latest
// version of the package. If so, the returned Module.URL will have the // version of the package. If so, the returned Module.URL will have the
// structure /<path> instead of /<path>@<version>. // structure /<path> instead of /<path>@<version>.
func createModule(vi *internal.VersionInfo, licmetas []*licenses.Metadata, latestRequested bool) *Module { func createModule(mi *internal.ModuleInfo, licmetas []*licenses.Metadata, latestRequested bool) *Module {
urlVersion := linkVersion(vi.Version, vi.ModulePath) urlVersion := linkVersion(mi.Version, mi.ModulePath)
if latestRequested { if latestRequested {
urlVersion = internal.LatestVersion urlVersion = internal.LatestVersion
} }
return &Module{ return &Module{
DisplayVersion: displayVersion(vi.Version, vi.ModulePath), DisplayVersion: displayVersion(mi.Version, mi.ModulePath),
LinkVersion: linkVersion(vi.Version, vi.ModulePath), LinkVersion: linkVersion(mi.Version, mi.ModulePath),
ModulePath: vi.ModulePath, ModulePath: mi.ModulePath,
CommitTime: elapsedTime(vi.CommitTime), CommitTime: elapsedTime(mi.CommitTime),
IsRedistributable: vi.IsRedistributable, IsRedistributable: mi.IsRedistributable,
Licenses: transformLicenseMetadata(licmetas), Licenses: transformLicenseMetadata(licmetas),
URL: constructModuleURL(vi.ModulePath, urlVersion), URL: constructModuleURL(mi.ModulePath, urlVersion),
LatestURL: constructModuleURL(vi.ModulePath, middleware.LatestVersionPlaceholder), LatestURL: constructModuleURL(mi.ModulePath, middleware.LatestVersionPlaceholder),
} }
} }

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

@ -144,7 +144,7 @@ func TestCreatePackageHeader(t *testing.T) {
} { } {
t.Run(tc.label, func(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 { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

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

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

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

@ -63,7 +63,7 @@ func TestFetchImportsDetails(t *testing.T) {
version.Packages[0].Path, version.Version, got, err, tc.wantDetails) 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 != "" { 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) 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. // version.
func firstVersionedPackage(v *internal.Version) *internal.VersionedPackage { func firstVersionedPackage(v *internal.Version) *internal.VersionedPackage {
return &internal.VersionedPackage{ return &internal.VersionedPackage{
Package: *v.Packages[0], Package: *v.Packages[0],
VersionInfo: v.VersionInfo, ModuleInfo: v.ModuleInfo,
} }
} }
@ -155,7 +155,7 @@ func TestFetchImportedByDetails(t *testing.T) {
tc.pkg.Path, got, err, tc.wantDetails) 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 != "" { if diff := cmp.Diff(tc.wantDetails, got); diff != "" {
t.Errorf("fetchImportedByDetails(ctx, db, %q) mismatch (-want +got):\n%s", tc.pkg.Path, 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) { func (s *Server) latestVersion(ctx context.Context, packagePath, modulePath, pageType string) (_ string, err error) {
defer derrors.Wrap(&err, "latestVersion(ctx, %q, %q)", modulePath, packagePath) defer derrors.Wrap(&err, "latestVersion(ctx, %q, %q)", modulePath, packagePath)
var vi *internal.VersionInfo var mi *internal.ModuleInfo
switch pageType { switch pageType {
case "mod": case "mod":
vi, err = s.ds.GetVersionInfo(ctx, modulePath, internal.LatestVersion) mi, err = s.ds.GetModuleInfo(ctx, modulePath, internal.LatestVersion)
if err != nil { if err != nil {
return "", err return "", err
} }
@ -44,10 +44,10 @@ func (s *Server) latestVersion(ctx context.Context, packagePath, modulePath, pag
if err != nil { if err != nil {
return "", err return "", err
} }
vi = &pkg.VersionInfo mi = &pkg.ModuleInfo
default: default:
// For directories we don't have a well-defined latest version. // For directories we don't have a well-defined latest version.
return "", nil 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 // fetchPackageLicensesDetails fetches license data for the package version specified by
// path and version from the database and returns a LicensesDetails. // path and version from the database and returns a LicensesDetails.
func fetchPackageLicensesDetails(ctx context.Context, ds internal.DataSource, pkg *internal.VersionedPackage) (*LicensesDetails, error) { 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 { if err != nil {
return nil, err 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 // 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 // b. We have valid versions for this module path, but `version` isn't
// one of them. Serve a 404 but recommend the other versions. // 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 { if err == nil {
s.serveModulePageWithModule(ctx, w, r, vi, version) s.serveModulePageWithModule(ctx, w, r, mi, version)
return return
} }
if !errors.Is(err, derrors.NotFound) { if !errors.Is(err, derrors.NotFound) {
@ -63,7 +63,7 @@ func (s *Server) serveModulePage(w http.ResponseWriter, r *http.Request, moduleP
return return
} }
if version != internal.LatestVersion { 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) log.Errorf(ctx, "error checking for latest module: %v", err)
} else { } else {
epage := &errorPage{ epage := &errorPage{
@ -80,15 +80,15 @@ func (s *Server) serveModulePage(w http.ResponseWriter, r *http.Request, moduleP
s.servePathNotFoundErrorPage(w, r, "module") s.servePathNotFoundErrorPage(w, r, "module")
} }
func (s *Server) serveModulePageWithModule(ctx context.Context, w http.ResponseWriter, r *http.Request, vi *internal.VersionInfo, requestedVersion string) { func (s *Server) serveModulePageWithModule(ctx context.Context, w http.ResponseWriter, r *http.Request, mi *internal.ModuleInfo, requestedVersion string) {
licenses, err := s.ds.GetModuleLicenses(ctx, vi.ModulePath, vi.Version) licenses, err := s.ds.GetModuleLicenses(ctx, mi.ModulePath, mi.Version)
if err != nil { if err != nil {
log.Errorf(ctx, "error getting module licenses: %v", err) log.Errorf(ctx, "error getting module licenses: %v", err)
s.serveErrorPage(w, r, http.StatusInternalServerError, nil) s.serveErrorPage(w, r, http.StatusInternalServerError, nil)
return return
} }
modHeader := createModule(vi, licensesToMetadatas(licenses), requestedVersion == internal.LatestVersion) modHeader := createModule(mi, licensesToMetadatas(licenses), requestedVersion == internal.LatestVersion)
tab := r.FormValue("tab") tab := r.FormValue("tab")
settings, ok := moduleTabLookup[tab] settings, ok := moduleTabLookup[tab]
if !ok { if !ok {
@ -99,7 +99,7 @@ func (s *Server) serveModulePageWithModule(ctx context.Context, w http.ResponseW
var details interface{} var details interface{}
if canShowDetails { if canShowDetails {
var err error 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 { if err != nil {
log.Errorf(ctx, "error fetching page for %q: %v", tab, err) log.Errorf(ctx, "error fetching page for %q: %v", tab, err)
s.serveErrorPage(w, r, http.StatusInternalServerError, nil) s.serveErrorPage(w, r, http.StatusInternalServerError, nil)
@ -107,8 +107,8 @@ func (s *Server) serveModulePageWithModule(ctx context.Context, w http.ResponseW
} }
} }
page := &DetailsPage{ page := &DetailsPage{
basePage: newBasePage(r, moduleHTMLTitle(vi.ModulePath)), basePage: newBasePage(r, moduleHTMLTitle(mi.ModulePath)),
Title: moduleTitle(vi.ModulePath), Title: moduleTitle(mi.ModulePath),
Settings: settings, Settings: settings,
Header: modHeader, Header: modHeader,
BreadcrumbPath: breadcrumbPath(modHeader.ModulePath, modHeader.ModulePath, modHeader.LinkVersion), BreadcrumbPath: breadcrumbPath(modHeader.ModulePath, modHeader.ModulePath, modHeader.LinkVersion),

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

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

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

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

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

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

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

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

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

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

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

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

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

@ -61,11 +61,11 @@ func TestFetchModuleVersionDetails(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), testTimeout) ctx, cancel := context.WithTimeout(context.Background(), testTimeout)
defer cancel() defer cancel()
info1 := sample.VersionInfo() info1 := sample.ModuleInfo()
info1.ModulePath = modulePath1 info1.ModulePath = modulePath1
info1.Version = "v1.2.1" info1.Version = "v1.2.1"
info2 := sample.VersionInfo() info2 := sample.ModuleInfo()
info2.ModulePath = modulePath2 info2.ModulePath = modulePath2
info2.Version = "v2.2.1-alpha.1" info2.Version = "v2.2.1-alpha.1"
@ -77,7 +77,7 @@ func TestFetchModuleVersionDetails(t *testing.T) {
for _, tc := range []struct { for _, tc := range []struct {
name string name string
info *internal.VersionInfo info *internal.ModuleInfo
versions []*internal.Version versions []*internal.Version
wantDetails *VersionsDetails wantDetails *VersionsDetails
}{ }{
@ -375,11 +375,11 @@ func TestPathInVersion(t *testing.T) {
} }
for _, test := range tests { for _, test := range tests {
vi := sample.VersionInfo() mi := sample.ModuleInfo()
vi.ModulePath = test.modulePath mi.ModulePath = test.modulePath
if got := pathInVersion(test.v1Path, vi); got != test.want { if got := pathInVersion(test.v1Path, mi); got != test.want {
t.Errorf("pathInVersion(%q, VersionInfo{...ModulePath:%q}) = %s, want %v", t.Errorf("pathInVersion(%q, ModuleInfo{...ModulePath:%q}) = %s, want %v",
test.v1Path, vi.ModulePath, got, test.want) 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 // GetTaggedVersionsForPackageSeries returns a list of tagged versions sorted in
// descending semver order. This list includes tagged versions of packages that // descending semver order. This list includes tagged versions of packages that
// have the same v1path. // 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}) return getPackageVersions(ctx, db, pkgPath, []version.Type{version.TypeRelease, version.TypePrerelease})
} }
// GetPseudoVersionsForPackageSeries returns the 10 most recent from a list of // GetPseudoVersionsForPackageSeries returns the 10 most recent from a list of
// pseudo-versions sorted in descending semver order. This list includes // pseudo-versions sorted in descending semver order. This list includes
// pseudo-versions of packages that have the same v1path. // 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}) return getPackageVersions(ctx, db, pkgPath, []version.Type{version.TypePseudo})
} }
// getPackageVersions returns a list of versions sorted in descending semver // getPackageVersions returns a list of versions sorted in descending semver
// order. The version types included in the list are specified by a list of // order. The version types included in the list are specified by a list of
// VersionTypes. // 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) defer derrors.Wrap(&err, "DB.getPackageVersions(ctx, db, %q, %v)", pkgPath, versionTypes)
baseQuery := ` baseQuery := `
@ -126,13 +126,13 @@ func getPackageVersions(ctx context.Context, db *DB, pkgPath string, versionType
} }
defer rows.Close() defer rows.Close()
var versionHistory []*internal.VersionInfo var versionHistory []*internal.ModuleInfo
for rows.Next() { for rows.Next() {
var vi internal.VersionInfo var mi internal.ModuleInfo
if err := rows.Scan(&vi.ModulePath, &vi.Version, &vi.CommitTime); err != nil { if err := rows.Scan(&mi.ModulePath, &mi.Version, &mi.CommitTime); err != nil {
return nil, fmt.Errorf("row.Scan(): %v", err) return nil, fmt.Errorf("row.Scan(): %v", err)
} }
versionHistory = append(versionHistory, &vi) versionHistory = append(versionHistory, &mi)
} }
if err := rows.Err(); err != nil { 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 // GetTaggedVersionsForModule returns a list of tagged versions sorted in
// descending semver order. // 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}) return getModuleVersions(ctx, db, modulePath, []version.Type{version.TypeRelease, version.TypePrerelease})
} }
// GetPseudoVersionsForModule returns the 10 most recent from a list of // GetPseudoVersionsForModule returns the 10 most recent from a list of
// pseudo-versions sorted in descending semver order. // 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}) return getModuleVersions(ctx, db, modulePath, []version.Type{version.TypePseudo})
} }
// getModuleVersions returns a list of versions sorted in descending semver // getModuleVersions returns a list of versions sorted in descending semver
// order. The version types included in the list are specified by a list of // order. The version types included in the list are specified by a list of
// VersionTypes. // 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. // TODO(b/139530312): get information for parent modules.
defer derrors.Wrap(&err, "getModuleVersions(ctx, db, %q, %v)", modulePath, versionTypes) 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;` queryEnd = `LIMIT 10;`
} }
query := fmt.Sprintf(baseQuery, versionTypeExpr(versionTypes), queryEnd) query := fmt.Sprintf(baseQuery, versionTypeExpr(versionTypes), queryEnd)
var vinfos []*internal.VersionInfo var vinfos []*internal.ModuleInfo
collect := func(rows *sql.Rows) error { collect := func(rows *sql.Rows) error {
var vi internal.VersionInfo var mi internal.ModuleInfo
if err := rows.Scan(&vi.ModulePath, &vi.Version, &vi.CommitTime); err != nil { if err := rows.Scan(&mi.ModulePath, &mi.Version, &mi.CommitTime); err != nil {
return err return err
} }
vinfos = append(vinfos, &vi) vinfos = append(vinfos, &mi)
return nil return nil
} }
if err := db.db.RunQuery(ctx, query, collect, internal.SeriesPathForModule(modulePath)); err != 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 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). // (module_path, version).
func (db *DB) GetVersionInfo(ctx context.Context, modulePath string, version string) (_ *internal.VersionInfo, err error) { func (db *DB) GetModuleInfo(ctx context.Context, modulePath string, version string) (_ *internal.ModuleInfo, err error) {
defer derrors.Wrap(&err, "GetVersionInfo(ctx, %q, %q)", modulePath, version) defer derrors.Wrap(&err, "GetModuleInfo(ctx, %q, %q)", modulePath, version)
query := ` query := `
SELECT SELECT
@ -458,28 +458,28 @@ func (db *DB) GetVersionInfo(ctx context.Context, modulePath string, version str
} }
var ( var (
vi internal.VersionInfo mi internal.ModuleInfo
hasGoMod sql.NullBool hasGoMod sql.NullBool
) )
row := db.db.QueryRow(ctx, query, args...) row := db.db.QueryRow(ctx, query, args...)
if err := row.Scan(&vi.ModulePath, &vi.Version, &vi.CommitTime, if err := row.Scan(&mi.ModulePath, &mi.Version, &mi.CommitTime,
database.NullIsEmpty(&vi.ReadmeFilePath), database.NullIsEmpty(&vi.ReadmeContents), &vi.VersionType, database.NullIsEmpty(&mi.ReadmeFilePath), database.NullIsEmpty(&mi.ReadmeContents), &mi.VersionType,
jsonbScanner{&vi.SourceInfo}, &vi.IsRedistributable, &hasGoMod); err != nil { jsonbScanner{&mi.SourceInfo}, &mi.IsRedistributable, &hasGoMod); err != nil {
if err == sql.ErrNoRows { if err == sql.ErrNoRows {
return nil, fmt.Errorf("module version %s@%s: %w", modulePath, version, derrors.NotFound) return nil, fmt.Errorf("module version %s@%s: %w", modulePath, version, derrors.NotFound)
} }
return nil, fmt.Errorf("row.Scan(): %v", err) return nil, fmt.Errorf("row.Scan(): %v", err)
} }
setHasGoMod(&vi, hasGoMod) setHasGoMod(&mi, hasGoMod)
return &vi, nil 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. // 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. // 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 { 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 err != nil {
if tc.wantErr == nil { if tc.wantErr == nil {
t.Fatalf("got unexpected error %v", err) t.Fatalf("got unexpected error %v", err)
@ -90,7 +90,7 @@ func TestPostgres_GetVersionInfo_Latest(t *testing.T) {
if tc.wantIndex >= len(tc.versions) { if tc.wantIndex >= len(tc.versions) {
t.Fatal("wantIndex too large") 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 != "" { if diff := cmp.Diff(wantVI, gotVI, cmpopts.EquateEmpty(), cmp.AllowUnexported(source.Info{})); diff != "" {
t.Errorf("mismatch (-want +got):\n%s", diff) t.Errorf("mismatch (-want +got):\n%s", diff)
} }
@ -227,7 +227,7 @@ func TestPostgres_GetTaggedAndPseudoVersions(t *testing.T) {
name, path, modulePath string name, path, modulePath string
numPseudo int numPseudo int
versions []*internal.Version versions []*internal.Version
wantTaggedVersions []*internal.VersionInfo wantTaggedVersions []*internal.ModuleInfo
}{ }{
{ {
name: "want_releases_and_prereleases_only", name: "want_releases_and_prereleases_only",
@ -235,7 +235,7 @@ func TestPostgres_GetTaggedAndPseudoVersions(t *testing.T) {
modulePath: modulePath1, modulePath: modulePath1,
numPseudo: 12, numPseudo: 12,
versions: testVersions, versions: testVersions,
wantTaggedVersions: []*internal.VersionInfo{ wantTaggedVersions: []*internal.ModuleInfo{
{ {
ModulePath: modulePath2, ModulePath: modulePath2,
Version: "v2.1.0", Version: "v2.1.0",
@ -275,7 +275,7 @@ func TestPostgres_GetTaggedAndPseudoVersions(t *testing.T) {
t.Run(tc.name, func(t *testing.T) { t.Run(tc.name, func(t *testing.T) {
defer ResetTestDB(testDB, t) defer ResetTestDB(testDB, t)
var wantPseudoVersions []*internal.VersionInfo var wantPseudoVersions []*internal.ModuleInfo
for i := 0; i < tc.numPseudo; i++ { for i := 0; i < tc.numPseudo; i++ {
pseudo := fmt.Sprintf("v0.0.0-201806111833%02d-d8887717615a", i+1) 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, // GetPseudoVersions should only return the 10 most recent pseudo versions,
// if there are more than 10 in the database // if there are more than 10 in the database
if i < 10 { if i < 10 {
wantPseudoVersions = append(wantPseudoVersions, &internal.VersionInfo{ wantPseudoVersions = append(wantPseudoVersions, &internal.ModuleInfo{
ModulePath: modulePath1, ModulePath: modulePath1,
Version: fmt.Sprintf("v0.0.0-201806111833%02d-d8887717615a", tc.numPseudo-i), Version: fmt.Sprintf("v0.0.0-201806111833%02d-d8887717615a", tc.numPseudo-i),
CommitTime: sample.CommitTime, CommitTime: sample.CommitTime,

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

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

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

@ -263,9 +263,9 @@ func TestGetDirectory(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
vi := sample.VersionInfo() mi := sample.ModuleInfo()
vi.ModulePath = tc.wantModulePath mi.ModulePath = tc.wantModulePath
vi.Version = tc.wantVersion mi.Version = tc.wantVersion
var wantPackages []*internal.Package var wantPackages []*internal.Package
for _, path := range tc.wantPkgPaths { for _, path := range tc.wantPkgPaths {
@ -279,9 +279,9 @@ func TestGetDirectory(t *testing.T) {
}) })
wantDirectory := &internal.Directory{ wantDirectory := &internal.Directory{
VersionInfo: *vi, ModuleInfo: *mi,
Packages: wantPackages, Packages: wantPackages,
Path: tc.dirPath, Path: tc.dirPath,
} }
opts := []cmp.Option{ opts := []cmp.Option{
cmpopts.EquateEmpty(), 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) 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) { if tc.wantReadErr != (err != nil) {
t.Fatalf("error: got %v, want read error: %t", err, tc.wantReadErr) t.Fatalf("error: got %v, want read error: %t", err, tc.wantReadErr)
} }
if !tc.wantReadErr && got == nil { 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 tc.version != nil {
if diff := cmp.Diff(&tc.version.VersionInfo, got, cmp.AllowUnexported(source.Info{})); !tc.wantReadErr && diff != "" { if diff := cmp.Diff(&tc.version.ModuleInfo, 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) 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] wantPkg := tc.version.Packages[0]
if 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.VersionInfo.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{ opts := cmp.Options{
@ -206,7 +206,7 @@ func TestPostgres_ReadAndWriteVersionAndPackages(t *testing.T) {
func TestPostgres_ReadAndWriteVersionOtherColumns(t *testing.T) { func TestPostgres_ReadAndWriteVersionOtherColumns(t *testing.T) {
// Verify that InsertVersion correctly populates the columns in the versions // 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) defer ResetTestDB(testDB, t)
ctx := context.Background() ctx := context.Background()
@ -252,13 +252,13 @@ func TestPostgres_DeleteVersion(t *testing.T) {
if err := testDB.InsertVersion(ctx, v); err != nil { if err := testDB.InsertVersion(ctx, v); err != nil {
t.Fatal(err) 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) t.Fatal(err)
} }
if err := testDB.DeleteVersion(ctx, nil, v.ModulePath, v.Version); err != nil { if err := testDB.DeleteVersion(ctx, nil, v.ModulePath, v.Version); err != nil {
t.Fatal(err) 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) 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, &pkg.V1Path, pq.Array(&licenseTypes), pq.Array(&licensePaths), &pkg.Package.IsRedistributable,
database.NullIsEmpty(&pkg.DocumentationHTML), &pkg.GOOS, &pkg.GOARCH, &pkg.Version, database.NullIsEmpty(&pkg.DocumentationHTML), &pkg.GOOS, &pkg.GOARCH, &pkg.Version,
&pkg.CommitTime, database.NullIsEmpty(&pkg.ReadmeFilePath), database.NullIsEmpty(&pkg.ReadmeContents), &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) &hasGoMod)
if err != nil { if err != nil {
if err == sql.ErrNoRows { 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) return nil, fmt.Errorf("row.Scan(): %v", err)
} }
setHasGoMod(&pkg.VersionInfo, hasGoMod) setHasGoMod(&pkg.ModuleInfo, hasGoMod)
lics, err := zipLicenseMetadata(licenseTypes, licensePaths) lics, err := zipLicenseMetadata(licenseTypes, licensePaths)
if err != nil { if err != nil {
return nil, err return nil, err

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

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

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

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

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

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