Skip to content

Commit fffc8ac

Browse files
committed
Add support for the golang type in purl2url.get_repo_url #107
Signed-off-by: Thomas Druez <[email protected]>
1 parent 905c89b commit fffc8ac

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

CHANGELOG.rst

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
Changelog
22
=========
33

4+
0.11.1 (unreleased)
5+
-------------------
6+
7+
- Add support for the golang type in `purl2url.get_repo_url()` #107
8+
49
0.11.0rc1 (2022-12-29)
5-
-------------------------
10+
----------------------
611

712
- Apply typing
813
- Add support for Python 3.11
@@ -11,14 +16,13 @@ Changelog
1116

1217

1318
0.10.5rc1 (2022-12-28)
14-
------------------------
19+
----------------------
1520

16-
- Fixed `PackageURL.from_string` to properly handle npm purls
17-
with namespace.
21+
- Fixed `PackageURL.from_string` to properly handle npm purls with namespace.
1822

1923

2024
0.10.4 (2022-10-17)
21-
--------------------
25+
-------------------
2226

2327
- Refactor the purl2url functions and utilities #42
2428

src/packageurl/contrib/purl2url.py

+17
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,23 @@ def build_hackage_repo_url(purl):
238238
return f"https://hackage.haskell.org/package/{name}"
239239

240240

241+
@repo_router.route("pkg:golang/.*")
242+
def build_golang_repo_url(purl):
243+
"""
244+
Return a golang repo URL from the `purl` string.
245+
"""
246+
purl_data = PackageURL.from_string(purl)
247+
248+
namespace = purl_data.namespace
249+
name = purl_data.name
250+
version = purl_data.version
251+
252+
if name and version:
253+
return f"https://pkg.go.dev/{namespace}/{name}@{version}"
254+
elif name:
255+
return f"https://pkg.go.dev/{namespace}/{name}"
256+
257+
241258
# Download URLs:
242259

243260

tests/contrib/test_purl2url.py

+5
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ def test_purl2url_get_repo_url():
5757
"pkg:nuget/[email protected]": "https://www.nuget.org/packages/System.Text.Json/6.0.6",
5858
"pkg:hackage/cli-extras": "https://hackage.haskell.org/package/cli-extras",
5959
"pkg:hackage/[email protected]": "https://hackage.haskell.org/package/cli-extras-0.2.0.0",
60+
"pkg:golang/xorm.io/xorm": "https://pkg.go.dev/xorm.io/xorm",
61+
"pkg:golang/xorm.io/[email protected]": "https://pkg.go.dev/xorm.io/[email protected]",
62+
"pkg:golang/gopkg.in/[email protected]": "https://pkg.go.dev/gopkg.in/[email protected]",
6063
}
6164

6265
for purl, url in purls_url.items():
@@ -86,6 +89,8 @@ def test_purl2url_get_download_url():
8689
"pkg:bitbucket/birkenfeld": None,
8790
"pkg:gitlab/tg1999/firebase@1a122122": None,
8891
"pkg:pypi/[email protected]": None,
92+
"pkg:golang/xorm.io/[email protected]": None,
93+
"pkg:golang/gopkg.in/[email protected]": None,
8994
}
9095

9196
for purl, url in purls_url.items():

0 commit comments

Comments
 (0)