Skip to content

Commit dee2720

Browse files
authored
Refine support for GitHub /archive/refs/tags/ URLs in url2purl (#161)
Signed-off-by: tdruez <tdruez@nexb.com>
1 parent fc0f1a0 commit dee2720

File tree

4 files changed

+14
-1
lines changed

4 files changed

+14
-1
lines changed

CHANGELOG.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ Changelog
44
0.16.0 (unreleased)
55
-------------------
66

7+
- Refine support for GitHub /archive/refs/tags/ URLs in ``url2purl``.
8+
The whole tag is now captured as the version.
9+
This allows to properly reconstruct valid URLs in ``purl2url``.
10+
711
0.15.5 (2024-07-24)
812
-------------------
913

src/packageurl/contrib/url2purl.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,13 @@ def build_github_purl(url):
502502
Return a PackageURL object from GitHub `url`.
503503
"""
504504

505+
# https://github.com/apache/nifi/archive/refs/tags/rel/nifi-2.0.0-M3.tar.gz
506+
archive_tags_pattern = (
507+
r"https?://github.com/(?P<namespace>.+)/(?P<name>.+)"
508+
r"/archive/refs/tags/"
509+
r"(?P<version>.+).(zip|tar.gz|tar.bz2|.tgz)"
510+
)
511+
505512
# https://github.com/nexB/scancode-toolkit/archive/v3.1.1.zip
506513
archive_pattern = (
507514
r"https?://github.com/(?P<namespace>.+)/(?P<name>.+)"
@@ -538,6 +545,7 @@ def build_github_purl(url):
538545
git_pattern = r"https?://github.com/(?P<namespace>.+)/(?P<name>.+).(git)"
539546

540547
patterns = (
548+
archive_tags_pattern,
541549
archive_pattern,
542550
raw_pattern,
543551
blob_pattern,

tests/contrib/data/url2purl.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@
193193
"https://github.com/TG1999/fetchcode/fetchcode/src": "pkg:github/tg1999/fetchcode@fetchcode#src",
194194
"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",
195195
"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",
196+
"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",
196197
"https://raw.githubusercontent.com/volatilityfoundation/dwarf2json/master/LICENSE.txt": "pkg:github/volatilityfoundation/dwarf2json@master#LICENSE.txt",
197198
"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",
198199
"https://raw.githubusercontent.com/NCIP/lexevs/master/lgSharedLibraries/jettison/jettison-1.1.jar": "pkg:github/ncip/lexevs@master#lgSharedLibraries/jettison/jettison-1.1.jar",

tests/contrib/test_url2purl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def python_safe(s):
6161

6262
def get_url2purl_test_method(test_url, expected_purl):
6363
def test_method(self):
64-
self.assertEqual(expected_purl, get_purl(test_url))
64+
self.assertEqual(expected_purl, get_purl(test_url), msg=test_url)
6565

6666
return test_method
6767

0 commit comments

Comments
 (0)