Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions cycode/cli/printers/sca_table_printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from cycode.cli.consts import LICENSE_COMPLIANCE_POLICY_ID, PACKAGE_VULNERABILITY_POLICY_ID
from cycode.cli.models import DocumentDetections, Detection
from cycode.cli.printers.base_table_printer import BaseTablePrinter
from cycode.cli.utils.string_utils import shortcut_dependency_paths

SEVERITY_COLUMN = 'Severity'
LICENSE_COLUMN = 'License'
Expand Down Expand Up @@ -108,20 +109,11 @@ def set_table_width(headers: List[str], text_table: Texttable) -> None:
def _print_summary_issues(detections: List, title: str) -> None:
click.echo(f'⛔ Found {len(detections)} issues of type: {click.style(title, bold=True)}')

@staticmethod
def _shortcut_dependency_paths(dependency_paths: str) -> str:
dependencies = dependency_paths.split(' -> ')

if len(dependencies) < 3:
return dependencies[0]

return f'{dependencies[0]} -> ... -> {dependencies[-1]}'

def _get_common_detection_fields(self, detection: Detection) -> List[str]:
dependency_paths = 'N/A'
dependency_paths_raw = detection.detection_details.get('dependency_paths')
if dependency_paths_raw:
dependency_paths = self._shortcut_dependency_paths(dependency_paths_raw)
dependency_paths = shortcut_dependency_paths(dependency_paths_raw)

row = [
detection.detection_details.get('file_name'),
Expand Down
10 changes: 10 additions & 0 deletions cycode/cli/utils/string_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,13 @@ def generate_random_string(string_len: int):

def get_position_in_line(text: str, position: int) -> int:
return position - text.rfind('\n', 0, position) - 1


@staticmethod
def shortcut_dependency_paths(dependency_paths: str) -> str:
dependencies = dependency_paths.split(' -> ')

if len(dependencies) < 3:
return dependency_paths

return f'{dependencies[0]} -> ... -> {dependencies[-1]}'
17 changes: 17 additions & 0 deletions tests/utils/test_string_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from cycode.cli.utils.string_utils import shortcut_dependency_paths


def test_shortcut_dependency_paths_single_dependencies():
dependency_paths = "A"
assert shortcut_dependency_paths(dependency_paths) == dependency_paths


def test_shortcut_dependency_paths_two_dependencies():
dependency_paths = "A -> B"
assert shortcut_dependency_paths(dependency_paths) == dependency_paths


def test_shortcut_dependency_paths_three_dependencies():
dependency_paths = "A -> B -> C"
expected_result = "A -> ... -> C"
assert shortcut_dependency_paths(dependency_paths) == expected_result