diff options
author | Christian Sattler <sattler.christian@gmail.com> | 2022-01-05 18:00:45 +0100 |
---|---|---|
committer | John Villalovos <john@sodarock.com> | 2022-01-13 17:17:20 -0800 |
commit | 0007006c184c64128caa96b82dafa3db0ea1101f (patch) | |
tree | 021d517ebf6ec79d914b331eb3442d18b33f2be8 | |
parent | 2c62d91a67442b21ce3011a2ba5aec7360ca766f (diff) | |
download | gitlab-0007006c184c64128caa96b82dafa3db0ea1101f.tar.gz |
feat: add support for Groups API method `transfer()`
-rw-r--r-- | gitlab/exceptions.py | 4 | ||||
-rw-r--r-- | gitlab/v4/objects/groups.py | 24 |
2 files changed, 27 insertions, 1 deletions
diff --git a/gitlab/exceptions.py b/gitlab/exceptions.py index 6b86471..54f9b8c 100644 --- a/gitlab/exceptions.py +++ b/gitlab/exceptions.py @@ -107,6 +107,10 @@ class GitlabTransferProjectError(GitlabOperationError): pass +class GitlabGroupTransferError(GitlabOperationError): + pass + + class GitlabProjectDeployKeyError(GitlabOperationError): pass diff --git a/gitlab/v4/objects/groups.py b/gitlab/v4/objects/groups.py index 662ea5d..adfca6e 100644 --- a/gitlab/v4/objects/groups.py +++ b/gitlab/v4/objects/groups.py @@ -95,12 +95,34 @@ class Group(SaveMixin, ObjectDeleteMixin, RESTObject): 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 |