Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BOM VDR Bugfixes #31

Merged
merged 3 commits into from
Aug 5, 2024
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
4 changes: 2 additions & 2 deletions custom_json_diff/bom_diff_template.j2
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
<th style="text-align: center; width: 46%">{{ bom_1 }}</th>
<th style="text-align: center; width: 46%">{{ bom_2 }}</th>
</tr>
{% if not (diff_apps_1 or diff_apps_2 or diff_frameworks_1 or diff_frameworks_2 or diff_lib_1 or diff_lib_2 or diff_other_1 or diff_other_2 or diff_vdrs_1 or diff_vdrs_2) %}
{% if diff_status == 0 %}
<tr>
<td colspan="3" style="text-align: center">No differences found.</td>
</tr>
Expand Down Expand Up @@ -432,7 +432,7 @@
Components
</th>
</tr>
{% if not (common_apps or common_frameworks or common_lib or common_other) %}
{% if not (common_apps or common_frameworks or common_lib or common_other or common_services or common_deps or common_vdrs) %}
<tr>
<td colspan="2" style="text-align: center">No commonalities.</td>
</tr>
Expand Down
7 changes: 4 additions & 3 deletions custom_json_diff/custom_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def compare_dicts(options: Options) -> Tuple[int, FlatDicts | BomDicts, FlatDict
return 1, json_1_data, json_2_data


def export_html_report(outfile: str, diffs: Dict, j1: BomDicts, j2: BomDicts, options: Options) -> None:
def export_html_report(outfile: str, diffs: Dict, j1: BomDicts, j2: BomDicts, options: Options, status: int) -> None:
if options.report_template:
template_file = options.report_template
else:
Expand Down Expand Up @@ -92,6 +92,7 @@ def export_html_report(outfile: str, diffs: Dict, j1: BomDicts, j2: BomDicts, op
stats=stats_summary,
comp_only=options.comp_only,
metadata=metadata_results,
diff_status=status,
)
with open(outfile, "w", encoding="utf-8") as f:
f.write(report_result)
Expand Down Expand Up @@ -146,7 +147,7 @@ def load_json(json_file: str, options: Options) -> FlatDicts | BomDicts:
logger.error("Invalid JSON: %s", json_file)
sys.exit(1)
if options.bom_diff:
data = sort_dict_lists(data, ["url", "content", "ref", "name", "value"])
data = sort_dict_lists(data, ["bom-ref", "id", "url", "content", "ref", "name", "value"])
data = filter_dict(data, options).to_dict(unflat=True)
return BomDicts(options, json_file, data, {})
return filter_dict(data, options)
Expand Down Expand Up @@ -178,7 +179,7 @@ def report_results(status: int, diffs: Dict, options: Options, j1: BomDicts | No
return
if options.bom_diff:
report_file = options.output.replace(".json", "") + ".html"
export_html_report(report_file, diffs, j1, j2, options) # type: ignore
export_html_report(report_file, diffs, j1, j2, options, status) # type: ignore


def sort_dict_lists(result: Dict, sort_keys: List[str]) -> Dict:
Expand Down
8 changes: 4 additions & 4 deletions custom_json_diff/custom_diff_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,11 +432,11 @@ def compare_bom_refs(v1: str, v2: str) -> bool:

def compare_date(dt1: str, dt2: str, comparator: str):
"""Compares two dates"""
if dt1 == dt2 or (not dt1 and not dt2):
if not dt1 and not dt2:
return True
try:
date_1 = datetime.fromisoformat(dt1)
date_2 = datetime.fromisoformat(dt2)
date_1 = datetime.fromisoformat(dt1).date()
date_2 = datetime.fromisoformat(dt2).date()
match comparator:
case "<":
return date_1 < date_2
Expand All @@ -454,7 +454,7 @@ def compare_date(dt1: str, dt2: str, comparator: str):

def compare_vdr_new_versions(vdr_1: BomVdr, vdr_2: BomVdr) -> bool:
return all((vdr_1.affects == vdr_2.affects,
compare_date(vdr_1.updated, vdr_2.updated, "<"),
(not vdr_1.updated or compare_date(vdr_1.updated, vdr_2.updated, "<=")),
compare_bom_refs(vdr_1.bom_ref, vdr_2.bom_ref)))


Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "custom-json-diff"
version = "1.5.5"
version = "1.5.6"
description = "Custom JSON and CycloneDx BOM diffing and comparison tool."
authors = [
{ name = "Caroline Russell", email = "[email protected]" },
Expand Down