From 947b264d94ec532d7fa04b03a411c631f6916037 Mon Sep 17 00:00:00 2001 From: Lukasz Raczylo Date: Mon, 23 Nov 2026 02:47:34 +0000 Subject: [PATCH] fix(pypi): send the release version in the scanned package list The package list builds its own payload when scanning is on, and that payload left out release_version, so the dashboard still showed file names. A helper now builds the summary and a test covers it. --- pkg/app/handlers.go | 31 ++++++++++++++++++++----------- pkg/app/package_summary_test.go | 20 ++++++++++++++++++++ 2 files changed, 40 insertions(+), 11 deletions(-) create mode 100644 pkg/app/package_summary_test.go diff --git a/pkg/app/handlers.go b/pkg/app/handlers.go index 3918cbb..15d3695 100644 --- a/pkg/app/handlers.go +++ b/pkg/app/handlers.go @@ -37,6 +37,25 @@ func (a *App) handlePackages(c fiber.Ctx) error { } } +// packageSummary is the list payload for one package when scan results are attached. +func packageSummary(pkg *metadata.Package) map[string]interface{} { + summary := map[string]interface{}{ + "id": pkg.ID, + "registry": pkg.Registry, + "name": pkg.Name, + "version": pkg.Version, + "size": pkg.Size, + "checksum_sha256": pkg.ChecksumSHA256, + "cached_at": pkg.CachedAt, + "last_accessed": pkg.LastAccessed, + "download_count": pkg.DownloadCount, + } + if pkg.ReleaseVersion != "" { + summary["release_version"] = pkg.ReleaseVersion + } + return summary +} + // handleListPackages returns list of cached packages func (a *App) handleListPackages(c fiber.Ctx) error { ctx := c.Context() @@ -119,17 +138,7 @@ func (a *App) handleListPackages(c fiber.Ctx) error { enhancedPackages := make([]map[string]interface{}, 0, len(packagesWithNames)) for _, entry := range packagesWithNames { pkg := entry.pkg - pkgMap := map[string]interface{}{ - "id": pkg.ID, - "registry": pkg.Registry, - "name": pkg.Name, - "version": pkg.Version, - "size": pkg.Size, - "checksum_sha256": pkg.ChecksumSHA256, - "cached_at": pkg.CachedAt, - "last_accessed": pkg.LastAccessed, - "download_count": pkg.DownloadCount, - } + pkgMap := packageSummary(pkg) // Add vulnerability info if scanned if pkg.SecurityScanned { diff --git a/pkg/app/package_summary_test.go b/pkg/app/package_summary_test.go new file mode 100644 index 0000000..83e521b --- /dev/null +++ b/pkg/app/package_summary_test.go @@ -0,0 +1,20 @@ +package app + +import ( + "testing" + + "github.com/lukaszraczylo/gohoarder/pkg/metadata" +) + +func TestPackageSummaryCarriesReleaseVersion(t *testing.T) { + withRelease := packageSummary(&metadata.Package{Name: "six", Version: "six-1.17.0.tar.gz", ReleaseVersion: "1.17.0"}) + if got := withRelease["release_version"]; got != "1.17.0" { + t.Errorf("release_version = %v, want 1.17.0", got) + } + if got := withRelease["version"]; got != "six-1.17.0.tar.gz" { + t.Errorf("version = %v, want the cache key", got) + } + if _, ok := packageSummary(&metadata.Package{Name: "left-pad", Version: "1.3.0"})["release_version"]; ok { + t.Error("a row without a release version must not send the field") + } +}