Skip to content

Commit 20d6678

Browse files
author
Gauvain Pocentek
authored
Merge pull request #244 from gpocentek/issue/209
Make GroupProject inherit from Project
2 parents 989f3b7 + 380bcc4 commit 20d6678

File tree

1 file changed

+75
-72
lines changed

1 file changed

+75
-72
lines changed

gitlab/objects.py

Lines changed: 75 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -915,20 +915,6 @@ class GroupNotificationSettingsManager(BaseManager):
915915
obj_cls = GroupNotificationSettings
916916

917917

918-
class GroupProject(GitlabObject):
919-
_url = '/groups/%(group_id)s/projects'
920-
canGet = 'from_list'
921-
canCreate = False
922-
canDelete = False
923-
canUpdate = False
924-
optionalListAttrs = ['archived', 'visibility', 'order_by', 'sort',
925-
'search', 'ci_enabled_first']
926-
927-
928-
class GroupProjectManager(BaseManager):
929-
obj_cls = GroupProject
930-
931-
932918
class GroupAccessRequest(GitlabObject):
933919
_url = '/groups/%(group_id)s/access_requests'
934920
canGet = 'from_list'
@@ -957,64 +943,6 @@ class GroupAccessRequestManager(BaseManager):
957943
obj_cls = GroupAccessRequest
958944

959945

960-
class Group(GitlabObject):
961-
_url = '/groups'
962-
requiredCreateAttrs = ['name', 'path']
963-
optionalCreateAttrs = ['description', 'visibility_level']
964-
optionalUpdateAttrs = ['name', 'path', 'description', 'visibility_level']
965-
shortPrintAttr = 'name'
966-
managers = (
967-
('accessrequests', GroupAccessRequestManager, [('group_id', 'id')]),
968-
('members', GroupMemberManager, [('group_id', 'id')]),
969-
('notificationsettings', GroupNotificationSettingsManager,
970-
[('group_id', 'id')]),
971-
('projects', GroupProjectManager, [('group_id', 'id')]),
972-
('issues', GroupIssueManager, [('group_id', 'id')]),
973-
)
974-
975-
GUEST_ACCESS = gitlab.GUEST_ACCESS
976-
REPORTER_ACCESS = gitlab.REPORTER_ACCESS
977-
DEVELOPER_ACCESS = gitlab.DEVELOPER_ACCESS
978-
MASTER_ACCESS = gitlab.MASTER_ACCESS
979-
OWNER_ACCESS = gitlab.OWNER_ACCESS
980-
981-
VISIBILITY_PRIVATE = gitlab.VISIBILITY_PRIVATE
982-
VISIBILITY_INTERNAL = gitlab.VISIBILITY_INTERNAL
983-
VISIBILITY_PUBLIC = gitlab.VISIBILITY_PUBLIC
984-
985-
def transfer_project(self, id, **kwargs):
986-
"""Transfers a project to this new groups.
987-
988-
Attrs:
989-
id (int): ID of the project to transfer.
990-
991-
Raises:
992-
GitlabConnectionError: If the server cannot be reached.
993-
GitlabTransferProjectError: If the server fails to perform the
994-
request.
995-
"""
996-
url = '/groups/%d/projects/%d' % (self.id, id)
997-
r = self.gitlab._raw_post(url, None, **kwargs)
998-
raise_error_from_response(r, GitlabTransferProjectError, 201)
999-
1000-
1001-
class GroupManager(BaseManager):
1002-
obj_cls = Group
1003-
1004-
def search(self, query, **kwargs):
1005-
"""Searches groups by name.
1006-
1007-
Args:
1008-
query (str): The search string
1009-
all (bool): If True, return all the items, without pagination
1010-
1011-
Returns:
1012-
list(Group): a list of matching groups.
1013-
"""
1014-
url = '/groups?search=' + query
1015-
return self.gitlab._raw_list(url, self.obj_cls, **kwargs)
1016-
1017-
1018946
class Hook(GitlabObject):
1019947
_url = '/hooks'
1020948
canUpdate = False
@@ -2724,6 +2652,81 @@ def starred(self, **kwargs):
27242652
return self.gitlab._raw_list("/projects/starred", Project, **kwargs)
27252653

27262654

2655+
class GroupProject(Project):
2656+
_url = '/groups/%(group_id)s/projects'
2657+
canGet = 'from_list'
2658+
canCreate = False
2659+
canDelete = False
2660+
canUpdate = False
2661+
optionalListAttrs = ['archived', 'visibility', 'order_by', 'sort',
2662+
'search', 'ci_enabled_first']
2663+
2664+
def __init__(self, *args, **kwargs):
2665+
Project.__init__(self, *args, **kwargs)
2666+
2667+
2668+
class GroupProjectManager(BaseManager):
2669+
obj_cls = GroupProject
2670+
2671+
2672+
class Group(GitlabObject):
2673+
_url = '/groups'
2674+
requiredCreateAttrs = ['name', 'path']
2675+
optionalCreateAttrs = ['description', 'visibility_level']
2676+
optionalUpdateAttrs = ['name', 'path', 'description', 'visibility_level']
2677+
shortPrintAttr = 'name'
2678+
managers = (
2679+
('accessrequests', GroupAccessRequestManager, [('group_id', 'id')]),
2680+
('members', GroupMemberManager, [('group_id', 'id')]),
2681+
('notificationsettings', GroupNotificationSettingsManager,
2682+
[('group_id', 'id')]),
2683+
('projects', GroupProjectManager, [('group_id', 'id')]),
2684+
('issues', GroupIssueManager, [('group_id', 'id')]),
2685+
)
2686+
2687+
GUEST_ACCESS = gitlab.GUEST_ACCESS
2688+
REPORTER_ACCESS = gitlab.REPORTER_ACCESS
2689+
DEVELOPER_ACCESS = gitlab.DEVELOPER_ACCESS
2690+
MASTER_ACCESS = gitlab.MASTER_ACCESS
2691+
OWNER_ACCESS = gitlab.OWNER_ACCESS
2692+
2693+
VISIBILITY_PRIVATE = gitlab.VISIBILITY_PRIVATE
2694+
VISIBILITY_INTERNAL = gitlab.VISIBILITY_INTERNAL
2695+
VISIBILITY_PUBLIC = gitlab.VISIBILITY_PUBLIC
2696+
2697+
def transfer_project(self, id, **kwargs):
2698+
"""Transfers a project to this new groups.
2699+
2700+
Attrs:
2701+
id (int): ID of the project to transfer.
2702+
2703+
Raises:
2704+
GitlabConnectionError: If the server cannot be reached.
2705+
GitlabTransferProjectError: If the server fails to perform the
2706+
request.
2707+
"""
2708+
url = '/groups/%d/projects/%d' % (self.id, id)
2709+
r = self.gitlab._raw_post(url, None, **kwargs)
2710+
raise_error_from_response(r, GitlabTransferProjectError, 201)
2711+
2712+
2713+
class GroupManager(BaseManager):
2714+
obj_cls = Group
2715+
2716+
def search(self, query, **kwargs):
2717+
"""Searches groups by name.
2718+
2719+
Args:
2720+
query (str): The search string
2721+
all (bool): If True, return all the items, without pagination
2722+
2723+
Returns:
2724+
list(Group): a list of matching groups.
2725+
"""
2726+
url = '/groups?search=' + query
2727+
return self.gitlab._raw_list(url, self.obj_cls, **kwargs)
2728+
2729+
27272730
class TeamMemberManager(BaseManager):
27282731
obj_cls = TeamMember
27292732

0 commit comments

Comments
 (0)