Skip to content

Commit caaaef2

Browse files
committed
updated getDependencyPathDetailsContent loop
1 parent 31c8dd3 commit caaaef2

File tree

1 file changed

+17
-22
lines changed

1 file changed

+17
-22
lines changed

utils/outputwriter/outputcontent.go

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -629,18 +629,15 @@ func getDependencyPathCellData(impactPaths [][]formats.ComponentRow, writer Outp
629629

630630
// Extract dependencies from all impact paths
631631
for _, path := range impactPaths {
632-
if len(path) < 2 {
633-
continue
634-
}
635-
// First element is always a direct dependency
636-
first := path[0]
637-
key := fmt.Sprintf("%s:%s", first.Name, first.Version)
638-
directDeps[key] = first
639-
640-
for i := 1; i < len(path)-1; i++ {
641-
component := path[i]
642-
key := fmt.Sprintf("%s:%s", component.Name, component.Version)
643-
transitiveDeps[key] = component
632+
if len(path) == 2 {
633+
direct := path[1]
634+
key := fmt.Sprintf("%s:%s", direct.Name, direct.Version)
635+
directDeps[key] = direct
636+
637+
} else if len(path) > 2 {
638+
transitive := path[len(path)-1]
639+
key := fmt.Sprintf("%s:%s", transitive.Name, transitive.Version)
640+
transitiveDeps[key] = transitive
644641
}
645642
}
646643

@@ -737,16 +734,14 @@ func getDependencyPathDetailsContent(impactPaths [][]formats.ComponentRow, fixed
737734
packages := make(map[string]packageInfo) // key: "name:version"
738735

739736
for _, path := range impactPaths {
740-
if len(path) < 2 {
741-
continue
742-
}
743-
first := path[0]
744-
key := fmt.Sprintf("%s:%s", first.Name, first.Version)
745-
packages[key] = packageInfo{component: first, isDirect: true}
746-
for i := 1; i < len(path)-1; i++ {
747-
component := path[i]
748-
key := fmt.Sprintf("%s:%s", component.Name, component.Version)
749-
packages[key] = packageInfo{component: component, isDirect: false}
737+
if len(path) == 2 {
738+
direct := path[1]
739+
key := fmt.Sprintf("%s:%s", direct.Name, direct.Version)
740+
packages[key] = packageInfo{component: direct, isDirect: true}
741+
} else if len(path) > 2 {
742+
transitive := path[len(path)-1]
743+
key := fmt.Sprintf("%s:%s", transitive.Name, transitive.Version)
744+
packages[key] = packageInfo{component: transitive, isDirect: true}
750745
}
751746
}
752747

0 commit comments

Comments
 (0)