Skip to content

Commit 8867ee5

Browse files
nejchJohnVillalovos
authored andcommitted
feat(objects): support get project storage endpoint
1 parent 792cee9 commit 8867ee5

File tree

4 files changed

+73
-0
lines changed

4 files changed

+73
-0
lines changed

docs/gl_objects/projects.rst

+27
Original file line numberDiff line numberDiff line change
@@ -783,3 +783,30 @@ Get all additional statistics of a project::
783783
Get total fetches in last 30 days of a project::
784784

785785
total_fetches = project.additionalstatistics.get().fetches['total']
786+
787+
Project storage
788+
=============================
789+
790+
This endpoint requires admin access.
791+
792+
Reference
793+
---------
794+
795+
* v4 API:
796+
797+
+ :class:`gitlab.v4.objects.ProjectStorage`
798+
+ :class:`gitlab.v4.objects.ProjectStorageManager`
799+
+ :attr:`gitlab.v4.objects.Project.storage`
800+
801+
* GitLab API: https://docs.gitlab.com/ee/api/projects.html#get-the-path-to-repository-storage
802+
803+
Examples
804+
---------
805+
806+
Get the repository storage details for a project::
807+
808+
storage = project.storage.get()
809+
810+
Get the repository storage disk path::
811+
812+
disk_path = project.storage.get().disk_path

gitlab/v4/objects/projects.py

+19
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from gitlab.mixins import (
1010
CreateMixin,
1111
CRUDMixin,
12+
GetWithoutIdMixin,
1213
ListMixin,
1314
ObjectDeleteMixin,
1415
RefreshMixin,
@@ -80,6 +81,8 @@
8081
"ProjectForkManager",
8182
"ProjectRemoteMirror",
8283
"ProjectRemoteMirrorManager",
84+
"ProjectStorage",
85+
"ProjectStorageManager",
8386
]
8487

8588

@@ -180,6 +183,7 @@ class Project(RefreshMixin, SaveMixin, ObjectDeleteMixin, RepositoryMixin, RESTO
180183
runners: ProjectRunnerManager
181184
services: ProjectServiceManager
182185
snippets: ProjectSnippetManager
186+
storage: "ProjectStorageManager"
183187
tags: ProjectTagManager
184188
triggers: ProjectTriggerManager
185189
users: ProjectUserManager
@@ -1013,3 +1017,18 @@ class ProjectRemoteMirrorManager(ListMixin, CreateMixin, UpdateMixin, RESTManage
10131017
required=("url",), optional=("enabled", "only_protected_branches")
10141018
)
10151019
_update_attrs = RequiredOptional(optional=("enabled", "only_protected_branches"))
1020+
1021+
1022+
class ProjectStorage(RefreshMixin, RESTObject):
1023+
pass
1024+
1025+
1026+
class ProjectStorageManager(GetWithoutIdMixin, RESTManager):
1027+
_path = "/projects/{project_id}/storage"
1028+
_obj_cls = ProjectStorage
1029+
_from_parent_attrs = {"project_id": "id"}
1030+
1031+
def get(
1032+
self, id: Optional[Union[int, str]] = None, **kwargs: Any
1033+
) -> Optional[ProjectStorage]:
1034+
return cast(Optional[ProjectStorage], super().get(id=id, **kwargs))

tests/functional/api/test_projects.py

+7
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import pytest
44

55
import gitlab
6+
from gitlab.v4.objects.projects import ProjectStorage
67

78

89
def test_create_project(gl, user):
@@ -285,6 +286,12 @@ def test_project_stars(project):
285286
assert project.star_count == 0
286287

287288

289+
def test_project_storage(project):
290+
storage = project.storage.get()
291+
assert isinstance(storage, ProjectStorage)
292+
assert storage.repository_storage == "default"
293+
294+
288295
def test_project_tags(project, project_file):
289296
tag = project.tags.create({"tag_name": "v1.0", "ref": "main"})
290297
assert len(project.tags.list()) == 1

tests/unit/objects/test_projects.py

+20
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
StarredProject,
1313
UserProject,
1414
)
15+
from gitlab.v4.objects.projects import ProjectStorage
1516

1617
project_content = {"name": "name", "id": 1}
1718
languages_content = {
@@ -49,6 +50,19 @@ def resp_get_project():
4950
yield rsps
5051

5152

53+
@pytest.fixture
54+
def resp_get_project_storage():
55+
with responses.RequestsMock() as rsps:
56+
rsps.add(
57+
method=responses.GET,
58+
url="http://localhost/api/v4/projects/1/storage",
59+
json={"project_id": 1, "disk_path": "/disk/path"},
60+
content_type="application/json",
61+
status=200,
62+
)
63+
yield rsps
64+
65+
5266
@pytest.fixture
5367
def resp_user_projects():
5468
with responses.RequestsMock() as rsps:
@@ -256,6 +270,12 @@ def test_get_project_languages(project, resp_list_languages):
256270
assert coffee_script == 00.01
257271

258272

273+
def test_get_project_storage(project, resp_get_project_storage):
274+
storage = project.storage.get()
275+
assert isinstance(storage, ProjectStorage)
276+
assert storage.disk_path == "/disk/path"
277+
278+
259279
@pytest.mark.skip(reason="missing test")
260280
def test_archive_project(gl):
261281
pass

0 commit comments

Comments
 (0)