lister: Allow lister to build url out of the instance parameter

This pushes the rather elementary logic within the lister's scope. This will simplify
and unify cli call between lister and scheduler clis. This will also allow to reduce
erroneous operations which can happen for example in the add-forge-now.

With the following, we will only have to provide the type and the instance, then
everything will be scheduled properly.

Refs. swh/devel/swh-lister#4693
This commit is contained in:
Antoine R. Dumont (@ardumont) 2023-05-19 11:04:26 +02:00
parent 596e8c6c40
commit 19bdeefb14
No known key found for this signature in database
GPG key ID: 52E2E9840D10C3B8
7 changed files with 100 additions and 18 deletions

View file

@ -1,4 +1,4 @@
# Copyright (C) 2019-2021 The Software Heritage developers
# Copyright (C) 2019-2023 The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU General Public License version 3, or any later version
# See top-level LICENSE file for more information
@ -17,14 +17,13 @@ lister_args = {
"api_token": "bogus",
},
"gitea": {
"url": "https://try.gitea.io/api/v1/",
"instance": "try.gitea.io",
},
"tuleap": {
"url": "https://tuleap.net",
},
"gitlab": {
"url": "https://gitlab.ow2.org/api/v4",
"instance": "ow2",
"instance": "gitlab.ow2.org",
},
"opam": {"url": "https://opam.ocaml.org", "instance": "opam"},
"maven": {
@ -32,7 +31,7 @@ lister_args = {
"index_url": "http://indexes/export.fld",
},
"gogs": {
"url": "https://try.gogs.io/",
"instance": "try.gogs.io",
"api_token": "secret",
},
"nixguix": {

View file

@ -24,6 +24,24 @@ class InstantiableLister(pattern.Lister[StateType, PageType]):
return d
def test_instantiation_fail_to_instantiate(swh_scheduler):
"""Instantiation without proper url or instance will raise."""
# While instantiating with either a url or instance is fine...
InstantiableLister(scheduler=swh_scheduler, url="https://example.com")
InstantiableLister(scheduler=swh_scheduler, instance="example.com")
# ... Instantiating will fail when:
# - no instance nor url parameters are provided to the constructor
with pytest.raises(ValueError, match="'url' or 'instance"):
InstantiableLister(
scheduler=swh_scheduler,
)
# - an instance, which is not in a net location format, is provided
with pytest.raises(ValueError, match="net location"):
InstantiableLister(scheduler=swh_scheduler, instance="http://example.com")
def test_instantiation(swh_scheduler):
lister = InstantiableLister(
scheduler=swh_scheduler, url="https://example.com", instance="example.com"