Skip to content

Commit 81933a5

Browse files
committed
Add commit url for these commits in reference
Signed-off-by: ziad hany <ziadhany2016@gmail.com>
1 parent acfaed2 commit 81933a5

File tree

2 files changed

+39
-6
lines changed

2 files changed

+39
-6
lines changed

vulnerabilities/pipes/vcs_collector_utils.py

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,15 @@
1313
from collections import defaultdict
1414

1515
from git import Repo
16+
from packageurl import PackageURL
17+
from packageurl.contrib.purl2url import purl2url
1618
from packageurl.contrib.url2purl import url2purl
1719

1820
from vulnerabilities.importer import AdvisoryData
1921
from vulnerabilities.importer import AffectedPackageV2
2022
from vulnerabilities.importer import PackageCommitPatchData
23+
from vulnerabilities.importer import ReferenceV2
24+
from vulnerabilities.models import AdvisoryReference
2125
from vulnerabilities.pipelines import VulnerableCodeBaseImporterPipelineV2
2226

2327

@@ -105,20 +109,37 @@ def collect_advisories(self):
105109
summary += f"{commit_hash}:{commit_message}\n"
106110
commit_hash_set.add(commit_hash)
107111

108-
affected_packages = [
109-
AffectedPackageV2(
112+
affected_packages = []
113+
references = []
114+
for commit_hash in commit_hash_set:
115+
affected_package = AffectedPackageV2(
110116
package=purl,
111117
fixed_by_commit_patches=[
112118
PackageCommitPatchData(vcs_url=self.repo_url, commit_hash=commit_hash)
113-
for commit_hash in commit_hash_set
114119
],
115120
)
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+
)
117137

118138
yield AdvisoryData(
119139
advisory_id=vuln_id,
120140
summary=summary,
121141
affected_packages=affected_packages,
142+
references_v2=references,
122143
url=self.repo_url,
123144
)
124145

vulnerabilities/tests/test_data/fix_commits/expected_linux_advisory_output.json

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,13 @@
2626
]
2727
}
2828
],
29-
"references_v2": [],
29+
"references_v2": [
30+
{
31+
"reference_id": "41b43c74bda19753c757036673ea9db74acf494a",
32+
"reference_type": "commit",
33+
"url": "https://github.com/test/repo/tree/41b43c74bda19753c757036673ea9db74acf494a"
34+
}
35+
],
3036
"patches": [],
3137
"severities": [],
3238
"date_published": null,
@@ -60,7 +66,13 @@
6066
]
6167
}
6268
],
63-
"references_v2": [],
69+
"references_v2": [
70+
{
71+
"reference_id": "49ff1042aa66bb25eda87e9a8ef82f3b0ad4eeba",
72+
"reference_type": "commit",
73+
"url": "https://github.com/test/repo/tree/49ff1042aa66bb25eda87e9a8ef82f3b0ad4eeba"
74+
}
75+
],
6476
"patches": [],
6577
"severities": [],
6678
"date_published": null,

0 commit comments

Comments
 (0)