summaryrefslogtreecommitdiff
path: root/gitlab/v4/objects.py
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 /gitlab/v4/objects.py
parent6ce5d1f14060a403f05993d77bf37720c25534ba (diff)
downloadgitlab-6cb9d9238ea3cc73689d6b71e991f2ec233ee8e6.tar.gz
feat(api): add support for Group Import/Export API (#1037)
Diffstat (limited to 'gitlab/v4/objects.py')
-rw-r--r--gitlab/v4/objects.py50
1 files changed, 50 insertions, 0 deletions
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"