Skip to content

Commit

Permalink
Include project errors in XLSX results output #364
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Druez <[email protected]>
  • Loading branch information
tdruez committed Dec 15, 2021
1 parent c120201 commit 4b8ba48
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Changelog
Unreleased
----------

- Include project errors in XLSX results output.
https://github.com/nexB/scancode.io/issues/364

- Refactor the update_or_create_package pipe to support the ProjectError system
and fix a database transaction error.
https://github.com/nexB/scancode.io/issues/381
Expand Down
5 changes: 3 additions & 2 deletions scanpipe/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ class ProjectErrorSerializer(serializers.ModelSerializer):

class Meta:
model = ProjectError
fields = ["uuid", "model", "details", "message", "traceback", "created_date"]
fields = ["uuid", "model", "message", "details", "traceback", "created_date"]

def get_traceback(self, project_error):
return project_error.traceback.split("\n")
Expand Down Expand Up @@ -261,8 +261,9 @@ def get_model_serializer(model_class):
Returns a Serializer class that ia related to a given `model_class`.
"""
serializer = {
DiscoveredPackage: DiscoveredPackageSerializer,
CodebaseResource: CodebaseResourceSerializer,
DiscoveredPackage: DiscoveredPackageSerializer,
ProjectError: ProjectErrorSerializer,
}.get(model_class, None)

if not serializer:
Expand Down
1 change: 1 addition & 0 deletions scanpipe/pipes/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ def to_xlsx(project):
querysets = [
project.discoveredpackages.all(),
project.codebaseresources.without_symlinks(),
project.projecterrors.all(),
]

with xlsxwriter.Workbook(output_file) as workbook:
Expand Down
4 changes: 4 additions & 0 deletions scanpipe/tests/test_pipes.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
from scanpipe.models import CodebaseResource
from scanpipe.models import DiscoveredPackage
from scanpipe.models import Project
from scanpipe.models import ProjectError
from scanpipe.pipes import codebase
from scanpipe.pipes import fetch
from scanpipe.pipes import filename_now
Expand Down Expand Up @@ -221,6 +222,9 @@ def test_scanpipe_pipes_outputs_to_xlsx(self):
path="filename.ext",
)
codebase_resource.create_and_add_package(package_data1)
ProjectError.objects.create(
project=project1, model="Model", details={}, message="Error"
)

output_file = output.to_xlsx(project=project1)
self.assertEqual([output_file.name], project1.output_root)
Expand Down

0 comments on commit 4b8ba48

Please sign in to comment.