Skip to content
Snippets Groups Projects
Verified Commit e91e0bf0 authored by Antoine R. Dumont's avatar Antoine R. Dumont
Browse files

cgit: Allow url to be optional

Some cgit instances are at a domain's root path so we can build their url directly from
their 'instance' parameter.

This unifies further the cli to register a lister and the cli to schedule the listed
origins from a forge.

[1]
```
https://git.kernel.org
https://source.codeaurora.org
https://git.trueelena.org
https://dev.sanctum.geek.nz
https://git.trueelena.org
https://git.dpkg.org
https://anongit.mindrot.org
https://git.aurel32.net
https://gitweb.gentoo.org
https://git.joeyh.name
https://git.adrian.geek.nz
```

Refs. swh/devel/swh-lister#4693
parent 19bdeefb
No related branches found
No related tags found
No related merge requests found
# Copyright (C) 2019-2022 The Software Heritage developers
# Copyright (C) 2019-2023 The Software Heritage developers
# License: GNU General Public License version 3, or any later version
# See top-level LICENSE file for more information
......@@ -46,7 +46,7 @@ class CGitLister(StatelessLister[Repositories]):
def __init__(
self,
scheduler: SchedulerInterface,
url: str,
url: Optional[str] = None,
instance: Optional[str] = None,
credentials: Optional[CredentialsType] = None,
base_git_url: Optional[str] = None,
......@@ -57,8 +57,9 @@ class CGitLister(StatelessLister[Repositories]):
"""Lister class for CGit repositories.
Args:
url: main URL of the CGit instance, i.e. url of the index
of published git repositories on this instance.
url: (Optional) Root URL of the CGit instance, i.e. url of the index of
published git repositories on this instance. Defaults to
:file:`https://{instance}` if unset.
instance: Name of cgit instance. Defaults to url's network location
if unset.
base_git_url: Optional base git url which allows the origin url
......
# Copyright (C) 2019-2022 The Software Heritage developers
# Copyright (C) 2019-2023 The Software Heritage developers
# License: GNU General Public License version 3, or any later version
# See top-level LICENSE file for more information
......@@ -155,6 +155,25 @@ requests_mock_datadir_missing_url = requests_mock_datadir_factory(
)
def test_lister_cgit_instantiate(swh_scheduler):
"""Build a lister with either an url or an instance is fine"""
url = "https://source.codeaurora.org"
lister = CGitLister(swh_scheduler, url=url)
assert lister is not None
assert lister.url == url
assert CGitLister(swh_scheduler, instance="source.codeaurora.org") is not None
assert lister is not None
assert lister.url == url
def test_lister_cgit_fail_to_instantiate(swh_scheduler):
"""Build a lister without its url nor its instance should raise"""
# ... It will raise without any of those
with pytest.raises(ValueError, match="'url' or 'instance'"):
CGitLister(swh_scheduler)
def test_lister_cgit_get_origin_from_repo_failing(
requests_mock_datadir_missing_url, swh_scheduler
):
......
......@@ -116,12 +116,14 @@ class Lister(Generic[StateType, PageType]):
raise ValueError("Must set the LISTER_NAME attribute on Lister classes")
self.url: str
# lister can be instantiated using directly their 'url' (the default behavior)
# or derive their url through an 'instance' (their domain's root path) parameter
if url is not None:
# Retro-compability with lister already instantiated out of a provided url
# direct url instantiation
self.url = url
elif url is None and instance is not None:
# Allow lister to be instantiated simply with their type and instance
# (as in their domain like "gitlab.com", "git.garbaye.fr", ...)
# Allow instantiation through their instance parameter (domain's root path)
# (e.g. "gitlab.com", "git.garbaye.fr", ...)
self.url = self.build_url(instance)
else:
raise ValueError(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment