|
13 | 13 | from collections import defaultdict |
14 | 14 |
|
15 | 15 | from git import Repo |
| 16 | +from packageurl import PackageURL |
| 17 | +from packageurl.contrib.purl2url import purl2url |
16 | 18 | from packageurl.contrib.url2purl import url2purl |
17 | 19 |
|
18 | 20 | from vulnerabilities.importer import AdvisoryData |
19 | 21 | from vulnerabilities.importer import AffectedPackageV2 |
20 | 22 | from vulnerabilities.importer import PackageCommitPatchData |
| 23 | +from vulnerabilities.importer import ReferenceV2 |
| 24 | +from vulnerabilities.models import AdvisoryReference |
21 | 25 | from vulnerabilities.pipelines import VulnerableCodeBaseImporterPipelineV2 |
22 | 26 |
|
23 | 27 |
|
@@ -105,20 +109,37 @@ def collect_advisories(self): |
105 | 109 | summary += f"{commit_hash}:{commit_message}\n" |
106 | 110 | commit_hash_set.add(commit_hash) |
107 | 111 |
|
108 | | - affected_packages = [ |
109 | | - AffectedPackageV2( |
| 112 | + affected_packages = [] |
| 113 | + references = [] |
| 114 | + for commit_hash in commit_hash_set: |
| 115 | + affected_package = AffectedPackageV2( |
110 | 116 | package=purl, |
111 | 117 | fixed_by_commit_patches=[ |
112 | 118 | PackageCommitPatchData(vcs_url=self.repo_url, commit_hash=commit_hash) |
113 | | - for commit_hash in commit_hash_set |
114 | 119 | ], |
115 | 120 | ) |
116 | | - ] |
| 121 | + affected_packages.append(affected_package) |
| 122 | + |
| 123 | + purl_with_commit_hash = PackageURL( |
| 124 | + type=purl.type, namespace=purl.namespace, name=purl.name, version=commit_hash |
| 125 | + ) |
| 126 | + ref_url = purl2url(purl=str(purl_with_commit_hash)) |
| 127 | + if not ref_url: |
| 128 | + continue |
| 129 | + |
| 130 | + references.append( |
| 131 | + ReferenceV2( |
| 132 | + reference_id=commit_hash, |
| 133 | + reference_type=AdvisoryReference.COMMIT, |
| 134 | + url=ref_url, |
| 135 | + ) |
| 136 | + ) |
117 | 137 |
|
118 | 138 | yield AdvisoryData( |
119 | 139 | advisory_id=vuln_id, |
120 | 140 | summary=summary, |
121 | 141 | affected_packages=affected_packages, |
| 142 | + references_v2=references, |
122 | 143 | url=self.repo_url, |
123 | 144 | ) |
124 | 145 |
|
|
0 commit comments