Skip to content

Commit 0f7c71c

Browse files
Fetch NuGet registration pages when versions are not inlined
Signed-off-by: Ali Zulfiqar <codewithfourtix@gmail.com>
1 parent 27c4fc9 commit 0f7c71c

2 files changed

Lines changed: 42 additions & 0 deletions

File tree

src/fetchcode/package_versions.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,8 @@ def cleaned_version(version):
456456

457457
def nuget_extract_versions(response: dict) -> Iterable[PackageVersion]:
458458
for entry_group in response.get("items") or []:
459+
if "items" not in entry_group and entry_group.get("@id"):
460+
entry_group = get_response(url=entry_group["@id"]) or {}
459461
for entry in entry_group.get("items") or []:
460462
catalog_entry = entry.get("catalogEntry") or {}
461463
version = catalog_entry.get("version")
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
17+
from fetchcode import package_versions
18+
19+
20+
def test_nuget_fetches_external_registration_pages(monkeypatch):
21+
calls = []
22+
23+
def response(url):
24+
calls.append(url)
25+
return {
26+
"items": [{"catalogEntry": {"version": "2.0", "published": "2024-01-01T00:00:00Z"}}]
27+
}
28+
29+
monkeypatch.setattr(package_versions, "get_response", response)
30+
index = {
31+
"items": [
32+
{"@id": "https://example.org/inline", "items": [{"catalogEntry": {"version": "1.0"}}]},
33+
{"@id": "https://example.org/page2"},
34+
{"@id": "https://example.org/empty", "items": []},
35+
]
36+
}
37+
versions = list(package_versions.nuget_extract_versions(index))
38+
assert [version.value for version in versions] == ["1.0", "2.0"]
39+
assert calls == ["https://example.org/page2"]
40+
assert versions[1].release_date.isoformat() == "2024-01-01T00:00:00+00:00"

0 commit comments

Comments
 (0)