pattern: Use URL network location as instance name when not provided

Make the instance parameter of the base pattern lister optional and set
lister name to URL network location when not provided.

It simplifies lister creation when associated forge type have a lot of
instances in the wild (e.g. gitlab or cgit) while giving more details
about the listed forge instance.

Also process listers for forge with multiple instances (cgit, gitea,
gitlab, phabricator and tuleap) to ensure URL network location will be
used when instance parameter is not provided.

Related to T3403
This commit is contained in:
Antoine Lambert 2021-07-13 12:33:41 +02:00
parent df46b22098
commit 6c12350863
7 changed files with 33 additions and 28 deletions

View file

@ -1,4 +1,4 @@
# Copyright (C) 2020 The Software Heritage developers
# Copyright (C) 2020-2021 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
@ -39,6 +39,18 @@ def test_instantiation(swh_scheduler):
lister.run()
def test_lister_instance_name(swh_scheduler):
lister = InstantiableLister(
scheduler=swh_scheduler, url="https://example.org", instance="example"
)
assert lister.instance == "example"
lister = InstantiableLister(scheduler=swh_scheduler, url="https://example.org")
assert lister.instance == "example.org"
def test_instantiation_from_configfile(swh_scheduler, mocker):
mock_load_from_envvar = mocker.patch("swh.lister.pattern.load_from_envvar")
mock_get_scheduler = mocker.patch("swh.lister.pattern.get_scheduler")