Skip to content

Commit 0007006

Browse files
sattlercJohnVillalovos
authored andcommitted
feat: add support for Groups API method transfer()
1 parent 2c62d91 commit 0007006

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
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 GitlabGroupTransferError(GitlabOperationError):
111+
pass
112+
113+
110114
class GitlabProjectDeployKeyError(GitlabOperationError):
111115
pass
112116

gitlab/v4/objects/groups.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,34 @@ def transfer_project(self, project_id: int, **kwargs: Any) -> None:
9595
path = f"/groups/{self.encoded_id}/projects/{project_id}"
9696
self.manager.gitlab.http_post(path, **kwargs)
9797

98+
@cli.register_custom_action("Group", tuple(), ("group_id",))
99+
@exc.on_http_error(exc.GitlabGroupTransferError)
100+
def transfer(self, group_id: Optional[int] = None, **kwargs: Any) -> None:
101+
"""Transfer the group to a new parent group or make it a top-level group.
102+
103+
Requires GitLab ≥14.6.
104+
105+
Args:
106+
group_id: ID of the new parent group. When not specified,
107+
the group to transfer is instead turned into a top-level group.
108+
**kwargs: Extra options to send to the server (e.g. sudo)
109+
110+
Raises:
111+
GitlabAuthenticationError: If authentication is not correct
112+
GitlabGroupTransferError: If the group could not be transferred
113+
"""
114+
path = f"/groups/{self.id}/transfer"
115+
post_data = {}
116+
if group_id is not None:
117+
post_data["group_id"] = group_id
118+
self.manager.gitlab.http_post(path, post_data=post_data, **kwargs)
119+
98120
@cli.register_custom_action("Group", ("scope", "search"))
99121
@exc.on_http_error(exc.GitlabSearchError)
100122
def search(
101123
self, scope: str, search: str, **kwargs: Any
102124
) -> Union[gitlab.GitlabList, List[Dict[str, Any]]]:
103-
"""Search the group resources matching the provided string.'
125+
"""Search the group resources matching the provided string.
104126
105127
Args:
106128
scope: Scope of the search

0 commit comments

Comments
 (0)