From 40c3a6f1bb74eec8967147a45d3a91bdbe108a33 Mon Sep 17 00:00:00 2001 From: Greg Hill Date: Wed, 9 Dec 2015 07:22:38 -0600 Subject: [PATCH] Add pull-request list ordering options This adds 'sort' and 'direction' options to the pull-request list method as kwargs. If they aren't passed, default values are assumed by the API. See github API docs for more info. --- .gitignore | 1 + pygithub3/services/pull_requests/__init__.py | 15 ++++++++++++--- pygithub3/tests/services/test_pull_requests.py | 14 ++++++++++++++ 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index f0c73ea..b77eacb 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ docs/_build dist/ build/ *egg-info +.idea diff --git a/pygithub3/services/pull_requests/__init__.py b/pygithub3/services/pull_requests/__init__.py index 49c1939..d40d647 100644 --- a/pygithub3/services/pull_requests/__init__.py +++ b/pygithub3/services/pull_requests/__init__.py @@ -11,20 +11,29 @@ def __init__(self, **config): self.comments = Comments(**config) super(PullRequests, self).__init__(**config) - def list(self, state='open', user=None, repo=None): + def list(self, state='open', user=None, repo=None, sort=None, direction=None): """List all of the pull requests for a repo - :param str state: Pull requests state ('open' or 'closed') + :param str state: Pull requests state ('open', 'closed', or 'all') :param str user: Username :param str repo: Repository + :param str sort: 'created', 'updated' or 'comments' + :param str direction: 'asc' or 'desc' :returns: A :doc:`result` .. note:: Remember :ref:`config precedence` """ + kwargs = {} + if sort is not None: + kwargs['sort'] = sort + if direction is not None: + kwargs['direction'] = direction + return self._get_result( self.make_request('pull_requests.list', user=user, repo=repo), - state=state + state=state, + **kwargs ) def get(self, number, user=None, repo=None): diff --git a/pygithub3/tests/services/test_pull_requests.py b/pygithub3/tests/services/test_pull_requests.py index 83a1202..6090397 100644 --- a/pygithub3/tests/services/test_pull_requests.py +++ b/pygithub3/tests/services/test_pull_requests.py @@ -26,6 +26,20 @@ def test_LIST(self, reqm): ('get', _('repos/user/repo/pulls')) ) + def test_LIST_ordered(self, reqm): + reqm.return_value = mock_response_result() + order_args = dict(sort='updated', direction='desc') + self.service.list(**order_args).all() + + self.assertEqual( + reqm.call_args[0], + ('get', _('repos/user/repo/pulls')) + ) + + params = reqm.call_args[1]['params'] + for key, value in order_args.iteritems(): + self.assertEqual(params[key], value) + def test_GET(self, reqm): reqm.return_value = mock_response() self.service.get(123)