77# See https://aboutcode.org for more information about nexB OSS projects.
88#
99
10+ import hashlib
11+ import json
1012from collections import defaultdict
1113
1214from django .db import transaction
1618from vulnerabilities .models import AdvisoryV2
1719from vulnerabilities .models import PackageV2
1820from vulnerabilities .pipelines import VulnerableCodePipeline
19- from vulnerabilities .utils import compute_advisory_content
21+ from vulnerabilities .utils import normalize_list
2022
2123
2224class GroupAdvisoriesForPackages (VulnerableCodePipeline ):
@@ -42,15 +44,26 @@ def merge_advisories(advisories):
4244 result_groups = []
4345
4446 for adv in advisories :
45- print (adv .avid )
46- if adv .advisory_content_hash :
47- content_hash_map [adv .advisory_content_hash ].append (adv )
47+ affected = []
48+ fixed = []
49+
50+ for impact in adv .impacted_packages .all ():
51+ affected .extend ([pkg .package_url for pkg in impact .affecting_packages .all ()])
52+
53+ fixed .extend ([pkg .package_url for pkg in impact .fixed_by_packages .all ()])
54+
55+ normalized_data = {
56+ "affected_packages" : normalize_list (affected ),
57+ "fixed_packages" : normalize_list (fixed ),
58+ }
59+
60+ normalized_json = json .dumps (normalized_data , separators = ("," , ":" ), sort_keys = True )
61+ content_hash = hashlib .sha256 (normalized_json .encode ("utf-8" )).hexdigest ()
62+
63+ if content_hash :
64+ content_hash_map [content_hash ].append (adv )
4865 else :
49- content_hash = compute_advisory_content (advisory_data = adv )
50- if content_hash :
51- content_hash_map [content_hash ].append (adv )
52- else :
53- result_groups .append ([adv ])
66+ result_groups .append ([adv ])
5467
5568 final_groups = []
5669
0 commit comments