summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNejc Habjan <hab.nejc@gmail.com>2020-04-05 21:56:43 +0200
committerNejc Habjan <hab.nejc@gmail.com>2020-04-05 22:48:33 +0200
commit6cb9d9238ea3cc73689d6b71e991f2ec233ee8e6 (patch)
tree3b94bc78d2f32e6e1368874d807b3aca8e5ab231
parent6ce5d1f14060a403f05993d77bf37720c25534ba (diff)
downloadgitlab-6cb9d9238ea3cc73689d6b71e991f2ec233ee8e6.tar.gz
feat(api): add support for Group Import/Export API (#1037)
-rw-r--r--gitlab/exceptions.py4
-rw-r--r--gitlab/mixins.py2
-rw-r--r--gitlab/v4/objects.py50
3 files changed, 55 insertions, 1 deletions
diff --git a/gitlab/exceptions.py b/gitlab/exceptions.py
index d6791f2..099a901 100644
--- a/gitlab/exceptions.py
+++ b/gitlab/exceptions.py
@@ -209,6 +209,10 @@ class GitlabAttachFileError(GitlabOperationError):
pass
+class GitlabImportError(GitlabOperationError):
+ pass
+
+
class GitlabCherryPickError(GitlabOperationError):
pass
diff --git a/gitlab/mixins.py b/gitlab/mixins.py
index 39d13c9..3053427 100644
--- a/gitlab/mixins.py
+++ b/gitlab/mixins.py
@@ -444,7 +444,7 @@ class AccessRequestMixin(object):
class ExportMixin(object):
- @cli.register_custom_action("ProjectExport")
+ @cli.register_custom_action(("GroupExport", "ProjectExport"))
@exc.on_http_error(exc.GitlabGetError)
def download(self, streamed=False, action=None, chunk_size=1024, **kwargs):
"""Download the archive of a resource export.
diff --git a/gitlab/v4/objects.py b/gitlab/v4/objects.py
index 281d3c7..02e6981 100644
--- a/gitlab/v4/objects.py
+++ b/gitlab/v4/objects.py
@@ -991,6 +991,26 @@ class GroupEpicManager(CRUDMixin, RESTManager):
_types = {"labels": types.ListAttribute}
+class GroupExport(ExportMixin, RESTObject):
+ _id_attr = None
+
+
+class GroupExportManager(GetWithoutIdMixin, CreateMixin, RESTManager):
+ _path = "/groups/%(group_id)s/export"
+ _obj_cls = GroupExport
+ _from_parent_attrs = {"group_id": "id"}
+
+
+class GroupImport(RESTObject):
+ _id_attr = None
+
+
+class GroupImportManager(GetWithoutIdMixin, RESTManager):
+ _path = "/groups/%(group_id)s/import"
+ _obj_cls = GroupImport
+ _from_parent_attrs = {"group_id": "id"}
+
+
class GroupIssue(RESTObject):
pass
@@ -1290,7 +1310,9 @@ class Group(SaveMixin, ObjectDeleteMixin, RESTObject):
("badges", "GroupBadgeManager"),
("boards", "GroupBoardManager"),
("customattributes", "GroupCustomAttributeManager"),
+ ("exports", "GroupExportManager"),
("epics", "GroupEpicManager"),
+ ("imports", "GroupImportManager"),
("issues", "GroupIssueManager"),
("labels", "GroupLabelManager"),
("members", "GroupMemberManager"),
@@ -1431,6 +1453,34 @@ class GroupManager(CRUDMixin, RESTManager):
),
)
+ @exc.on_http_error(exc.GitlabImportError)
+ def import_group(self, file, path, name, parent_id=None, **kwargs):
+ """Import a group from an archive file.
+
+ Args:
+ file: Data or file object containing the group
+ path (str): The path for the new group to be imported.
+ name (str): The name for the new group.
+ parent_id (str): ID of a parent group that the group will
+ be imported into.
+ **kwargs: Extra options to send to the server (e.g. sudo)
+
+ Raises:
+ GitlabAuthenticationError: If authentication is not correct
+ GitlabImportError: If the server failed to perform the request
+
+ Returns:
+ dict: A representation of the import status.
+ """
+ files = {"file": ("file.tar.gz", file)}
+ data = {"path": path, "name": name}
+ if parent_id is not None:
+ data["parent_id"] = parent_id
+
+ return self.gitlab.http_post(
+ "/groups/import", post_data=data, files=files, **kwargs
+ )
+
class Hook(ObjectDeleteMixin, RESTObject):
_url = "/hooks"