Skip to content

Commit 80101d4

Browse files
committed
Add support for Groups API method transfer_group.
1 parent 9894b35 commit 80101d4

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

gitlab/exceptions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ class GitlabTransferProjectError(GitlabOperationError):
107107
pass
108108

109109

110+
class GitlabTransferGroupError(GitlabOperationError):
111+
pass
112+
113+
110114
class GitlabProjectDeployKeyError(GitlabOperationError):
111115
pass
112116

gitlab/v4/objects/groups.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,30 @@ def transfer_project(self, project_id: int, **kwargs: Any) -> None:
9393
path = f"/groups/{self.id}/projects/{project_id}"
9494
self.manager.gitlab.http_post(path, **kwargs)
9595

96+
@cli.register_custom_action("Group", tuple(), ("group_id",))
97+
@exc.on_http_error(exc.GitlabTransferProjectError)
98+
def transfer_group(self, group_id: Optional[int] = None, **kwargs: Any) -> None:
99+
"""Transfer a project to this group.
100+
101+
Requires GitLab ≥14.6.
102+
103+
Args:
104+
group_id: ID of the new parent group. When not specified,
105+
the group to transfer is instead turned into a top-level group.
106+
**kwargs: Extra options to send to the server (e.g. sudo)
107+
108+
Raises:
109+
GitlabAuthenticationError: If authentication is not correct
110+
GitlabTransferProjectError: If the group could not be transferred
111+
"""
112+
path = f"/groups/{self.id}/transfer"
113+
114+
def data():
115+
if group_id is not None:
116+
yield ("group_id", group_id)
117+
118+
self.manager.gitlab.http_post(path, post_data=dict(data()), **kwargs)
119+
96120
@cli.register_custom_action("Group", ("scope", "search"))
97121
@exc.on_http_error(exc.GitlabSearchError)
98122
def search(

0 commit comments

Comments
 (0)