Skip to content

Commit 2110269

Browse files
committed
CM-68446: Read package health from the nested ossf detection detail
1 parent d25fea0 commit 2110269

4 files changed

Lines changed: 22 additions & 11 deletions

File tree

cycode/cli/printers/rich_printer.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
)
1717
from cycode.cli.printers.utils.detection_ordering.common_ordering import sort_and_group_detections_from_scan_result
1818
from cycode.cli.printers.utils.rich_helpers import get_columns_in_1_to_3_ratio, get_markdown_panel, get_panel
19+
from cycode.cli.printers.utils.sca_ossf import get_ossf_report_url, get_ossf_score
1920

2021
if TYPE_CHECKING:
2122
from cycode.cli.models import CliError, Detection, Document, LocalScanResult
@@ -98,13 +99,9 @@ def __add_sca_scan_related_rows(details_table: Table, detection: 'Detection') ->
9899
details_table.add_row('Dependency path', dependency_path or 'N/A')
99100

100101
if detection.detection_type_id == consts.UNMAINTAINED_PACKAGE_POLICY_ID:
101-
ossf_scorecard_score = detection_details.get('ossf_scorecard_score')
102-
details_table.add_row(
103-
'OSSF Scorecard score', 'N/A' if ossf_scorecard_score is None else str(ossf_scorecard_score)
104-
)
105-
details_table.add_row(
106-
'Source code repository', detection_details.get('source_code_repository_url') or 'N/A'
107-
)
102+
ossf_score = get_ossf_score(detection_details)
103+
details_table.add_row('OSSF Scorecard score', 'N/A' if ossf_score is None else str(ossf_score))
104+
details_table.add_row('Scorecard report', get_ossf_report_url(detection_details) or 'N/A')
108105
elif not detection.has_alert:
109106
details_table.add_row('License', detection_details.get('license'))
110107

cycode/cli/printers/tables/sca_table_printer.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from cycode.cli.printers.tables.table_printer_base import TablePrinterBase
1414
from cycode.cli.printers.utils import is_git_diff_based_scan
1515
from cycode.cli.printers.utils.detection_ordering.sca_ordering import sort_and_group_detections
16+
from cycode.cli.printers.utils.sca_ossf import get_ossf_score
1617
from cycode.cli.utils.string_utils import shortcut_dependency_paths
1718

1819
if TYPE_CHECKING:
@@ -129,8 +130,8 @@ def _enrich_table_with_values(table: Table, detection: Detection) -> None:
129130
table.add_cell(CVE_COLUMNS, detection_details.get('vulnerability_id'))
130131
table.add_cell(LICENSE_COLUMN, detection_details.get('license'))
131132

132-
ossf_scorecard_score = detection_details.get('ossf_scorecard_score')
133-
table.add_cell(OSSF_SCORE_COLUMN, 'N/A' if ossf_scorecard_score is None else str(ossf_scorecard_score))
133+
ossf_score = get_ossf_score(detection_details)
134+
table.add_cell(OSSF_SCORE_COLUMN, 'N/A' if ossf_score is None else str(ossf_score))
134135

135136
def _print_summary_issues(self, detections_count: int, title: str) -> None:
136137
self.console.print(f'[bold]Cycode found {detections_count} violations of type: [cyan]{title}[/]')
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from typing import Any, Optional
2+
3+
4+
def _get_ossf_details(detection_details: dict) -> dict:
5+
"""Package health lives in a nested "ossf" object, absent when no scorecard was resolved."""
6+
return detection_details.get('ossf') or {}
7+
8+
9+
def get_ossf_score(detection_details: dict) -> Optional[Any]:
10+
return _get_ossf_details(detection_details).get('score')
11+
12+
13+
def get_ossf_report_url(detection_details: dict) -> Optional[str]:
14+
return _get_ossf_details(detection_details).get('scorecard_report_url')

tests/cli/printers/test_sca_table_printer.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,7 @@ def test_enrich_table_with_values_populates_the_score(printer: ScaTablePrinter)
8787
ecosystem='npm',
8888
package_name='left-pad',
8989
package_version='1.0.0',
90-
ossf_scorecard_score=1.5,
91-
source_code_repository_url='https://github.com/example/left-pad',
90+
ossf={'score': 1.5, 'scorecard_report_url': 'https://scorecard.dev/viewer/?uri=github.com/example/left-pad'},
9291
)
9392

9493
ScaTablePrinter._enrich_table_with_values(table, detection)

0 commit comments

Comments
 (0)