From a02f53730097e2e3807617a6b44795a3c9f6301c Mon Sep 17 00:00:00 2001 From: Oleh Paduchak Date: Mon, 2 Dec 2024 14:23:00 +0200 Subject: [PATCH] fixed gitlab configuration --- addon_imps/storage/gitlab.py | 12 ++++++------ addon_imps/tests/storage/test_gitlab.py | 2 +- .../commands/migrate_authorized_account.py | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/addon_imps/storage/gitlab.py b/addon_imps/storage/gitlab.py index 3369d0c6..aa490bf4 100644 --- a/addon_imps/storage/gitlab.py +++ b/addon_imps/storage/gitlab.py @@ -29,7 +29,7 @@ class GitlabStorageImp(storage.StorageAddonHttpRequestorImp): """ async def get_external_account_id(self, _: dict[str, str]) -> str: - async with self.network.GET("user/preferences") as response: + async with self.network.GET("api/v4/user/preferences") as response: resp_json = await response.json_content() return resp_json.get("user_id", "") @@ -55,7 +55,7 @@ async def list_root_items(self, page_cursor: str = "") -> storage.ItemSampleResu "sort": "asc", }, ) - async with self.network.GET("projects", query=query_params) as response: + async with self.network.GET("api/v4/projects", query=query_params) as response: resp = await response.json_content() return ItemSampleResult( items=[Repository.from_json(item).item_result for item in resp], @@ -93,12 +93,12 @@ async def get_item_info(self, item_id: str) -> storage.ItemResult: return (await self._get_repository(parsed_id.repo_id)).item_result async def _get_repository(self, repo_id): - async with self.network.GET(f"projects/{repo_id}") as response: + async with self.network.GET(f"api/v4/projects/{repo_id}") as response: content = await response.json_content() return Repository.from_json(content) async def get_file_or_folder(self, parsed_id: ItemId): - async with self.network.GET(f"projects/{parsed_id.repo_id}") as response: + async with self.network.GET(f"api/v4/projects/{parsed_id.repo_id}") as response: content = await response.json_content() ref = content.get("default_branch") if file_item := await self._get_file(parsed_id, ref): @@ -113,7 +113,7 @@ async def get_file_or_folder(self, parsed_id: ItemId): async def _get_file(self, parsed_id, ref): async with self.network.GET( - f"projects/{parsed_id.repo_id}/repository/files/{quote_plus(parsed_id.file_path)}", + f"api/v4/projects/{parsed_id.repo_id}/repository/files/{quote_plus(parsed_id.file_path)}", query={"ref": ref}, ) as response: content = await response.json_content() @@ -142,7 +142,7 @@ async def list_child_items( }, ) async with self.network.GET( - f"projects/{parsed_id.repo_id}/repository/tree", + f"api/v4/projects/{parsed_id.repo_id}/repository/tree", query=query_params, ) as response: if response.http_status == HTTPStatus.NOT_FOUND: diff --git a/addon_imps/tests/storage/test_gitlab.py b/addon_imps/tests/storage/test_gitlab.py index 874fa035..abf75385 100644 --- a/addon_imps/tests/storage/test_gitlab.py +++ b/addon_imps/tests/storage/test_gitlab.py @@ -28,7 +28,7 @@ def _patch_get(self, return_value: dict | list, status=200, headers=None): def _assert_get(self, url: str, query: dict = None): extra_params = {"query": query} if query else {} - self.network.GET.assert_called_once_with(url, **extra_params) + self.network.GET.assert_called_once_with(f"api/v4/{url}", **extra_params) self.network.GET.return_value.__aenter__.assert_awaited_once() self.network.GET.return_value.__aenter__.return_value.json_content.assert_awaited_once() self.network.GET.return_value.__aexit__.assert_awaited_once_with( diff --git a/addon_service/management/commands/migrate_authorized_account.py b/addon_service/management/commands/migrate_authorized_account.py index 49abfe66..68e04287 100644 --- a/addon_service/management/commands/migrate_authorized_account.py +++ b/addon_service/management/commands/migrate_authorized_account.py @@ -227,6 +227,6 @@ def get_api_base_url(self, external_service, osf_account): if external_service.wb_key == "owncloud": return f"{osf_account.profile_url.removesuffix('/')}/remote.php/dav/files/{osf_account.display_name}/" elif external_service.wb_key == "gitlab": - return f"{osf_account.oauth_secret.removesuffix('/')}/api/v4/" + return f"{osf_account.oauth_secret.removesuffix('/')}" elif external_service.wb_key == "dataverse": return f"https://{osf_account.oauth_key}"