mirror of
https://github.com/lukaszraczylo/gohoarder.git
synced 2026-11-25 06:35:21 +00:00
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.
This commit is contained in:
+20
-11
@@ -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 {
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user