From 689ecae70585e79c281224162a0ba2ab3921242a Mon Sep 17 00:00:00 2001 From: Gauvain Pocentek Date: Fri, 8 Jan 2016 22:35:30 +0100 Subject: Implement ProjectManager search/list methods The existing Gitlab methods are deprecated. Unit tests have been added. --- gitlab/objects.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'gitlab/objects.py') diff --git a/gitlab/objects.py b/gitlab/objects.py index 3637fe8..aaaadbb 100644 --- a/gitlab/objects.py +++ b/gitlab/objects.py @@ -1016,6 +1016,33 @@ 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) + + def all(self, **kwargs): + """Lists all the projects (need admin rights).""" + return self._custom_list("/projects/all", **kwargs) + + def owned(self, **kwargs): + """Lists owned projects.""" + return self._custom_list("/projects/owned", **kwargs) + class UserProjectManager(BaseManager): obj_cls = UserProject -- cgit v1.2.1