Skip to content

Commit

Permalink
Merge pull request #343 from viveksahu26/fix/shorten_elementid
Browse files Browse the repository at this point in the history
shorten name and version to avoid table breaking or destructuring
  • Loading branch information
riteshnoronha authored Nov 3, 2024
2 parents 136909b + 3160764 commit f545b10
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion pkg/compliance/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package common

import (
"path"
"strings"
"time"

Expand Down Expand Up @@ -350,7 +351,20 @@ func GetID(componentID string) string {
}

func UniqueElementID(component sbom.GetComponent) string {
return component.GetName() + "-" + component.GetVersion()
componentName := path.Base(component.GetName())

if len(componentName) > 20 {
// "org.jetbrains.kotlin:kotlin-stdlib-jdk7" would become "org.jetbrain...lib-jdk7"
componentName = componentName[:12] + "..." + componentName[len(componentName)-8:]
}

version := component.GetVersion()
if len(version) > 12 {
// "v0.0.0-20230321023759-10a507213a29" would become "v0.0.0...213a29"
version = version[:6] + "..." + version[len(version)-6:]
}

return componentName + "-" + version
}

func IsComponentPartOfPrimaryDependency(primaryCompDeps []string, comp string) bool {
Expand Down

0 comments on commit f545b10

Please sign in to comment.