Skip to content

Commit

Permalink
feat: add support for Groups API method transfer()
Browse files Browse the repository at this point in the history
  • Loading branch information
sattlerc authored and JohnVillalovos committed Jan 14, 2022
1 parent 2c62d91 commit 0007006
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
4 changes: 4 additions & 0 deletions gitlab/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ class GitlabTransferProjectError(GitlabOperationError):
pass


class GitlabGroupTransferError(GitlabOperationError):
pass


class GitlabProjectDeployKeyError(GitlabOperationError):
pass

Expand Down
24 changes: 23 additions & 1 deletion gitlab/v4/objects/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,34 @@ def transfer_project(self, project_id: int, **kwargs: Any) -> None:
path = f"/groups/{self.encoded_id}/projects/{project_id}"
self.manager.gitlab.http_post(path, **kwargs)

@cli.register_custom_action("Group", tuple(), ("group_id",))
@exc.on_http_error(exc.GitlabGroupTransferError)
def transfer(self, group_id: Optional[int] = None, **kwargs: Any) -> None:
"""Transfer the group to a new parent group or make it a top-level group.
Requires GitLab ≥14.6.
Args:
group_id: ID of the new parent group. When not specified,
the group to transfer is instead turned into a top-level group.
**kwargs: Extra options to send to the server (e.g. sudo)
Raises:
GitlabAuthenticationError: If authentication is not correct
GitlabGroupTransferError: If the group could not be transferred
"""
path = f"/groups/{self.id}/transfer"
post_data = {}
if group_id is not None:
post_data["group_id"] = group_id
self.manager.gitlab.http_post(path, post_data=post_data, **kwargs)

@cli.register_custom_action("Group", ("scope", "search"))
@exc.on_http_error(exc.GitlabSearchError)
def search(
self, scope: str, search: str, **kwargs: Any
) -> Union[gitlab.GitlabList, List[Dict[str, Any]]]:
"""Search the group resources matching the provided string.'
"""Search the group resources matching the provided string.
Args:
scope: Scope of the search
Expand Down

0 comments on commit 0007006

Please sign in to comment.