diff --git a/swh/web/browse/snapshot_context.py b/swh/web/browse/snapshot_context.py --- a/swh/web/browse/snapshot_context.py +++ b/swh/web/browse/snapshot_context.py @@ -106,17 +106,25 @@ return filtered_releases[0] else: # case where a large branches list has been truncated - for branch_name in (release_name, f"refs/tags/{release_name}"): + try: + # git origins have specific branches for releases + snp = service.lookup_snapshot( + snapshot_id, + branches_from=f"refs/tags/{release_name}", + branches_count=1, + target_types=["release"], + ) + except NotFoundExc: snp = service.lookup_snapshot( snapshot_id, - branches_from=branch_name, + branches_from=release_name, branches_count=1, target_types=["release"], ) - _, snp_release = process_snapshot_branches(snp) - if snp_release and snp_release[0]["name"] == release_name: - releases.append(snp_release[0]) - return snp_release[0] + _, snp_release = process_snapshot_branches(snp) + if snp_release and snp_release[0]["name"] == release_name: + releases.append(snp_release[0]) + return snp_release[0] def _branch_not_found( diff --git a/swh/web/tests/browse/test_snapshot_context.py b/swh/web/tests/browse/test_snapshot_context.py --- a/swh/web/tests/browse/test_snapshot_context.py +++ b/swh/web/tests/browse/test_snapshot_context.py @@ -11,6 +11,7 @@ get_origin_visit_snapshot, get_snapshot_content, get_snapshot_context, + _get_release, ) from swh.web.common.identifiers import get_swh_persistent_id from swh.web.common.origin_visits import get_origin_visit, get_origin_visits @@ -20,7 +21,11 @@ SnapshotContext, ) from swh.web.common.utils import format_utc_iso_date, reverse -from swh.web.tests.strategies import origin_with_multiple_visits, snapshot +from swh.web.tests.strategies import ( + origin_with_multiple_visits, + snapshot, + origin_with_releases, +) @given(origin_with_multiple_visits()) @@ -327,3 +332,24 @@ expected_revision["query_params"] = {"revision": revision["id"], **query_params} assert snapshot_context == expected_revision + + +@given(origin_with_releases()) +def test_get_release_large_snapshot(archive_data, origin): + snapshot = archive_data.snapshot_get_latest(origin["url"]) + release_id = random.choice( + [ + v["target"] + for v in snapshot["branches"].values() + if v["target_type"] == "release" + ] + ) + release_data = archive_data.release_get(release_id) + # simulate large snapshot processing by providing releases parameter + # as an empty list + release = _get_release( + releases=[], release_name=release_data["name"], snapshot_id=snapshot["id"] + ) + + assert release_data["name"] == release["name"] + assert release_data["id"] == release["id"]