diff options
author | Gauvain Pocentek <gauvain.pocentek@objectif-libre.com> | 2016-01-09 08:36:18 +0100 |
---|---|---|
committer | Gauvain Pocentek <gauvain.pocentek@objectif-libre.com> | 2016-01-09 08:36:18 +0100 |
commit | 5513d0f52cd488b14c94389a09d01877fa5596e0 (patch) | |
tree | 4e8dab28f2c95e8214cfc1a4d4d39f1e4295007d /gitlab/objects.py | |
parent | 0ae315a4d1d154122208883bd006b2b882cb5113 (diff) | |
download | gitlab-5513d0f52cd488b14c94389a09d01877fa5596e0.tar.gz |
Add support for groups search
Factorize the code to avoid duplication with the ProjectManager class.
Implement unit tests for the group search.
Original patchh from Daniel Serodio (PR #55).
Diffstat (limited to 'gitlab/objects.py')
-rw-r--r-- | gitlab/objects.py | 39 |
1 files changed, 24 insertions, 15 deletions
diff --git a/gitlab/objects.py b/gitlab/objects.py index aaaadbb..ccd4f0a 100644 --- a/gitlab/objects.py +++ b/gitlab/objects.py @@ -70,6 +70,18 @@ class BaseManager(object): raise NotImplementedError return self.obj_cls.create(self.gitlab, data, **kwargs) + def _custom_list(self, url, cls, **kwargs): + r = self.gitlab._raw_get(url, **kwargs) + raise_error_from_response(r, GitlabListError) + + l = [] + for j in r.json(): + o = cls(self, j) + o._from_api = True + l.append(o) + + return l + class GitlabObject(object): """Base class for all classes that interface with GitLab @@ -433,6 +445,14 @@ class Group(GitlabObject): class GroupManager(BaseManager): obj_cls = Group + def search(self, query, **kwargs): + """Searches groups by name. + + Returns a list of matching groups. + """ + url = '/groups?search=' + query + return self._custom_list(url, Group, **kwargs) + class Hook(GitlabObject): _url = '/hooks' @@ -1016,32 +1036,21 @@ class UserProject(GitlabObject): class ProjectManager(BaseManager): obj_cls = Project - def _custom_list(self, url, **kwargs): - r = self.gitlab._raw_get(url, **kwargs) - raise_error_from_response(r, GitlabListError) - - l = [] - for o in r.json(): - p = Project(self, o) - p._from_api = True - l.append(p) - - return l - def search(self, query, **kwargs): """Searches projects by name. Returns a list of matching projects. """ - return self._custom_list("/projects/search/" + query, **kwargs) + return self._custom_list("/projects/search/" + query, Project, + **kwargs) def all(self, **kwargs): """Lists all the projects (need admin rights).""" - return self._custom_list("/projects/all", **kwargs) + return self._custom_list("/projects/all", Project, **kwargs) def owned(self, **kwargs): """Lists owned projects.""" - return self._custom_list("/projects/owned", **kwargs) + return self._custom_list("/projects/owned", Project, **kwargs) class UserProjectManager(BaseManager): |