Skip to content

Commit 1e66dd0

Browse files
committed
Add url2purl support for git.kernel.org, android.googlesource.com
Signed-off-by: ziad hany <ziadhany2016@gmail.com>
1 parent a13141e commit 1e66dd0

2 files changed

Lines changed: 62 additions & 1 deletion

File tree

src/packageurl/contrib/url2purl.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,63 @@ def build_bitbucket_purl(url):
667667
)
668668

669669

670+
@purl_router.route("https?://git\.kernel\\.org/.*")
671+
def build_kernel_purl(url):
672+
"""
673+
Return a PackageURL object from Kernel `url`.
674+
For example:
675+
https://git.kernel.org/pub/scm/bluetooth/bluez.git/commit/?id=74770b1fd2be612f9c2cf807db81fcdcc35e6560
676+
"""
677+
678+
kernel_project_pattern = (
679+
r"^https?://git\.kernel\.org/pub/scm/[^/]+/"
680+
r"(?P<namespace>.+)/"
681+
r"(?P<name>[^/]+?)"
682+
r"(?:\.git)?"
683+
r"/commit/\?id="
684+
r"(?P<version>[0-9a-fA-F]{7,64})/?$"
685+
)
686+
687+
commit_matche = re.search(kernel_project_pattern, url)
688+
if commit_matche:
689+
namespace = "git.kernel.org/" + commit_matche.group("namespace")
690+
return PackageURL(
691+
type="generic",
692+
namespace=namespace,
693+
name=commit_matche.group("name"),
694+
version=commit_matche.group("version"),
695+
qualifiers={},
696+
subpath="",
697+
)
698+
699+
700+
@purl_router.route("https?://android\.googlesource\\.com/.*")
701+
def build_android_purl(url):
702+
"""
703+
Return a PackageURL object from Android `url`.
704+
For example:
705+
https://android.googlesource.com/platform/packages/apps/Settings/+/2968ccc911956fa5813a9a6a5e5c8970e383a60f
706+
"""
707+
708+
commit_pattern = (
709+
r"^https?://android\.googlesource\.com/"
710+
r"(?P<name>.+)"
711+
r"/\+/"
712+
r"(?P<version>[0-9a-fA-F]{7,64})"
713+
)
714+
715+
commit_matche = re.search(commit_pattern, url)
716+
if commit_matche:
717+
return PackageURL(
718+
type="generic",
719+
namespace="android.googlesource.com",
720+
name=commit_matche.group("name"),
721+
version=commit_matche.group("version"),
722+
qualifiers={},
723+
subpath="",
724+
)
725+
726+
670727
@purl_router.route("https?://gitlab\\.com/(?!.*/archive/).*")
671728
def build_gitlab_purl(url):
672729
"""

tests/contrib/data/url2purl.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,5 +277,9 @@
277277
"https://packagemanager.rstudio.com/cran/2022-06-23/src/contrib/curl_4.3.2.tar.gz": "pkg:cran/curl@4.3.2?download_url=https://packagemanager.rstudio.com/cran/2022-06-23/src/contrib/curl_4.3.2.tar.gz",
278278
"https://github.com/TG1999/first_repo/commit/98e516011d6e096e25247b82fc5f196bbeecff10": "pkg:github/tg1999/first_repo@98e516011d6e096e25247b82fc5f196bbeecff10",
279279
"https://gitlab.com/TG1999/first_repo/-/commit/bf04e5f289885cf2f20a92b387bcc6df33e30809": "pkg:gitlab/tg1999/first_repo@bf04e5f289885cf2f20a92b387bcc6df33e30809",
280-
"https://bitbucket.org/TG1999/first_repo/commits/16a60c4a74ef477cd8c16ca82442eaab2fbe8c86": "pkg:bitbucket/tg1999/first_repo@16a60c4a74ef477cd8c16ca82442eaab2fbe8c86"
280+
"https://git.kernel.org/pub/scm/utils/b4/b4.git/commit/?id=477734000555ffc24bf873952e40367deee26f17": "pkg:generic/git.kernel.org/b4/b4@477734000555ffc24bf873952e40367deee26f17",
281+
"https://git.kernel.org/pub/scm/docs/kernel/ksmap.git/commit/?id=e8c7bac5321ba31d63496bd7fecea3db1848e355": "pkg:generic/git.kernel.org/kernel/ksmap@e8c7bac5321ba31d63496bd7fecea3db1848e355",
282+
"https://git.kernel.org/pub/scm/virt/kvm/mst/qemu.git/commit/?id=7457fe9541b5162f285454947448d553a5d5a531": "pkg:generic/git.kernel.org/kvm/mst/qemu@7457fe9541b5162f285454947448d553a5d5a531",
283+
"https://android.googlesource.com/platform/frameworks/base/+/b4da73a935a8c906ff5df562155824d63ac849ab": "pkg:generic/android.googlesource.com/platform/frameworks/base@b4da73a935a8c906ff5df562155824d63ac849ab",
284+
"https://android.googlesource.com/device/generic/vulkan-cereal/+/240dedcb0fa917b3d2dcc4a9d4c332697c5e48a0": "pkg:generic/android.googlesource.com/device/generic/vulkan-cereal@240dedcb0fa917b3d2dcc4a9d4c332697c5e48a0"
281285
}

0 commit comments

Comments
 (0)