Skip to content

Commit 6cb9d92

Browse files
committed
feat(api): add support for Group Import/Export API (#1037)
1 parent 6ce5d1f commit 6cb9d92

File tree

3 files changed

+55
-1
lines changed

3 files changed

+55
-1
lines changed

gitlab/exceptions.py

+4
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,10 @@ class GitlabAttachFileError(GitlabOperationError):
209209
pass
210210

211211

212+
class GitlabImportError(GitlabOperationError):
213+
pass
214+
215+
212216
class GitlabCherryPickError(GitlabOperationError):
213217
pass
214218

gitlab/mixins.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ def approve(self, access_level=gitlab.DEVELOPER_ACCESS, **kwargs):
444444

445445

446446
class ExportMixin(object):
447-
@cli.register_custom_action("ProjectExport")
447+
@cli.register_custom_action(("GroupExport", "ProjectExport"))
448448
@exc.on_http_error(exc.GitlabGetError)
449449
def download(self, streamed=False, action=None, chunk_size=1024, **kwargs):
450450
"""Download the archive of a resource export.

gitlab/v4/objects.py

+50
Original file line numberDiff line numberDiff line change
@@ -991,6 +991,26 @@ class GroupEpicManager(CRUDMixin, RESTManager):
991991
_types = {"labels": types.ListAttribute}
992992

993993

994+
class GroupExport(ExportMixin, RESTObject):
995+
_id_attr = None
996+
997+
998+
class GroupExportManager(GetWithoutIdMixin, CreateMixin, RESTManager):
999+
_path = "/groups/%(group_id)s/export"
1000+
_obj_cls = GroupExport
1001+
_from_parent_attrs = {"group_id": "id"}
1002+
1003+
1004+
class GroupImport(RESTObject):
1005+
_id_attr = None
1006+
1007+
1008+
class GroupImportManager(GetWithoutIdMixin, RESTManager):
1009+
_path = "/groups/%(group_id)s/import"
1010+
_obj_cls = GroupImport
1011+
_from_parent_attrs = {"group_id": "id"}
1012+
1013+
9941014
class GroupIssue(RESTObject):
9951015
pass
9961016

@@ -1290,7 +1310,9 @@ class Group(SaveMixin, ObjectDeleteMixin, RESTObject):
12901310
("badges", "GroupBadgeManager"),
12911311
("boards", "GroupBoardManager"),
12921312
("customattributes", "GroupCustomAttributeManager"),
1313+
("exports", "GroupExportManager"),
12931314
("epics", "GroupEpicManager"),
1315+
("imports", "GroupImportManager"),
12941316
("issues", "GroupIssueManager"),
12951317
("labels", "GroupLabelManager"),
12961318
("members", "GroupMemberManager"),
@@ -1431,6 +1453,34 @@ class GroupManager(CRUDMixin, RESTManager):
14311453
),
14321454
)
14331455

1456+
@exc.on_http_error(exc.GitlabImportError)
1457+
def import_group(self, file, path, name, parent_id=None, **kwargs):
1458+
"""Import a group from an archive file.
1459+
1460+
Args:
1461+
file: Data or file object containing the group
1462+
path (str): The path for the new group to be imported.
1463+
name (str): The name for the new group.
1464+
parent_id (str): ID of a parent group that the group will
1465+
be imported into.
1466+
**kwargs: Extra options to send to the server (e.g. sudo)
1467+
1468+
Raises:
1469+
GitlabAuthenticationError: If authentication is not correct
1470+
GitlabImportError: If the server failed to perform the request
1471+
1472+
Returns:
1473+
dict: A representation of the import status.
1474+
"""
1475+
files = {"file": ("file.tar.gz", file)}
1476+
data = {"path": path, "name": name}
1477+
if parent_id is not None:
1478+
data["parent_id"] = parent_id
1479+
1480+
return self.gitlab.http_post(
1481+
"/groups/import", post_data=data, files=files, **kwargs
1482+
)
1483+
14341484

14351485
class Hook(ObjectDeleteMixin, RESTObject):
14361486
_url = "/hooks"

0 commit comments

Comments
 (0)