gitlab: Deal with missing or trailing / in url input
This commit is contained in:
parent
3bede83d0f
commit
72be074a79
2 changed files with 15 additions and 2 deletions
|
@ -106,7 +106,10 @@ class GitLabLister(Lister[GitLabListerState, PageResult]):
|
|||
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 @@ class GitLabLister(Lister[GitLabListerState, PageResult]):
|
|||
}
|
||||
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]
|
||||
|
|
|
@ -216,6 +216,16 @@ def test_lister_gitlab_credentials(swh_scheduler):
|
|||
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",
|
||||
[
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue