Skip to content

Commit

Permalink
De-dupe release PURLs after reading them. (#9)
Browse files Browse the repository at this point in the history
* go 1.22 ~> 1.23 for access to maps.Keys()

* Remove dupe releases in SBOMs by accumulating them in a map of strings.
  • Loading branch information
tiegz authored Sep 3, 2024
1 parent 873ce6c commit 831a223
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/tidelift/tidelift-sbom-info

go 1.22
go 1.23

require github.com/CycloneDX/cyclonedx-go v0.9.0 // direct

Expand Down
9 changes: 8 additions & 1 deletion internal/cyclonedx/cyclonedx.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func decodeCyclonedx(filename string) (*cdx.BOM, error) {
}

func extractSupportedPurls(bom *cdx.BOM) ([]packageurl.PackageURL, error) {
var purls []packageurl.PackageURL
purlMap := map[string]packageurl.PackageURL{}

if bom.Components == nil {
log.Warn("CycloneDX file does not have any components")
Expand All @@ -70,10 +70,17 @@ func extractSupportedPurls(bom *cdx.BOM) ([]packageurl.PackageURL, error) {
continue
}

purlMap[purl.String()] = purl
}

purls := make([]packageurl.PackageURL, 0, len(purlMap))

for _, purl := range purlMap {
purls = append(purls, purl)
}

log.Debug(fmt.Sprintf("Found %d purls\n", len(purls)))

return purls, nil
}

Expand Down

0 comments on commit 831a223

Please sign in to comment.