From 4bd76d5066741ad357cf8fa90c1680c004dbc9c0 Mon Sep 17 00:00:00 2001 From: "John M. Horan" Date: Mon, 8 Apr 2024 15:43:15 -0700 Subject: [PATCH] Add repo URL support and testing for cocoapods #143 Reference: https://github.com/package-url/packageurl-python/issues/143 Signed-off-by: John M. Horan --- src/packageurl/contrib/purl2url.py | 14 ++++++++++++++ tests/contrib/test_purl2url.py | 7 ++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/packageurl/contrib/purl2url.py b/src/packageurl/contrib/purl2url.py index 69d3e4c..54c5e37 100644 --- a/src/packageurl/contrib/purl2url.py +++ b/src/packageurl/contrib/purl2url.py @@ -304,6 +304,20 @@ def build_golang_repo_url(purl): return f"https://pkg.go.dev/{namespace}/{name}" +@repo_router.route("pkg:cocoapods/.*") +def build_cocoapods_repo_url(purl): + """ + Return a CocoaPods repo URL from the `purl` string. + """ + purl_data = PackageURL.from_string(purl) + name = purl_data.name + + if name: + repository_homepage_url = f"https://cocoapods.org/pods/{name}" + + return repository_homepage_url + + # Download URLs: diff --git a/tests/contrib/test_purl2url.py b/tests/contrib/test_purl2url.py index c76fa52..20086f9 100644 --- a/tests/contrib/test_purl2url.py +++ b/tests/contrib/test_purl2url.py @@ -64,6 +64,8 @@ def test_purl2url_get_repo_url(): "pkg:golang/xorm.io/xorm": "https://pkg.go.dev/xorm.io/xorm", "pkg:golang/xorm.io/xorm@v0.8.2": "https://pkg.go.dev/xorm.io/xorm@v0.8.2", "pkg:golang/gopkg.in/ldap.v3@v3.1.0": "https://pkg.go.dev/gopkg.in/ldap.v3@v3.1.0", + "pkg:cocoapods/AFNetworking@4.0.1": "https://cocoapods.org/pods/AFNetworking", + "pkg:cocoapods/MapsIndoors@3.24.0": "https://cocoapods.org/pods/MapsIndoors", } for purl, url in purls_url.items(): @@ -134,7 +136,10 @@ def test_purl2url_get_inferred_urls(): "https://gitlab.com/tg1999/firebase", "https://gitlab.com/tg1999/firebase/-/archive/1a122122/firebase-1a122122.tar.gz", ], - "pkg:pypi/sortedcontainers@2.4.0": ["https://pypi.org/project/sortedcontainers/2.4.0/"], + "pkg:pypi/sortedcontainers@2.4.0": [ + "https://pypi.org/project/sortedcontainers/2.4.0/" + ], + "pkg:cocoapods/AFNetworking@4.0.1": ["https://cocoapods.org/pods/AFNetworking"], "pkg:composer/psr/log@1.1.3": ["https://packagist.org/packages/psr/log#1.1.3"], "pkg:rubygems/package-name": ["https://rubygems.org/gems/package-name"], "pkg:bitbucket/birkenfeld": [],