Skip to content

Commit

Permalink
Refine support for GitHub /archive/refs/tags/ URLs in url2purl
Browse files Browse the repository at this point in the history
Signed-off-by: tdruez <[email protected]>
  • Loading branch information
tdruez committed Jul 25, 2024
1 parent fc0f1a0 commit 3a17b69
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ Changelog
0.16.0 (unreleased)
-------------------

- Refine support for GitHub /archive/refs/tags/ URLs in ``url2purl``.
The whole tag is now captured as the version.
This allows to properly reconstruct valid URLs in ``purl2url``.

0.15.5 (2024-07-24)
-------------------

Expand Down
8 changes: 8 additions & 0 deletions src/packageurl/contrib/url2purl.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,13 @@ def build_github_purl(url):
Return a PackageURL object from GitHub `url`.
"""

# https://github.com/apache/nifi/archive/refs/tags/rel/nifi-2.0.0-M3.tar.gz
archive_tags_pattern = (
r"https?://github.com/(?P<namespace>.+)/(?P<name>.+)"
r"/archive/refs/tags/"
r"(?P<version>.+).(zip|tar.gz|tar.bz2|.tgz)"
)

# https://github.com/nexB/scancode-toolkit/archive/v3.1.1.zip
archive_pattern = (
r"https?://github.com/(?P<namespace>.+)/(?P<name>.+)"
Expand Down Expand Up @@ -538,6 +545,7 @@ def build_github_purl(url):
git_pattern = r"https?://github.com/(?P<namespace>.+)/(?P<name>.+).(git)"

patterns = (
archive_tags_pattern,
archive_pattern,
raw_pattern,
blob_pattern,
Expand Down
1 change: 1 addition & 0 deletions tests/contrib/data/url2purl.json
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@
"https://github.com/TG1999/fetchcode/fetchcode/src": "pkg:github/tg1999/fetchcode@fetchcode#src",
"https://github.com/NEXB/SCANCODE-TOOLKIT/tree/develop/PLUGINS/scancode-ctags-macosx_10_9_intel": "pkg:github/nexb/scancode-toolkit@develop#PLUGINS/scancode-ctags-macosx_10_9_intel",
"https://github.com/NEXB/SCANCODE-TOOLKIT/tree/DEVELOP/PLUGINS/scancode-ctags-macosx_10_9_intel": "pkg:github/nexb/scancode-toolkit@DEVELOP#PLUGINS/scancode-ctags-macosx_10_9_intel",
"https://github.com/apache/nifi/archive/refs/tags/rel/nifi-2.0.0-M3.tar.gz": "pkg:github/apache/nifi@rel/nifi-2.0.0-M3",
"https://raw.githubusercontent.com/volatilityfoundation/dwarf2json/master/LICENSE.txt": "pkg:github/volatilityfoundation/dwarf2json@master#LICENSE.txt",
"https://raw.githubusercontent.com/LeZuse/flex-sdk/master/frameworks/projects/mx/src/mx/containers/accordionClasses/AccordionHeader.as": "pkg:github/lezuse/flex-sdk@master#frameworks/projects/mx/src/mx/containers/accordionClasses/AccordionHeader.as",
"https://raw.githubusercontent.com/NCIP/lexevs/master/lgSharedLibraries/jettison/jettison-1.1.jar": "pkg:github/ncip/lexevs@master#lgSharedLibraries/jettison/jettison-1.1.jar",
Expand Down
2 changes: 1 addition & 1 deletion tests/contrib/test_url2purl.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def python_safe(s):

def get_url2purl_test_method(test_url, expected_purl):
def test_method(self):
self.assertEqual(expected_purl, get_purl(test_url))
self.assertEqual(expected_purl, get_purl(test_url), msg=test_url)

return test_method

Expand Down

0 comments on commit 3a17b69

Please sign in to comment.