diff --git a/swh/web/common/service.py b/swh/web/common/service.py --- a/swh/web/common/service.py +++ b/swh/web/common/service.py @@ -13,6 +13,7 @@ from swh.model import hashutil from swh.model.identifiers import CONTENT, DIRECTORY, RELEASE, REVISION, SNAPSHOT from swh.storage.algos import diff, revisions_walker +from swh.storage.algos.origin import origin_get_latest_visit_status from swh.storage.algos.snapshot import snapshot_get_latest from swh.vault.exc import NotFoundExc as VaultNotFoundExc from swh.web import config @@ -914,10 +915,14 @@ dict: The origin_visit concerned """ - visit = storage.origin_visit_get_latest( - origin_url, require_snapshot=require_snapshot + visit_and_status = origin_get_latest_visit_status( + storage, origin_url, require_snapshot=require_snapshot ) - return converters.from_origin_visit(visit) + if not visit_and_status: + return converters.from_origin_visit({}) + visit, visit_status = visit_and_status + visit_info_dict = {**visit_status.to_dict(), "type": visit.type} + return converters.from_origin_visit(visit_info_dict) def lookup_origin_visit(origin_url: str, visit_id: int) -> OriginVisitInfo: diff --git a/swh/web/tests/api/views/test_origin.py b/swh/web/tests/api/views/test_origin.py --- a/swh/web/tests/api/views/test_origin.py +++ b/swh/web/tests/api/views/test_origin.py @@ -13,6 +13,7 @@ from swh.storage.utils import now from swh.web.api.utils import enrich_origin_visit, enrich_origin +from swh.web.common import converters from swh.web.common.exc import BadInputExc from swh.web.common.utils import reverse from swh.web.common.origin_visits import get_origin_visits @@ -343,9 +344,11 @@ archive_data.snapshot_add([new_snapshots[0]]) + # Add snapshot to the latest visit + visit_id = visit_ids[-1] visit_status = OriginVisitStatus( origin=new_origin.url, - visit=visit_ids[0], + visit=visit_id, date=now(), status="full", snapshot=new_snapshots[0].id, @@ -363,7 +366,14 @@ assert rv.status_code == 200, rv.data assert rv["Content-Type"] == "application/json" - expected_visit = archive_data.origin_visit_get_by(new_origin.url, visit_ids[0]) + expected_visit = converters.from_origin_visit( + { + **archive_data.storage.origin_visit_status_get_latest( + new_origin.url, visit_id + ).to_dict(), + "type": "git", + } + ) expected_visit = enrich_origin_visit( expected_visit,