Skip to content

Commit 5d9eb58

Browse files
committed
Update generate_patch_url function to use purl2url.get_patch_url function
Signed-off-by: ziad hany <ziadhany2016@gmail.com>
1 parent 8723c4a commit 5d9eb58

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

vulnerabilities/pipelines/v2_improvers/fetch_patch_url.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ class FetchPatchURLImproverPipeline(VulnerableCodePipeline):
1818
"""FetchPatchURL Improver Pipeline"""
1919

2020
pipeline_id = "fetch_patch_url"
21-
precedence = 200
2221

2322
@classmethod
2423
def steps(cls):

vulnerabilities/utils.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@
3434
from cwe2.database import Database
3535
from cwe2.database import InvalidCWEError
3636
from packageurl import PackageURL
37+
from packageurl.contrib import purl2url
3738
from packageurl.contrib.django.utils import without_empty_values
39+
from packageurl.contrib.url2purl import url2purl
3840
from univers.version_range import RANGE_CLASS_BY_SCHEMES
3941
from univers.version_range import AlpineLinuxVersionRange
4042
from univers.version_range import NginxVersionRange
@@ -873,17 +875,16 @@ def generate_patch_url(vcs_url, commit_hash):
873875
"""
874876
Generate patch URL from VCS URL and commit hash.
875877
"""
878+
876879
if not vcs_url or not commit_hash:
877-
return None
880+
return
881+
882+
purl = url2purl(vcs_url)
883+
if not purl:
884+
return
885+
886+
new_purl = PackageURL(
887+
type=purl.type, namespace=purl.namespace, name=purl.name, version=commit_hash
888+
)
878889

879-
vcs_url = vcs_url.rstrip("/")
880-
881-
if vcs_url.startswith("https://github.com"):
882-
return f"{vcs_url}/commit/{commit_hash}.patch"
883-
elif vcs_url.startswith("https://gitlab.com"):
884-
return f"{vcs_url}/-/commit/{commit_hash}.patch"
885-
elif vcs_url.startswith("https://bitbucket.org"):
886-
return f"{vcs_url}/-/commit/{commit_hash}/raw"
887-
elif vcs_url.startswith("https://git.kernel.org"):
888-
return f"{vcs_url}.git/patch/?id={commit_hash}"
889-
return
890+
return purl2url.get_patch_url(str(new_purl))

0 commit comments

Comments
 (0)