From a80d89b6b077f29ca172c8dd8f0ddc9dd9ced4e8 Mon Sep 17 00:00:00 2001 From: Conor Branagan Date: Mon, 13 Jan 2014 16:31:35 +0000 Subject: [PATCH 1/4] Update requests requirement with API changes. --- pygithub3/core/client.py | 5 ++--- requirements/base.txt | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/pygithub3/core/client.py b/pygithub3/core/client.py index 139bee8..4d719e5 100644 --- a/pygithub3/core/client.py +++ b/pygithub3/core/client.py @@ -49,11 +49,10 @@ def set_credentials(self, login, password): def set_token(self, token): if token: - self.requester.params.append(('access_token', token)) + self.requester.params['access_token'] = token def __set_params(self, config): - per_page = ('per_page', config.get('per_page')) - self.requester.params.append(per_page) + self.requester.params['per_page'] = config.get('per_page') if config.get('verbose'): self.requester.config = {'verbose': config['verbose']} if config.get('timeout'): diff --git a/requirements/base.txt b/requirements/base.txt index 1ff0d4c..78a36b6 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -1 +1 @@ -requests==0.14.0 +requests>=2.0.0 From d2e2e39aca33d40bfaa742e33e07925fc0147c8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Kijewski?= Date: Sat, 5 Jul 2014 23:25:36 +0200 Subject: [PATCH 2/4] Easify list by (default) conditions I found that the current `pygithub3.services.issues.Issue.list_by_repo` implementations does not work. Overriding the default parameters did not seem to work for me. This PR removes the default parameters. The default parameters don't need to be passed. --- pygithub3/services/issues/__init__.py | 11 ++--------- pygithub3/services/issues/milestones.py | 6 ++---- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/pygithub3/services/issues/__init__.py b/pygithub3/services/issues/__init__.py index ca3aad8..1681e95 100644 --- a/pygithub3/services/issues/__init__.py +++ b/pygithub3/services/issues/__init__.py @@ -17,8 +17,7 @@ def __init__(self, **config): self.milestones = Milestones(**config) super(Issue, self).__init__(**config) - def list(self, filter='assigned', state='open', labels='', sort='created', - direction='desc', since=None): + def list(self, **params): """ List your issues :param str filter: 'assigned', 'created', 'mentioned' or 'subscribed' @@ -33,14 +32,10 @@ def list(self, filter='assigned', state='open', labels='', sort='created', .. warning:: You must be authenticated """ - params = dict(filter=filter, state=state, labels=labels, sort=sort, - direction=direction) request = self.request_builder('issues.list') return self._get_result(request, **params) - def list_by_repo(self, user=None, repo=None, milestone='*', state='open', - assignee='*', mentioned='', labels='', sort='created', - direction='desc', since=None): + def list_by_repo(self, user=None, repo=None, **params): """ List issues for a repo :param str milestone: Milestone ID, 'none' or '*' @@ -57,8 +52,6 @@ def list_by_repo(self, user=None, repo=None, milestone='*', state='open', .. note:: Remember :ref:`config precedence` """ - params = dict(milestone=milestone, state=state, assignee=assignee, - mentioned=mentioned, labels=labels, sort=sort, direction=direction) request = self.make_request('issues.list_by_repo', user=user, repo=repo) return self._get_result(request, **params) diff --git a/pygithub3/services/issues/milestones.py b/pygithub3/services/issues/milestones.py index 1126805..09cc4ba 100644 --- a/pygithub3/services/issues/milestones.py +++ b/pygithub3/services/issues/milestones.py @@ -8,8 +8,7 @@ class Milestones(Service): """ Consume `Milestones API `_ """ - def list(self, user=None, repo=None, state='open', sort='due_date', - direction='desc'): + def list(self, user=None, repo=None, **params): """ List milestones for a repo :param str user: Username @@ -24,8 +23,7 @@ def list(self, user=None, repo=None, state='open', sort='due_date', """ request = self.make_request('issues.milestones.list', user=user, repo=repo) - return self._get_result(request, state=state, sort=sort, - direction=direction) + return self._get_result(request, **params) def get(self, number, user=None, repo=None): """ Get a single milestone From 321385860cb2ecaea1221612682c20e8069768b0 Mon Sep 17 00:00:00 2001 From: David Medina Date: Fri, 28 Nov 2014 11:13:02 +0100 Subject: [PATCH 3/4] 0.5.1: Upload to Pypi --- pygithub3/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygithub3/__init__.py b/pygithub3/__init__.py index 461dabe..deff002 100644 --- a/pygithub3/__init__.py +++ b/pygithub3/__init__.py @@ -1,7 +1,7 @@ # -*- encoding: utf-8 -*- __title__ = 'pygithub3' -__version__ = '0.5' +__version__ = '0.5.1' __author__ = 'David Medina' __email__ = 'davidmedina9@gmail.com' __license__ = 'ISC' From dc9128ad5f2514f68cf4a1da15ea3b4f87ca8864 Mon Sep 17 00:00:00 2001 From: Abder Benbachir Date: Wed, 12 Oct 2016 13:27:46 -0400 Subject: [PATCH 4/4] fix #58 implement search feature for users --- .gitignore | 1 + AUTHORS.rst | 1 + pygithub3/github.py | 9 +++++++ pygithub3/requests/search/__init__.py | 3 +++ pygithub3/requests/search/search_users.py | 12 +++++++++ pygithub3/resources/search.py | 21 +++++++++++++++ pygithub3/services/search/__init__.py | 15 +++++++++++ pygithub3/services/search/search_users.py | 20 ++++++++++++++ pygithub3/tests/services/test_search.py | 33 +++++++++++++++++++++++ 9 files changed, 115 insertions(+) create mode 100644 pygithub3/requests/search/__init__.py create mode 100644 pygithub3/requests/search/search_users.py create mode 100644 pygithub3/resources/search.py create mode 100644 pygithub3/services/search/__init__.py create mode 100644 pygithub3/services/search/search_users.py create mode 100644 pygithub3/tests/services/test_search.py diff --git a/.gitignore b/.gitignore index f0c73ea..24d3122 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ docs/_build dist/ build/ *egg-info +.idea/ diff --git a/AUTHORS.rst b/AUTHORS.rst index ac8946c..b3e74dd 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -31,3 +31,4 @@ Patches and Suggestions - Ralph Bean - Jason A. Donenfeld - Brad Montgomery +- Abderrahmane Benbachir diff --git a/pygithub3/github.py b/pygithub3/github.py index d64577c..432af21 100644 --- a/pygithub3/github.py +++ b/pygithub3/github.py @@ -22,6 +22,7 @@ def __init__(self, **config): from pygithub3.services.pull_requests import PullRequests from pygithub3.services.orgs import Org from pygithub3.services.issues import Issue + from pygithub3.services.search import Search self._users = User(**config) self._repos = Repo(**config) self._gists = Gist(**config) @@ -30,6 +31,7 @@ def __init__(self, **config): self._orgs = Org(**config) self._issues = Issue(**config) self._events = Event(**config) + self._search = Search(**config) @property def remaining_requests(self): @@ -92,3 +94,10 @@ def events(self): :ref:`Events service ` """ return self._events + + @property + def search(self): + """ + :ref:`Search service ` + """ + return self._search diff --git a/pygithub3/requests/search/__init__.py b/pygithub3/requests/search/__init__.py new file mode 100644 index 0000000..1b9a6f7 --- /dev/null +++ b/pygithub3/requests/search/__init__.py @@ -0,0 +1,3 @@ +# -*- encoding: utf-8 -*- + +from pygithub3.requests.base import Request, ValidationError \ No newline at end of file diff --git a/pygithub3/requests/search/search_users.py b/pygithub3/requests/search/search_users.py new file mode 100644 index 0000000..a84f174 --- /dev/null +++ b/pygithub3/requests/search/search_users.py @@ -0,0 +1,12 @@ +#!/usr/bin/env python +# -*- encoding: utf-8 -*- + +from . import Request +from pygithub3.resources.search import SearchUsers + + +class List(Request): + + resource = SearchUsers + uri = 'search/users' + diff --git a/pygithub3/resources/search.py b/pygithub3/resources/search.py new file mode 100644 index 0000000..1603467 --- /dev/null +++ b/pygithub3/resources/search.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python +# -*- encoding: utf-8 -*- + +from .base import Resource +from .users import User + +__all__ = ('SearchUsers', 'SearchIssues') + + +class SearchUsers(Resource): + _maps = {'user': User} + def __str__(self): + return '' % getattr(self, 'login', '') + + +class SearchIssues(Resource): + + def __str__(self): + return '' % getattr(self, 'title', '') + + diff --git a/pygithub3/services/search/__init__.py b/pygithub3/services/search/__init__.py new file mode 100644 index 0000000..c3acb73 --- /dev/null +++ b/pygithub3/services/search/__init__.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python +# -*- encoding: utf-8 -*- + +from pygithub3.services.base import Service +from .search_users import SearchUsers + + +class Search(Service): + """ Consume `Users API `_ """ + + def __init__(self, **config): + super(Search, self).__init__(**config) + self.search_users = SearchUsers(**config) + + diff --git a/pygithub3/services/search/search_users.py b/pygithub3/services/search/search_users.py new file mode 100644 index 0000000..e7de6cf --- /dev/null +++ b/pygithub3/services/search/search_users.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python +# -*- encoding: utf-8 -*- + +from pygithub3.services.base import Service +from pprint import pprint + +class SearchUsers(Service): + """ Consume `Followers API + `_ + """ + + def list(self, query=None, sort=None, order=None): + + request = self.request_builder('search.search_users.list', query=query, sort=sort, order=order) + + return self._get(request, q=query) + + + + diff --git a/pygithub3/tests/services/test_search.py b/pygithub3/tests/services/test_search.py new file mode 100644 index 0000000..6ab4fb3 --- /dev/null +++ b/pygithub3/tests/services/test_search.py @@ -0,0 +1,33 @@ +# -*- encoding: utf-8 -*- + +import requests +from pprint import pprint +from mock import patch + +from pygithub3.core.client import Client +from pygithub3.exceptions import ValidationError +from pygithub3.services.search.search_users import SearchUsers +from pygithub3.tests.utils.base import (dummy_json, mock_response, + mock_response_result) +from pygithub3.tests.utils.core import TestCase +from pygithub3.tests.utils.services import _ + + +@dummy_json +@patch.object(requests.sessions.Session, 'request') +class TestSearchUsersService(TestCase): + + def setUp(self): + self.search_users = SearchUsers() + + # def test_GET_without_user(self, request_method): + # request_method.return_value = mock_response() + # self.us.get() + # self.assertEqual(request_method.call_args[0], ('get', _('user'))) + + def test_GET_LIST(self, request_method): + request_method.return_value = mock_response() + result = self.search_users.list(query='abder') + # self.assertEqual(request_method.call_args[0], ('get', _('users/octocat'))) + +