Skip to content

Commit 75111b3

Browse files
Preserve single tag prefixes and correct OpenSSL version fixtures
Signed-off-by: Ali Zulfiqar <codewithfourtix@gmail.com>
1 parent 7f15856 commit 75111b3

3 files changed

Lines changed: 35 additions & 8 deletions

File tree

src/fetchcode/package_util.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,11 @@ def _get_github_packages(purl, version_regex, ignored_tag_regex, default_package
119119
else:
120120
version = tag
121121

122-
version = version.strip().lstrip("Vv")
122+
version = version.strip()
123+
if version.startswith(("v", "V")):
124+
version = version[1:]
123125
if "+" in version:
124-
first, last = version.split("+")
126+
first, last = version.split("+", 1)
125127
first = first.replace("_", ".")
126128
version = f"{first}+{last}"
127129
else:

tests/data/package/github/openssl-expected.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3099,7 +3099,7 @@
30993099
"type": "openssl",
31003100
"namespace": null,
31013101
"name": "openssl",
3102-
"version": "0.9.8",
3102+
"version": "0.9.8v",
31033103
"qualifiers": {},
31043104
"subpath": null,
31053105
"primary_language": "C",
@@ -3126,7 +3126,7 @@
31263126
"dependencies": [],
31273127
"contains_source_code": null,
31283128
"source_packages": [],
3129-
"purl": "pkg:openssl/openssl@0.9.8",
3129+
"purl": "pkg:openssl/openssl@0.9.8v",
31303130
"repository_homepage_url": null,
31313131
"repository_download_url": null,
31323132
"api_data_url": null
@@ -8499,7 +8499,7 @@
84998499
"type": "openssl",
85008500
"namespace": null,
85018501
"name": "openssl",
8502-
"version": "1.1.1",
8502+
"version": "1.1.1v",
85038503
"qualifiers": {},
85048504
"subpath": null,
85058505
"primary_language": "C",
@@ -8526,7 +8526,7 @@
85268526
"dependencies": [],
85278527
"contains_source_code": null,
85288528
"source_packages": [],
8529-
"purl": "pkg:openssl/openssl@1.1.1",
8529+
"purl": "pkg:openssl/openssl@1.1.1v",
85308530
"repository_homepage_url": null,
85318531
"repository_download_url": null,
85328532
"api_data_url": null
@@ -10295,4 +10295,4 @@
1029510295
"repository_download_url": null,
1029610296
"api_data_url": null
1029710297
}
10298-
]
10298+
]

tests/test_github_tag_versions.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
# fetchcode is a free software tool from nexB Inc. and others.
2+
# Visit https://github.com/aboutcode-org/fetchcode for support and download.
3+
4+
# Copyright (c) nexB Inc. and others. All rights reserved.
5+
# http://nexb.com and http://aboutcode.org
6+
7+
# This software is licensed under the Apache License version 2.0.
8+
9+
# You may not use this software except in compliance with the License.
10+
# You may obtain a copy of the License at:
11+
# http://apache.org/licenses/LICENSE-2.0
12+
# Unless required by applicable law or agreed to in writing, software distributed
13+
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
14+
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations under the License.
16+
117
import datetime
218

319
import pytest
@@ -8,7 +24,13 @@
824

925

1026
@pytest.mark.parametrize(
11-
"tag,expected", [("v1.2-dev", "1.2-dev"), ("v1_2_3+build_4", "1.2.3+build_4")]
27+
"tag,expected",
28+
[
29+
("v1.2-dev", "1.2-dev"),
30+
("v1_2_3+build_4", "1.2.3+build_4"),
31+
("v1_2+build+extra", "1.2+build+extra"),
32+
("vv1.2", None),
33+
],
1234
)
1335
def test_github_tag_version_normalization(monkeypatch, tag, expected):
1436
monkeypatch.setattr(
@@ -18,5 +40,8 @@ def test_github_tag_version_normalization(monkeypatch, tag, expected):
1840
)
1941
purl = PackageURL("github", "example", "project")
2042
packages = list(package_util.get_github_packages(purl, None, None, Package(**purl.to_dict())))
43+
if expected is None:
44+
assert packages == []
45+
return
2146
assert packages[0].version == expected
2247
assert packages[0].download_url.endswith(f"/{tag}.tar.gz")

0 commit comments

Comments
 (0)