Skip to content
This repository has been archived by the owner on Oct 24, 2022. It is now read-only.

Add pull-request list ordering options #52

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ docs/_build
dist/
build/
*egg-info
.idea
15 changes: 12 additions & 3 deletions pygithub3/services/pull_requests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
14 changes: 14 additions & 0 deletions pygithub3/tests/services/test_pull_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down