8000 feat(projects): add support for project restore API by nejch · Pull Request #2171 · python-gitlab/python-gitlab · GitHub
[go: up one dir, main page]

Skip to content

feat(projects): add support for project restore API #2171

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/gl_objects/projects.rst
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ Delete a project::
# or
project.delete()

Restore a project marked for deletion (Premium only)::

project.restore()

Fork a project::

fork = project.forks.create({})
Expand Down
4 changes: 4 additions & 0 deletions gitlab/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,10 @@ class GitlabRepairError(GitlabOperationError):
pass


class GitlabRestoreError(GitlabOperationError):
pass


class GitlabRevertError(GitlabOperationError):
pass

Expand Down
15 changes: 15 additions & 0 deletions gitlab/v4/objects/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,21 @@ def upload(
assert isinstance(data, dict)
return {"alt": data["alt"], "url": data["url"], "markdown": data["markdown"]}

@cli.register_custom_action("Project")
@exc.on_http_error(exc.GitlabRestoreError)
def restore(self, **kwargs: Any) -> None:
"""Restore a project marked for deletion.

Args:
**kwargs: Extra options to send to the server (e.g. sudo)

Raises:
GitlabAuthenticationError: If authentication is not correct
GitlabRestoreError: If the server failed to perform the request
"""
path = f"/projects/{self.encoded_id}/restore"
self.manager.gitlab.http_post(path, **kwargs)

@cli.register_custom_action("Project", optional=("wiki",))
@exc.on_http_error(exc.GitlabGetError)
def snapshot(
Expand Down
17 changes: 17 additions & 0 deletions tests/unit/objects/test_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,19 @@ def resp_delete_push_rules_project(no_content):
yield rsps


@pytest.fixture
def resp_restore_project(created_content):
with responses.RequestsMock() as rsps:
rsps.add(
method=responses.POST,
url="http://localhost/api/v4/projects/1/restore",
json=created_content,
content_type="application/json",
status=201,
)
yield rsps


@pytest.fixture
def resp_start_pull_mirroring_project():
with responses.RequestsMock() as rsps:
Expand Down Expand Up @@ -753,6 +766,10 @@ def test_project_pull_mirror(project, resp_start_pull_mirroring_project):
project.mirror_pull()


def test_project_restore(project, resp_restore_project):
project.restore()


def test_project_snapshot(project, resp_snapshot_project):
tar_file = project.snapshot()
assert isinstance(tar_file, bytes)
0