Repository: sigmavirus24/github3.py

Issue:
per_page not respected in search_issues.py
The docs specify `per_page` is a supported parameter to `search_issues`, but the parameter isn't actually forwarded to the query `params`. Is this intentional, or a small oversight?

Discussion:

Patch:
diff --git a/AUTHORS.rst b/AUTHORS.rst
index 841a0b85..80598277 100644
--- a/AUTHORS.rst
+++ b/AUTHORS.rst
@@ -222,3 +222,5 @@ Contributors
 - Andrew MacCormack (@amaccormack-lumira)
 
 - Chris R (@offbyone)
+
+- Chris Cotter (@ccotter)
diff --git a/src/github3/github.py b/src/github3/github.py
index ac38cfb8..c759b021 100644
--- a/src/github3/github.py
+++ b/src/github3/github.py
@@ -2248,6 +2248,9 @@ class GitHub(models.GitHubCore):
         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"
@@ -2335,6 +2338,9 @@ class GitHub(models.GitHubCore):
         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(
                 [
@@ -2427,6 +2433,9 @@ class GitHub(models.GitHubCore):
         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"
@@ -2505,6 +2514,9 @@ class GitHub(models.GitHubCore):
         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"
@@ -2588,6 +2600,9 @@ class GitHub(models.GitHubCore):
         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"


Test patch:
diff --git a/tests/unit/test_github.py b/tests/unit/test_github.py
index c1e90c0c..dab91fb4 100644
--- a/tests/unit/test_github.py
+++ b/tests/unit/test_github.py
@@ -1317,14 +1317,14 @@ 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={},
@@ -1332,6 +1332,19 @@ class TestGitHubSearchIterators(helper.UnitSearchIteratorHelper):
 
     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)
 
@@ -1347,6 +1360,7 @@ class TestGitHubSearchIterators(helper.UnitSearchIteratorHelper):
             "windows label:bug language:python state:open",
             sort="created",
             order="asc",
+            per_page=15,
         )
         self.get_next(i)
 
@@ -1354,7 +1368,7 @@ class TestGitHubSearchIterators(helper.UnitSearchIteratorHelper):
             url_for("search/issues"),
             params={
                 "order": "asc",
-                "per_page": 100,
+                "per_page": 15,
                 "q": "windows label:bug language:python state:open",
                 "sort": "created",
             },
@@ -1364,7 +1378,7 @@ class TestGitHubSearchIterators(helper.UnitSearchIteratorHelper):
     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)
 
@@ -1372,7 +1386,7 @@ class TestGitHubSearchIterators(helper.UnitSearchIteratorHelper):
             url_for("search/repositories"),
             params={
                 "order": "asc",
-                "per_page": 100,
+                "per_page": 15,
                 "q": "tetris language:assembly",
                 "sort": "stars",
             },
@@ -1381,12 +1395,14 @@ class TestGitHubSearchIterators(helper.UnitSearchIteratorHelper):
 
     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={},
         )