Skip to content

Commit 307d736

Browse files
committed
Merge branch 'feat/page_support'
Closes ask#66. * feat/page_support: Added tests/examples for paged request results. Added warning for unpageable requests. Add `page` parameter for objects supporting a list.
2 parents 00e2ce5 + ab8ec7d commit 307d736

15 files changed

Lines changed: 124 additions & 12 deletions

doc/api/commit.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ Listing Commits on a Branch
2121

2222
>>> commits = github.commits.list("mojombo/grit", "master")
2323

24+
By default the first page of results is returned, you can return further results
25+
with the ``page`` parameter:
26+
27+
>>> commits = github.commits.list("mojombo/grit", "master", page=2)
2428

2529
Listing Commits for a File
2630
''''''''''''''''''''''''''

doc/api/pull_requests.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ Listing pull requests
1919

2020
>>> results = github.pull_requests.list("ask/python-github2")
2121

22+
By default the first page of results is returned, you can return further results
23+
with the ``page`` parameter:
24+
25+
>>> results = github.pull_requests.list("ask/python-github2", page=2)
26+
2227
View a pull request
2328
'''''''''''''''''''
2429

doc/api/repos.rst

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,13 @@ Show Repo Info
3232
List All Repositories
3333
'''''''''''''''''''''
3434

35-
# By default lists all repos for the current user.
36-
>>> repos = github.repos.list()
37-
3835
>>> repos = github.repos.list("schacon")
3936

37+
By default the first page of results is returned, you can return further results
38+
with the ``page`` parameter:
39+
40+
>>> repos = github.repos.list("schacon", page=2)
41+
4042
Watching Repositories
4143
'''''''''''''''''''''
4244

github2/commits.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def __repr__(self):
2727
class Commits(GithubCommand):
2828
domain = "commits"
2929

30-
def list(self, project, branch="master", file=None):
30+
def list(self, project, branch="master", file=None, page=1):
3131
"""List commits on a project
3232
3333
.. warning::
@@ -38,9 +38,10 @@ def list(self, project, branch="master", file=None):
3838
:param str project: project name
3939
:param str branch: branch name, or ``master`` if not given
4040
:param str file: optional file filter
41+
:param int page: optional page number
4142
"""
42-
return self.get_values("list", project, branch, file,
43-
filter="commits", datatype=Commit)
43+
return self.get_values("list", project, branch, file, filter="commits",
44+
datatype=Commit, page=page)
4445

4546
def show(self, project, sha):
4647
"""Get a specific commit

github2/core.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ def __init__(self, request):
135135
def make_request(self, command, *args, **kwargs):
136136
filter = kwargs.get("filter")
137137
post_data = kwargs.get("post_data") or {}
138+
page = kwargs.pop("page", 1)
139+
if page and not page == 1:
140+
post_data["page"] = page
138141
method = kwargs.get("method", "GET")
139142
if method.upper() == "POST" or method.upper() == "GET" and post_data:
140143
response = self.request.post(self.domain, command, *args,

github2/pull_requests.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,12 @@ def show(self, project, number):
8484
return self.get_value(project, str(number), filter="pull",
8585
datatype=PullRequest)
8686

87-
def list(self, project, state="open"):
87+
def list(self, project, state="open", page=1):
8888
"""List all pull requests for a project
8989
9090
:param str project: Github project
9191
:param str state: can be either ``open`` or ``closed``
92+
:param int page: optional page number
9293
"""
9394
return self.get_values(project, state, filter="pulls",
94-
datatype=PullRequest)
95+
datatype=PullRequest, page=page)

github2/repositories.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ class Repositories(GithubCommand):
3939
def search(self, query):
4040
"""Get all repositories that match term.
4141
42+
.. warning:
43+
Returns at most 100 repositories
44+
4245
:param str query: term to search issues for
4346
"""
4447
return self.get_values("search", query, filter="repositories",
@@ -62,7 +65,7 @@ def pushable(self):
6265
datatype=Repository)
6366

6467

65-
def list(self, user=None):
68+
def list(self, user=None, page=1):
6669
"""Return a list of all repositories for a user.
6770
6871
.. deprecated: 0.4.0
@@ -71,10 +74,11 @@ def list(self, user=None):
7174
brittle and will be removed in a future release!
7275
7376
:param str user: Github user name to list repositories for
77+
:param int page: optional page number
7478
"""
7579
user = user or self.request.username
7680
return self.get_values("show", user, filter="repositories",
77-
datatype=Repository)
81+
datatype=Repository, page=page)
7882

7983
@requires_auth
8084
def watch(self, project):
@@ -208,14 +212,15 @@ def watchers(self, project):
208212
"""
209213
return self.get_values("show", project, "watchers", filter="watchers")
210214

211-
def watching(self, for_user=None):
215+
def watching(self, for_user=None, page=None):
212216
"""Lists all the repos a user is watching
213217
214218
:param str for_user: optional Github user name to list repositories for
219+
:param int page: optional page number
215220
"""
216221
for_user = for_user or self.request.username
217222
return self.get_values("watched", for_user, filter="repositories",
218-
datatype=Repository)
223+
datatype=Repository, page=page)
219224

220225
def list_contributors(self, project):
221226
"""Lists all the contributors in a project

github2/users.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ class Users(GithubCommand):
4343
def search(self, query):
4444
"""Search for users
4545
46+
.. warning:
47+
Returns at most 100 users
48+
4649
:param str query: term to search for
4750
"""
4851
return self.get_values("search", urllib.quote_plus(query),

tests/data/github.com,api,v2,json,commits,list,JNRowe,jnrowe-misc,master,a252487bd992cdfc8247b3c41d0cb9fa

Lines changed: 18 additions & 0 deletions
Large diffs are not rendered by default.

tests/data/github.com,api,v2,json,pulls,robbyrussell,oh-my-zsh,open,b0f946d4b280dcc6f7b65dd7fddeea6b

Lines changed: 16 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)