diff --git a/swh/web/browse/urls.py b/swh/web/browse/urls.py --- a/swh/web/browse/urls.py +++ b/swh/web/browse/urls.py @@ -15,7 +15,7 @@ import swh.web.browse.views.release # noqa import swh.web.browse.views.revision # noqa import swh.web.browse.views.snapshot # noqa -from swh.web.common.utils import reverse +from swh.web.common.utils import origin_visit_types, reverse def _browse_help_view(request): @@ -31,6 +31,7 @@ { "heading": "Search software origins to browse", "enable_ql": config.get_config()["search_config"].get("enable_ql", False), + "visit_types": origin_visit_types(), }, ) diff --git a/swh/web/common/utils.py b/swh/web/common/utils.py --- a/swh/web/common/utils.py +++ b/swh/web/common/utils.py @@ -25,7 +25,7 @@ from swh.web.common.exc import BadInputExc from swh.web.common.typing import QueryParameters -from swh.web.config import ORIGIN_VISIT_TYPES, get_config +from swh.web.config import get_config, search SWH_WEB_METRICS_REGISTRY = CollectorRegistry(auto_describe=True) @@ -284,7 +284,6 @@ ] ), "swh_web_version": get_distribution("swh.web").version, - "visit_types": ORIGIN_VISIT_TYPES, "iframe_mode": False, } @@ -389,3 +388,13 @@ cache.set("swh-deposit-list", deposits_data) return deposits_data["results"] + + +def origin_visit_types() -> List[str]: + """Return the exhaustive list of visit types for origins + ingested into the archive. + """ + try: + return sorted(search().visit_types_count().keys()) + except Exception: + return [] diff --git a/swh/web/config.py b/swh/web/config.py --- a/swh/web/config.py +++ b/swh/web/config.py @@ -22,21 +22,6 @@ "webapp.internal.staging.swh.network", ] -ORIGIN_VISIT_TYPES = [ - "cran", - "deb", - "deposit", - "ftp", - "hg", - "git", - "nixguix", - "npm", - "pypi", - "svn", - "tar", -] - - SETTINGS_DIR = os.path.dirname(settings.__file__) DEFAULT_CONFIG = { diff --git a/swh/web/tests/common/test_utils.py b/swh/web/tests/common/test_utils.py --- a/swh/web/tests/common/test_utils.py +++ b/swh/web/tests/common/test_utils.py @@ -285,3 +285,15 @@ ) assert utils.get_deposits_list() == deposits_data["results"] + + +@pytest.mark.parametrize("backend", ["swh-search", "swh-storage"]) +def test_origin_visit_types(mocker, backend): + if backend != "swh-search": + # equivalent to not configuring search in the config + search = mocker.patch("swh.web.common.utils.search") + search.return_value = None + assert utils.origin_visit_types() == [] + else: + # see swh/web/tests/data.py for origins added for tests + assert utils.origin_visit_types() == ["git", "tar"] diff --git a/swh/web/urls.py b/swh/web/urls.py --- a/swh/web/urls.py +++ b/swh/web/urls.py @@ -27,6 +27,7 @@ swh_handle404, swh_handle500, ) +from swh.web.common.utils import origin_visit_types from swh.web.config import get_config swh_web_config = get_config() @@ -40,7 +41,10 @@ return render( request, "homepage.html", - {"enable_ql": swh_web_config["search_config"].get("enable_ql", False),}, + { + "enable_ql": swh_web_config["search_config"].get("enable_ql", False), + "visit_types": origin_visit_types(), + }, )