diff options
author | Gauvain Pocentek <gauvain@pocentek.net> | 2018-05-21 16:21:48 +0200 |
---|---|---|
committer | Gauvain Pocentek <gauvain@pocentek.net> | 2018-05-21 16:21:48 +0200 |
commit | 97c8619c5b07abc714417d6e5be2f553270b54a6 (patch) | |
tree | ff7ac748615cf0a2b18eedd9c789b8eaf0396263 /gitlab/v4/objects.py | |
parent | b5f9616f21b7dcdf166033d0dba09b3dd2289849 (diff) | |
download | gitlab-97c8619c5b07abc714417d6e5be2f553270b54a6.tar.gz |
Add support for the search API
Fixes #470
Diffstat (limited to 'gitlab/v4/objects.py')
-rw-r--r-- | gitlab/v4/objects.py | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/gitlab/v4/objects.py b/gitlab/v4/objects.py index ac25f1e..6f40dc8 100644 --- a/gitlab/v4/objects.py +++ b/gitlab/v4/objects.py @@ -713,6 +713,27 @@ class Group(SaveMixin, ObjectDeleteMixin, RESTObject): path = '/groups/%d/projects/%d' % (self.id, to_project_id) self.manager.gitlab.http_post(path, **kwargs) + @cli.register_custom_action('Group', ('scope', 'search')) + @exc.on_http_error(exc.GitlabSearchError) + def search(self, scope, search, **kwargs): + """Search the group resources matching the provided string.' + + Args: + scope (str): Scope of the search + search (str): Search string + **kwargs: Extra options to send to the server (e.g. sudo) + + Raises: + GitlabAuthenticationError: If authentication is not correct + GitlabSearchError: If the server failed to perform the request + + Returns: + GitlabList: A list of dicts describing the resources found. + """ + data = {'scope': scope, 'search': search} + path = '/groups/%d/search' % self.get_id() + return self.manager.gitlab.http_list(path, query_data=data, **kwargs) + class GroupManager(CRUDMixin, RESTManager): _path = '/groups' @@ -2867,6 +2888,27 @@ class Project(SaveMixin, ObjectDeleteMixin, RESTObject): "markdown": data['markdown'] } + @cli.register_custom_action('Project', ('scope', 'search')) + @exc.on_http_error(exc.GitlabSearchError) + def search(self, scope, search, **kwargs): + """Search the project resources matching the provided string.' + + Args: + scope (str): Scope of the search + search (str): Search string + **kwargs: Extra options to send to the server (e.g. sudo) + + Raises: + GitlabAuthenticationError: If authentication is not correct + GitlabSearchError: If the server failed to perform the request + + Returns: + GitlabList: A list of dicts describing the resources found. + """ + data = {'scope': scope, 'search': search} + path = '/projects/%d/search' % self.get_id() + return self.manager.gitlab.http_list(path, query_data=data, **kwargs) + class ProjectManager(CRUDMixin, RESTManager): _path = '/projects' |