Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support per_page search parameter #1167

Merged
merged 2 commits into from
Nov 18, 2023
Merged
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
2 changes: 2 additions & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -222,3 +222,5 @@ Contributors
- Andrew MacCormack (@amaccormack-lumira)

- Chris R (@offbyone)

- Chris Cotter (@ccotter)
15 changes: 15 additions & 0 deletions src/github3/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -2248,6 +2248,9 @@ def search_code(
if sort and order in ("asc", "desc"):
params["order"] = order

if per_page is not None:
params["per_page"] = per_page

if text_match:
headers = {
"Accept": "application/vnd.github.v3.full.text-match+json"
Expand Down Expand Up @@ -2335,6 +2338,9 @@ def search_commits(
if sort and order in ("asc", "desc"):
params["order"] = order

if per_page is not None:
params["per_page"] = per_page

if text_match:
headers["Accept"] = ", ".join(
[
Expand Down Expand Up @@ -2427,6 +2433,9 @@ def search_issues(
if order in ("asc", "desc"):
params["order"] = order

if per_page is not None:
params["per_page"] = per_page

if text_match:
headers = {
"Accept": "application/vnd.github.v3.full.text-match+json"
Expand Down Expand Up @@ -2505,6 +2514,9 @@ def search_repositories(
if order in ("asc", "desc"):
params["order"] = order

if per_page is not None:
params["per_page"] = per_page

if text_match:
headers = {
"Accept": "application/vnd.github.v3.full.text-match+json"
Expand Down Expand Up @@ -2588,6 +2600,9 @@ def search_users(
if order in ("asc", "desc"):
params["order"] = order

if per_page is not None:
params["per_page"] = per_page

if text_match:
headers = {
"Accept": "application/vnd.github.v3.full.text-match+json"
Expand Down
30 changes: 23 additions & 7 deletions tests/unit/test_github.py
Original file line number Diff line number Diff line change
Expand Up @@ -1317,21 +1317,34 @@ class TestGitHubSearchIterators(helper.UnitSearchIteratorHelper):
def test_search_code(self):
"""Verify the request to search for code."""
i = self.instance.search_code(
"addClass in:file language:js repo:jquery/jquery"
"addClass in:file language:js repo:jquery/jquery", per_page=15
)
self.get_next(i)

self.session.get.assert_called_once_with(
url_for("search/code"),
params={
"per_page": 100,
"per_page": 15,
"q": "addClass in:file language:js repo:jquery/jquery",
},
headers={},
)

def test_search_commits(self):
"""Verify the request to search for commits."""
i = self.instance.search_commits(
"css repo:octocat/Spoon-Knife", per_page=15
)
self.get_next(i)

self.session.get.assert_called_once_with(
url_for("search/commits"),
params={"per_page": 15, "q": "css repo:octocat/Spoon-Knife"},
headers={"Accept": "application/vnd.github.cloak-preview"},
)

def test_search_commits_default_per_page(self):
"""Verify the default per_page in the commits search."""
i = self.instance.search_commits("css repo:octocat/Spoon-Knife")
self.get_next(i)

Expand All @@ -1347,14 +1360,15 @@ def test_search_issues(self):
"windows label:bug language:python state:open",
sort="created",
order="asc",
per_page=15,
)
self.get_next(i)

self.session.get.assert_called_once_with(
url_for("search/issues"),
params={
"order": "asc",
"per_page": 100,
"per_page": 15,
"q": "windows label:bug language:python state:open",
"sort": "created",
},
Expand All @@ -1364,15 +1378,15 @@ def test_search_issues(self):
def test_search_repositories(self):
"""Verify the request to search for repositories."""
i = self.instance.search_repositories(
"tetris language:assembly", sort="stars", order="asc"
"tetris language:assembly", sort="stars", order="asc", per_page=15
)
self.get_next(i)

self.session.get.assert_called_once_with(
url_for("search/repositories"),
params={
"order": "asc",
"per_page": 100,
"per_page": 15,
"q": "tetris language:assembly",
"sort": "stars",
},
Expand All @@ -1381,12 +1395,14 @@ def test_search_repositories(self):

def test_search_users(self):
"""Verify the request to search for users."""
i = self.instance.search_users("tom repos:>42 followers:>1000")
i = self.instance.search_users(
"tom repos:>42 followers:>1000", per_page=15
)
self.get_next(i)

self.session.get.assert_called_once_with(
url_for("search/users"),
params={"per_page": 100, "q": "tom repos:>42 followers:>1000"},
params={"per_page": 15, "q": "tom repos:>42 followers:>1000"},
headers={},
)

Expand Down
Loading