From d8b7a728b193d3dbfc4a93763c2a4beca0ecce6d Mon Sep 17 00:00:00 2001 From: tdruez Date: Wed, 24 Jul 2024 20:19:22 +0400 Subject: [PATCH] Capture the whole git tag as the version for GutHub URL in url2purl Signed-off-by: tdruez --- CHANGELOG.rst | 5 +++++ src/packageurl/contrib/url2purl.py | 10 +++++----- tests/contrib/data/url2purl.json | 20 ++++++++++---------- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index c613709..5456a4f 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -4,6 +4,11 @@ Changelog 0.16.0 (unreleased) ------------------- +- Capture the whole git tag as the version for GutHub URL in ``url2purl`` instead of + adding a version_prefix qualifier. + Note that the version_prefix qualifier is still supported in ``purl2url`` for + backward compatibility. + 0.15.4 (2024-07-15) ------------------- diff --git a/src/packageurl/contrib/url2purl.py b/src/packageurl/contrib/url2purl.py index 5ce8aa1..aa3bd93 100644 --- a/src/packageurl/contrib/url2purl.py +++ b/src/packageurl/contrib/url2purl.py @@ -490,7 +490,7 @@ def build_github_api_purl(url): github_codeload_pattern = ( r"https?://codeload.github.com/(?P.+)/(?P.+)/" r"(zip|tar.gz|tar.bz2|tgz)/(.*/)*" - r"(?Pv|V?)(?P.+)$" + r"(?P.+)$" ) register_pattern("github", github_codeload_pattern) @@ -507,20 +507,20 @@ def build_github_purl(url): r"https?://github.com/(?P.+)/(?P.+)" r"/archive/(.*/)*" r"((?P=name)(-|_|@))?" - r"(?Pv|V?)(?P.+).(zip|tar.gz|tar.bz2|.tgz)" + r"(?P.+).(zip|tar.gz|tar.bz2|.tgz)" ) # https://github.com/downloads/mozilla/rhino/rhino1_7R4.zip download_pattern = ( r"https?://github.com/downloads/(?P.+)/(?P.+)/" r"((?P=name)(-|@)?)?" - r"(?Pv|V?)(?P.+).(zip|tar.gz|tar.bz2|.tgz)" + r"(?P.+).(zip|tar.gz|tar.bz2|.tgz)" ) # https://github.com/pypa/get-virtualenv/raw/20.0.31/public/virtualenv.pyz raw_pattern = ( r"https?://github.com/(?P.+)/(?P.+)" - r"/raw/(?Pv|V?)(?P[^/]+)/(?P.*)$" + r"/raw/(?P[^/]+)/(?P.*)$" ) # https://github.com/fanf2/unifdef/blob/master/unifdef.c @@ -531,7 +531,7 @@ def build_github_purl(url): releases_download_pattern = ( r"https?://github.com/(?P.+)/(?P.+)" - r"/releases/download/(?Pv|V?)(?P[^/]+)/.*$" + r"/releases/download/(?P[^/]+)/.*$" ) # https://github.com/pombredanne/schematics.git diff --git a/tests/contrib/data/url2purl.json b/tests/contrib/data/url2purl.json index 2157ac8..877d0c4 100644 --- a/tests/contrib/data/url2purl.json +++ b/tests/contrib/data/url2purl.json @@ -202,33 +202,33 @@ "https://api.github.com/repos/nexB/scancode-toolkit": "pkg:github/nexb/scancode-toolkit", "https://api.github.com/repos/nexB/scancode-toolkit/commits/40593af0df6c8378d2b180324b97cb439fa11d66": "pkg:github/nexb/scancode-toolkit@40593af0df6c8378d2b180324b97cb439fa11d66", "https://codeload.github.com/nexB/scancode-toolkit/tar.gz/3.1.1": "pkg:github/nexb/scancode-toolkit@3.1.1", - "https://codeload.github.com/nexB/scancode-toolkit/tar.gz/v3.1.1": "pkg:github/nexb/scancode-toolkit@3.1.1?version_prefix=v", + "https://codeload.github.com/nexB/scancode-toolkit/tar.gz/v3.1.1": "pkg:github/nexb/scancode-toolkit@v3.1.1", "https://codeload.github.com/nexB/scancode-toolkit/zip/3.1.1": "pkg:github/nexb/scancode-toolkit@3.1.1", - "https://codeload.github.com/nexB/scancode-toolkit/zip/v3.1.1": "pkg:github/nexb/scancode-toolkit@3.1.1?version_prefix=v", + "https://codeload.github.com/nexB/scancode-toolkit/zip/v3.1.1": "pkg:github/nexb/scancode-toolkit@v3.1.1", "https://codeload.github.com/nexB/scancode.io/tar.gz/1.0": "pkg:github/nexb/scancode.io@1.0", - "https://codeload.github.com/nexB/scancode.io/tar.gz/V1.0": "pkg:github/nexb/scancode.io@1.0?version_prefix=V", + "https://codeload.github.com/nexB/scancode.io/tar.gz/V1.0": "pkg:github/nexb/scancode.io@V1.0", "https://codeload.github.com/berngp/grails-rest/zip/release/0.7": "pkg:github/berngp/grails-rest@0.7", "https://codeload.github.com/eclipse/m2e-core/zip/releases/1.2/1.2.0.20120903-1050": "pkg:github/eclipse/m2e-core@1.2.0.20120903-1050", "https://github.com/nexB/scancode-toolkit/archive/3.1.1.zip": "pkg:github/nexb/scancode-toolkit@3.1.1", - "https://github.com/nexB/scancode-toolkit/archive/v3.1.1.zip": "pkg:github/nexb/scancode-toolkit@3.1.1?version_prefix=v", + "https://github.com/nexB/scancode-toolkit/archive/v3.1.1.zip": "pkg:github/nexb/scancode-toolkit@v3.1.1", "https://github.com/pypa/get-virtualenv/raw/20.0.31/public/virtualenv.pyz": "pkg:github/pypa/get-virtualenv@20.0.31#public/virtualenv.pyz", - "https://github.com/pypa/get-virtualenv/raw/v20.0.31/public/virtualenv.pyz": "pkg:github/pypa/get-virtualenv@20.0.31?version_prefix=v#public/virtualenv.pyz", + "https://github.com/pypa/get-virtualenv/raw/v20.0.31/public/virtualenv.pyz": "pkg:github/pypa/get-virtualenv@v20.0.31#public/virtualenv.pyz", "https://github.com/fanf2/unifdef/blob/master/unifdef.c": "pkg:github/fanf2/unifdef@master#unifdef.c", "https://github.com/joebeeson/amazon/blob/master/vendors/aws-sdk/sdk.class.php": "pkg:github/joebeeson/amazon@master#vendors/aws-sdk/sdk.class.php", "https://github.com/modelfabric/yowl/blob/master/bin/yowl": "pkg:github/modelfabric/yowl@master#bin/yowl", - "https://github.com/syncthing/syncthing/releases/download/v0.14.36/syncthing-source-v0.14.36.tar.gz": "pkg:github/syncthing/syncthing@0.14.36?download_url=https://github.com/syncthing/syncthing/releases/download/v0.14.36/syncthing-source-v0.14.36.tar.gz&version_prefix=v", - "https://github.com/torakiki/pdfsam/releases/download/v3.3.2/pdfsam-3.3.2-bin.zip": "pkg:github/torakiki/pdfsam@3.3.2?download_url=https://github.com/torakiki/pdfsam/releases/download/v3.3.2/pdfsam-3.3.2-bin.zip&version_prefix=v", - "https://github.com/yarnpkg/yarn/releases/download/v1.3.2/yarn-v1.3.2.tar.gz": "pkg:github/yarnpkg/yarn@1.3.2?download_url=https://github.com/yarnpkg/yarn/releases/download/v1.3.2/yarn-v1.3.2.tar.gz&version_prefix=v", + "https://github.com/syncthing/syncthing/releases/download/v0.14.36/syncthing-source-v0.14.36.tar.gz": "pkg:github/syncthing/syncthing@v0.14.36?download_url=https://github.com/syncthing/syncthing/releases/download/v0.14.36/syncthing-source-v0.14.36.tar.gz", + "https://github.com/torakiki/pdfsam/releases/download/v3.3.2/pdfsam-3.3.2-bin.zip": "pkg:github/torakiki/pdfsam@v3.3.2?download_url=https://github.com/torakiki/pdfsam/releases/download/v3.3.2/pdfsam-3.3.2-bin.zip", + "https://github.com/yarnpkg/yarn/releases/download/v1.3.2/yarn-v1.3.2.tar.gz": "pkg:github/yarnpkg/yarn@v1.3.2?download_url=https://github.com/yarnpkg/yarn/releases/download/v1.3.2/yarn-v1.3.2.tar.gz", "https://github.com/z3APA3A/3proxy/releases/download/0.8.11/3proxy-0.8.11.zip": "pkg:github/z3apa3a/3proxy@0.8.11?download_url=https://github.com/z3APA3A/3proxy/releases/download/0.8.11/3proxy-0.8.11.zip", "https://github.com/FasterXML/woodstox/archive/woodstox-core-5.0.2.zip": "pkg:github/fasterxml/woodstox@core-5.0.2", "https://github.com/adobe-fonts/source-code-pro/archive/2.030R-ro/1.050R-it.tar.gz": "pkg:github/adobe-fonts/source-code-pro@1.050R-it", "https://github.com/cassandra-rb/simple_uuid/archive/simple_uuid-0.3.0.zip": "pkg:github/cassandra-rb/simple_uuid@0.3.0", "https://github.com/djberg96/sys-filesystem/archive/sys-filesystem-1.1.4.zip": "pkg:github/djberg96/sys-filesystem@1.1.4", "https://github.com/freedesktop/xorg-intel-gpu-tools/archive/igt-gpu-tools-1.23.tar.gz": "pkg:github/freedesktop/xorg-intel-gpu-tools@igt-gpu-tools-1.23", - "https://github.com/grnet/synnefo/archive/synnefo/v0.12.3.zip": "pkg:github/grnet/synnefo@0.12.3?version_prefix=v", + "https://github.com/grnet/synnefo/archive/synnefo/v0.12.3.zip": "pkg:github/grnet/synnefo@v0.12.3", "https://github.com/n8n-io/n8n/archive/n8n@0.23.0.tar.gz": "pkg:github/n8n-io/n8n@0.23.0", "https://github.com/nginx/nginx/archive/branches/stable-0.7.zip": "pkg:github/nginx/nginx@stable-0.7", - "https://github.com/swagger-api/swagger-codegen/archive/refs/tags/v3.0.25.tar.gz": "pkg:github/swagger-api/swagger-codegen@3.0.25?version_prefix=v", + "https://github.com/swagger-api/swagger-codegen/archive/refs/tags/v3.0.25.tar.gz": "pkg:github/swagger-api/swagger-codegen@v3.0.25", "https://github.com/bareos/bareos/archive/Release/16.2.6.zip": "pkg:github/bareos/bareos@16.2.6", "https://github.com/hessu/bchunk/archive/release/1.2.2.tar.gz": "pkg:github/hessu/bchunk@1.2.2", "https://github.com/downloads/mozilla/rhino/rhino1_7R4.zip": "pkg:github/mozilla/rhino@1_7R4",