Skip to content

Commit

Permalink
Set the proper exclude for the report XLSX outputs #1524
Browse files Browse the repository at this point in the history
Signed-off-by: tdruez <[email protected]>
  • Loading branch information
tdruez committed Jan 17, 2025
1 parent 2c5750d commit 673110b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
1 change: 1 addition & 0 deletions scanpipe/management/commands/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ def handle(self, *args, **options):
output.queryset_to_xlsx_worksheet(
worksheet_queryset,
workbook,
exclude_fields=output.XLSX_EXCLUDE_FIELDS,
prepend_fields=["project"],
worksheet_name="TODOS",
)
Expand Down
19 changes: 11 additions & 8 deletions scanpipe/pipes/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,16 @@ def _adapt_value_for_xlsx(fieldname, value, maximum_length=32767, _adapt=True):
return value, error


XLSX_EXCLUDE_FIELDS = [
"extra_data",
"package_data",
"license_detections",
"other_license_detections",
"license_clues",
"affected_by_vulnerabilities",
]


def to_xlsx(project):
"""
Generate output for the provided ``project`` in XLSX format.
Expand All @@ -484,15 +494,8 @@ def to_xlsx(project):
with possible error messages for a row when converting the data to XLSX
exceed the limits of what can be stored in a cell.
"""
exclude_fields = XLSX_EXCLUDE_FIELDS.copy()
output_file = project.get_output_file_path("results", "xlsx")
exclude_fields = [
"extra_data",
"package_data",
"license_detections",
"other_license_detections",
"license_clues",
"affected_by_vulnerabilities",
]

if not project.policies_enabled:
exclude_fields.append("compliance_alert")
Expand Down
3 changes: 3 additions & 0 deletions scanpipe/tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -1133,6 +1133,9 @@ def test_scanpipe_management_command_report(self):
workbook = openpyxl.load_workbook(output_file, read_only=True, data_only=True)
self.assertEqual(["TODOS"], workbook.get_sheet_names())
todos_sheet = workbook.get_sheet_by_name("TODOS")
header = list(todos_sheet.values)[0]

self.assertNotIn("extra_data", header)
row1 = list(todos_sheet.values)[1]
expected = ("project1", "file.ext", "file", "file.ext", "requires-review")
self.assertEqual(expected, row1[0:5])
Expand Down
1 change: 1 addition & 0 deletions scanpipe/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,7 @@ def export_xlsx_file_response(self):
output.queryset_to_xlsx_worksheet(
queryset,
workbook,
exclude_fields=output.XLSX_EXCLUDE_FIELDS,
prepend_fields=prepend_fields,
worksheet_name=worksheet_name,
)
Expand Down

0 comments on commit 673110b

Please sign in to comment.