@@ -70,6 +70,18 @@ def create(self, data, **kwargs):
70
70
raise NotImplementedError
71
71
return self .obj_cls .create (self .gitlab , data , ** kwargs )
72
72
73
+ def _custom_list (self , url , cls , ** kwargs ):
74
+ r = self .gitlab ._raw_get (url , ** kwargs )
75
+ raise_error_from_response (r , GitlabListError )
76
+
77
+ l = []
78
+ for j in r .json ():
79
+ o = cls (self , j )
80
+ o ._from_api = True
81
+ l .append (o )
82
+
83
+ return l
84
+
73
85
74
86
class GitlabObject (object ):
75
87
"""Base class for all classes that interface with GitLab
@@ -433,6 +445,14 @@ def transfer_project(self, id, **kwargs):
433
445
class GroupManager (BaseManager ):
434
446
obj_cls = Group
435
447
448
+ def search (self , query , ** kwargs ):
449
+ """Searches groups by name.
450
+
451
+ Returns a list of matching groups.
452
+ """
453
+ url = '/groups?search=' + query
454
+ return self ._custom_list (url , Group , ** kwargs )
455
+
436
456
437
457
class Hook (GitlabObject ):
438
458
_url = '/hooks'
@@ -1016,32 +1036,21 @@ class UserProject(GitlabObject):
1016
1036
class ProjectManager (BaseManager ):
1017
1037
obj_cls = Project
1018
1038
1019
- def _custom_list (self , url , ** kwargs ):
1020
- r = self .gitlab ._raw_get (url , ** kwargs )
1021
- raise_error_from_response (r , GitlabListError )
1022
-
1023
- l = []
1024
- for o in r .json ():
1025
- p = Project (self , o )
1026
- p ._from_api = True
1027
- l .append (p )
1028
-
1029
- return l
1030
-
1031
1039
def search (self , query , ** kwargs ):
1032
1040
"""Searches projects by name.
1033
1041
1034
1042
Returns a list of matching projects.
1035
1043
"""
1036
- return self ._custom_list ("/projects/search/" + query , ** kwargs )
1044
+ return self ._custom_list ("/projects/search/" + query , Project ,
1045
+ ** kwargs )
1037
1046
1038
1047
def all (self , ** kwargs ):
1039
1048
"""Lists all the projects (need admin rights)."""
1040
- return self ._custom_list ("/projects/all" , ** kwargs )
1049
+ return self ._custom_list ("/projects/all" , Project , ** kwargs )
1041
1050
1042
1051
def owned (self , ** kwargs ):
1043
1052
"""Lists owned projects."""
1044
- return self ._custom_list ("/projects/owned" , ** kwargs )
1053
+ return self ._custom_list ("/projects/owned" , Project , ** kwargs )
1045
1054
1046
1055
1047
1056
class UserProjectManager (BaseManager ):
0 commit comments