Skip to content

Commit

Permalink
Add support for the golang type in purl2url.get_repo_url #107
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Druez <[email protected]>
  • Loading branch information
tdruez committed Mar 24, 2023
1 parent 905c89b commit fffc8ac
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
14 changes: 9 additions & 5 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
Changelog
=========

0.11.1 (unreleased)
-------------------

- Add support for the golang type in `purl2url.get_repo_url()` #107

0.11.0rc1 (2022-12-29)
-------------------------
----------------------

- Apply typing
- Add support for Python 3.11
Expand All @@ -11,14 +16,13 @@ Changelog


0.10.5rc1 (2022-12-28)
------------------------
----------------------

- Fixed `PackageURL.from_string` to properly handle npm purls
with namespace.
- Fixed `PackageURL.from_string` to properly handle npm purls with namespace.


0.10.4 (2022-10-17)
--------------------
-------------------

- Refactor the purl2url functions and utilities #42

Expand Down
17 changes: 17 additions & 0 deletions src/packageurl/contrib/purl2url.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,23 @@ def build_hackage_repo_url(purl):
return f"https://hackage.haskell.org/package/{name}"


@repo_router.route("pkg:golang/.*")
def build_golang_repo_url(purl):
"""
Return a golang repo URL from the `purl` string.
"""
purl_data = PackageURL.from_string(purl)

namespace = purl_data.namespace
name = purl_data.name
version = purl_data.version

if name and version:
return f"https://pkg.go.dev/{namespace}/{name}@{version}"
elif name:
return f"https://pkg.go.dev/{namespace}/{name}"


# Download URLs:


Expand Down
5 changes: 5 additions & 0 deletions tests/contrib/test_purl2url.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ def test_purl2url_get_repo_url():
"pkg:nuget/[email protected]": "https://www.nuget.org/packages/System.Text.Json/6.0.6",
"pkg:hackage/cli-extras": "https://hackage.haskell.org/package/cli-extras",
"pkg:hackage/[email protected]": "https://hackage.haskell.org/package/cli-extras-0.2.0.0",
"pkg:golang/xorm.io/xorm": "https://pkg.go.dev/xorm.io/xorm",
"pkg:golang/xorm.io/[email protected]": "https://pkg.go.dev/xorm.io/[email protected]",
"pkg:golang/gopkg.in/[email protected]": "https://pkg.go.dev/gopkg.in/[email protected]",
}

for purl, url in purls_url.items():
Expand Down Expand Up @@ -86,6 +89,8 @@ def test_purl2url_get_download_url():
"pkg:bitbucket/birkenfeld": None,
"pkg:gitlab/tg1999/firebase@1a122122": None,
"pkg:pypi/[email protected]": None,
"pkg:golang/xorm.io/[email protected]": None,
"pkg:golang/gopkg.in/[email protected]": None,
}

for purl, url in purls_url.items():
Expand Down

0 comments on commit fffc8ac

Please sign in to comment.