Skip to content

Commit 64fc6f0

Browse files
fix: include namespace in deduplicated purl construction (#44)
* fix: include namespace in deduplicated purl construction Fix purl deduplication logic to properly handle namespace and inputPurl fields. Previously, Maven packages were missing namespace in the returned purl field. - Use inputPurl when available and complete - Append version to incomplete inputPurl - Construct proper purl with namespace when building from scratch * Added in templates * Update .github/PULL_REQUEST_TEMPLATE/bug-fix.md Co-authored-by: Philipp Burckhardt <[email protected]> --------- Co-authored-by: Philipp Burckhardt <[email protected]>
1 parent 1a5401a commit 64fc6f0

File tree

7 files changed

+75
-3
lines changed

7 files changed

+75
-3
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Click on the "Preview" tab and select appropriate PR template:
2+
3+
[New Feature](?expand=1&template=feature.md)
4+
[Bug Fix](?expand=1&template=bug-fix.md)
5+
[Improvement](?expand=1&template=improvement.md)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!--Description: Briefly describe the bug and its impact. ⬇️ -->
2+
3+
## Root Cause
4+
<!-- Concise explanation of what caused the bug ⬇️ -->
5+
6+
7+
8+
## Fix
9+
<!-- Explain how your changes address the bug ⬇️ -->
10+
11+
## Public Changelog
12+
<!-- Write a changelog message between comment tags if this should be included in the public product changelog, Leave blank otherwise. -->
13+
14+
<!-- changelog ⬇️-->
15+
N/A
16+
<!-- /changelog ⬆️ -->
17+
18+
19+
<!-- TEMPLATE TYPE DON'T REMOVE: python-sdk-template-bug-fix -->
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!-- Description: Briefly describe the new feature you're introducing ⬇️ -->
2+
3+
4+
## Why?
5+
<!-- Explain the motivation behind this feature and its expected benefits ⬇️ -->
6+
7+
8+
9+
## Public Changelog
10+
<!-- Write a changelog message between comment tags if this should be included in the public product changelog. -->
11+
12+
<!-- changelog ⬇️-->
13+
N/A
14+
<!-- /changelog ⬆️ -->
15+
16+
<!-- TEMPLATE TYPE DON'T REMOVE: python-sdk-template-feature -->
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!-- Description: Briefly describe the code improvement you're making. This could include things like lint fixes, adding monitoring dashboards, optimizing scripts, refactoring, etc. ⬇️ -->
2+
3+
## Public Changelog
4+
<!-- Write a changelog message between comment tags if this should be included in the public product changelog. -->
5+
6+
<!-- changelog ⬇️-->
7+
N/A
8+
<!-- /changelog ⬆️ -->
9+
10+
<!-- TEMPLATE TYPE DON'T REMOVE: python-sdk-template-improvement -->

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "socketdev"
7-
version = "3.0.0"
7+
version = "3.0.2"
88
requires-python = ">= 3.9"
99
dependencies = [
1010
'requests',

socketdev/core/dedupe.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,29 @@ def alert_identity(alert: dict) -> tuple:
6161
base = package_group[0]
6262
base["releases"] = sorted(releases)
6363
base["alerts"] = list(alert_map.values())
64-
base["purl"] = f"pkg:{base.get('type', 'unknown')}/{base.get('name', 'unknown')}@{base.get('version', '0.0.0')}"
64+
65+
# Use inputPurl if available and complete, otherwise construct proper purl with namespace
66+
if "inputPurl" in base and "@" in base["inputPurl"]:
67+
# inputPurl has version, use it as-is
68+
base["purl"] = base["inputPurl"]
69+
else:
70+
# Construct purl properly with namespace and version
71+
purl_type = base.get('type', 'unknown')
72+
namespace = base.get('namespace')
73+
name = base.get('name', 'unknown')
74+
version = base.get('version', '0.0.0')
75+
76+
# Start with inputPurl if available (without version) or construct from scratch
77+
if "inputPurl" in base and not "@" in base["inputPurl"]:
78+
# inputPurl exists but lacks version, append it
79+
base["purl"] = f"{base['inputPurl']}@{version}"
80+
else:
81+
# Construct complete purl from components
82+
if namespace:
83+
base["purl"] = f"pkg:{purl_type}/{namespace}/{name}@{version}"
84+
else:
85+
base["purl"] = f"pkg:{purl_type}/{name}@{version}"
86+
6587
return base
6688

6789
@staticmethod

socketdev/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "3.0.0"
1+
__version__ = "3.0.2"

0 commit comments

Comments
 (0)