Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ dependencies = [
"pyshacl[js]>=0.30.0",
"rdflib>=7.1.1",
"toml>=0.10.2",
"jinja2>=3.1.6",
]
requires-python = ">=3.10"
authors = [
Expand Down
20 changes: 14 additions & 6 deletions src/software_card_policies/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileContributor: David Pape

from jinja2 import Environment, PackageLoader, select_autoescape
from rdflib import Graph
from rdflib.namespace import RDF, SH

Expand All @@ -12,8 +11,17 @@
def create_report(validation_graph: Graph, debug=False) -> str:
shacl_report, *_ = validation_graph.subjects(RDF.type, SH.ValidationReport)
validation_report = ValidationReport.from_graph(shacl_report, validation_graph)
environment = Environment(
loader=PackageLoader("software_card_policies"), autoescape=select_autoescape()
)
template = environment.get_template("report.j2")
return template.render(validation_report=validation_report, debug=debug)

if validation_report.conforms:
return "Validation succeeded!"

text = "Validation failed!\n"
for validation_result in validation_report.results:
text += "\n"
text += f"{validation_result.severity}:\n"
text += f"Breached policy: {validation_result.source_policy.name}\n"
text += f"{validation_result.source_policy.description}\n"
if debug:
text += f"Debug: {validation_result.message}\n"

return text
17 changes: 0 additions & 17 deletions src/software_card_policies/templates/report.j2

This file was deleted.

Loading