Skip to content

Commit 4794ecc

Browse files
nejchJohnVillalovos
authored andcommitted
feat(projects): add support for project restore API
1 parent 9833632 commit 4794ecc

File tree

4 files changed

+40
-0
lines changed

4 files changed

+40
-0
lines changed

docs/gl_objects/projects.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ Delete a project::
115115
# or
116116
project.delete()
117117

118+
Restore a project marked for deletion (Premium only)::
119+
120+
project.restore()
121+
118122
Fork a project::
119123

120124
fork = project.forks.create({})

gitlab/exceptions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,10 @@ class GitlabRepairError(GitlabOperationError):
286286
pass
287287

288288

289+
class GitlabRestoreError(GitlabOperationError):
290+
pass
291+
292+
289293
class GitlabRevertError(GitlabOperationError):
290294
pass
291295

gitlab/v4/objects/projects.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,21 @@ def upload(
477477
assert isinstance(data, dict)
478478
return {"alt": data["alt"], "url": data["url"], "markdown": data["markdown"]}
479479

480+
@cli.register_custom_action("Project")
481+
@exc.on_http_error(exc.GitlabRestoreError)
482+
def restore(self, **kwargs: Any) -> None:
483+
"""Restore a project marked for deletion.
484+
485+
Args:
486+
**kwargs: Extra options to send to the server (e.g. sudo)
487+
488+
Raises:
489+
GitlabAuthenticationError: If authentication is not correct
490+
GitlabRestoreError: If the server failed to perform the request
491+
"""
492+
path = f"/projects/{self.encoded_id}/restore"
493+
self.manager.gitlab.http_post(path, **kwargs)
494+
480495
@cli.register_custom_action("Project", optional=("wiki",))
481496
@exc.on_http_error(exc.GitlabGetError)
482497
def snapshot(

tests/unit/objects/test_projects.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,19 @@ def resp_delete_push_rules_project(no_content):
504504
yield rsps
505505

506506

507+
@pytest.fixture
508+
def resp_restore_project(created_content):
509+
with responses.RequestsMock() as rsps:
510+
rsps.add(
511+
method=responses.POST,
512+
url="http://localhost/api/v4/projects/1/restore",
513+
json=created_content,
514+
content_type="application/json",
515+
status=201,
516+
)
517+
yield rsps
518+
519+
507520
@pytest.fixture
508521
def resp_start_pull_mirroring_project():
509522
with responses.RequestsMock() as rsps:
@@ -753,6 +766,10 @@ def test_project_pull_mirror(project, resp_start_pull_mirroring_project):
753766
project.mirror_pull()
754767

755768

769+
def test_project_restore(project, resp_restore_project):
770+
project.restore()
771+
772+
756773
def test_project_snapshot(project, resp_snapshot_project):
757774
tar_file = project.snapshot()
758775
assert isinstance(tar_file, bytes)

0 commit comments

Comments
 (0)