Skip to content

Commit 673110b

Browse files
committed
Set the proper exclude for the report XLSX outputs #1524
Signed-off-by: tdruez <tdruez@nexb.com>
1 parent 2c5750d commit 673110b

File tree

4 files changed

+16
-8
lines changed

4 files changed

+16
-8
lines changed

scanpipe/management/commands/report.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ def handle(self, *args, **options):
110110
output.queryset_to_xlsx_worksheet(
111111
worksheet_queryset,
112112
workbook,
113+
exclude_fields=output.XLSX_EXCLUDE_FIELDS,
113114
prepend_fields=["project"],
114115
worksheet_name="TODOS",
115116
)

scanpipe/pipes/output.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,16 @@ def _adapt_value_for_xlsx(fieldname, value, maximum_length=32767, _adapt=True):
474474
return value, error
475475

476476

477+
XLSX_EXCLUDE_FIELDS = [
478+
"extra_data",
479+
"package_data",
480+
"license_detections",
481+
"other_license_detections",
482+
"license_clues",
483+
"affected_by_vulnerabilities",
484+
]
485+
486+
477487
def to_xlsx(project):
478488
"""
479489
Generate output for the provided ``project`` in XLSX format.
@@ -484,15 +494,8 @@ def to_xlsx(project):
484494
with possible error messages for a row when converting the data to XLSX
485495
exceed the limits of what can be stored in a cell.
486496
"""
497+
exclude_fields = XLSX_EXCLUDE_FIELDS.copy()
487498
output_file = project.get_output_file_path("results", "xlsx")
488-
exclude_fields = [
489-
"extra_data",
490-
"package_data",
491-
"license_detections",
492-
"other_license_detections",
493-
"license_clues",
494-
"affected_by_vulnerabilities",
495-
]
496499

497500
if not project.policies_enabled:
498501
exclude_fields.append("compliance_alert")

scanpipe/tests/test_commands.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,6 +1133,9 @@ def test_scanpipe_management_command_report(self):
11331133
workbook = openpyxl.load_workbook(output_file, read_only=True, data_only=True)
11341134
self.assertEqual(["TODOS"], workbook.get_sheet_names())
11351135
todos_sheet = workbook.get_sheet_by_name("TODOS")
1136+
header = list(todos_sheet.values)[0]
1137+
1138+
self.assertNotIn("extra_data", header)
11361139
row1 = list(todos_sheet.values)[1]
11371140
expected = ("project1", "file.ext", "file", "file.ext", "requires-review")
11381141
self.assertEqual(expected, row1[0:5])

scanpipe/views.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,7 @@ def export_xlsx_file_response(self):
466466
output.queryset_to_xlsx_worksheet(
467467
queryset,
468468
workbook,
469+
exclude_fields=output.XLSX_EXCLUDE_FIELDS,
469470
prepend_fields=prepend_fields,
470471
worksheet_name=worksheet_name,
471472
)

0 commit comments

Comments
 (0)