diff --git a/swh/lister/gitlab/lister.py b/swh/lister/gitlab/lister.py --- a/swh/lister/gitlab/lister.py +++ b/swh/lister/gitlab/lister.py @@ -106,7 +106,10 @@ if instance is None: instance = parse_url(url).host super().__init__( - scheduler=scheduler, url=url, instance=instance, credentials=credentials, + scheduler=scheduler, + url=url.rstrip("/"), + instance=instance, + credentials=credentials, ) self.incremental = incremental self.last_page: Optional[str] = None @@ -161,7 +164,7 @@ } if id_after is not None: parameters["id_after"] = str(id_after) - return f"{self.url}projects?{urlencode(parameters)}" + return f"{self.url}/projects?{urlencode(parameters)}" def get_pages(self) -> Iterator[PageResult]: next_page: Optional[str] diff --git a/swh/lister/gitlab/tests/test_lister.py b/swh/lister/gitlab/tests/test_lister.py --- a/swh/lister/gitlab/tests/test_lister.py +++ b/swh/lister/gitlab/tests/test_lister.py @@ -216,6 +216,16 @@ assert lister.session.headers["Authorization"] == "Bearer api-token" +@pytest.mark.parametrize("url", [api_url("gitlab").rstrip("/"), api_url("gitlab"),]) +def test_lister_gitlab_url_computation(url, swh_scheduler): + lister = GitLabLister(scheduler=swh_scheduler, url=url) + assert not lister.url.endswith("/") + + page_url = lister.page_url() + # ensure the generated url contains the separated / + assert page_url.startswith(f"{lister.url}/projects") + + @pytest.mark.parametrize( "url,expected_result", [