diff --git a/swh/web/common/archive.py b/swh/web/common/archive.py --- a/swh/web/common/archive.py +++ b/swh/web/common/archive.py @@ -295,6 +295,21 @@ ) +def lookup_origin_snapshots(origin: OriginInfo) -> List[str]: + """Return ids of the snapshots of an origin. + + Args: + origin: origin's dict with 'url' key + + Returns: + List of unique snapshot identifiers in hexadecimal format resulting + from the visits of the origin. + """ + return [ + snapshot.hex() for snapshot in storage.origin_snapshot_get_all(origin["url"]) + ] + + def search_origin( url_pattern: str, use_ql: bool = False, diff --git a/swh/web/tests/common/test_archive.py b/swh/web/tests/common/test_archive.py --- a/swh/web/tests/common/test_archive.py +++ b/swh/web/tests/common/test_archive.py @@ -216,6 +216,14 @@ assert actual_origin == expected_origin +def test_lookup_origin_snapshots(archive_data, origin_with_multiple_visits): + origin_url = origin_with_multiple_visits["url"] + visits = archive_data.origin_visit_get(origin_url) + + origin_snapshots = archive.lookup_origin_snapshots(origin_with_multiple_visits) + assert set(origin_snapshots) == {v["snapshot"] for v in visits} + + def test_lookup_release_ko_id_checksum_not_a_sha1(invalid_sha1): with pytest.raises(BadInputExc) as e: archive.lookup_release(invalid_sha1)