Skip to content

Commit 8b7ccd2

Browse files
authored
feat: increase result per page for prs issues listings (#102)
1 parent 5801c85 commit 8b7ccd2

File tree

5 files changed

+151
-131
lines changed

5 files changed

+151
-131
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
.python-version .venv/ __pycache__/
1+
.python-version .venv/ __pycache__/ build/ mcp_github_pr_issue_analyser.egg-info/

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "mcp-github-pr-issue-analyser"
3-
version = "2.6.2"
3+
version = "2.7.0"
44
description = "MCP GitHub Issues Create/Update and PR Analyse"
55
readme = "README.md"
66
requires-python = ">=3.12"

src/mcp_github/github_integration.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
import requests
2222
import traceback
2323
from os import getenv
24-
from typing import Dict, Any, Optional, Literal
24+
from pydantic import BaseModel, conint
25+
from typing import Annotated, Any, Dict, Optional, Literal
2526

2627
GITHUB_TOKEN = getenv('GITHUB_TOKEN')
2728

@@ -30,6 +31,8 @@
3031
logging.basicConfig(level=logging.WARNING)
3132

3233
class GitHubIntegration:
34+
PerPage = conint(ge=1, le=100)
35+
3336
def __init__(self):
3437
"""
3538
Initialise the GitHubIntegration class.
@@ -267,13 +270,22 @@ def update_pr_description(self, repo_owner: str, repo_name: str, pr_number: int,
267270
traceback.print_exc()
268271
return None
269272

270-
def list_open_issues_prs(self, repo_owner: str, issue: Literal['pr', 'issue'] = 'pr', filtering: Literal['user', 'owner', 'involves'] = 'involves') -> Dict[str, Any]:
273+
def list_open_issues_prs(
274+
self,
275+
repo_owner: str,
276+
issue: Literal['pr', 'issue'] = 'pr',
277+
filtering: Literal['user', 'owner', 'involves'] = 'involves',
278+
per_page: Annotated[PerPage, "Number of results per page (1-100)"] = 50,
279+
page: int = 1
280+
) -> Dict[str, Any]:
271281
"""
272282
Lists all open Issues or Pull Requests for a given repository owner.
273283
Args:
274284
repo_owner (str): The owner of the repository.
275285
issue (Literal['pr', 'issue']): The type of items to list, either 'pr' for pull requests or 'issue' for issues. Defaults to 'pr'.
276286
filtering (Literal['user', 'owner', 'involves']): The filtering criteria for the search. Defaults to 'involves'.
287+
per_page (Annotated[int, PerPage]): The number of results to return per page, range 1-100. Defaults to 50.
288+
page (int): The page number to retrieve. Defaults to 1.
277289
Returns:
278290
Dict[str, Any]: A dictionary containing the list of open pull requests or issues, depending on the value of the `issue` parameter.
279291
None: If an error occurs during the request.
@@ -283,7 +295,7 @@ def list_open_issues_prs(self, repo_owner: str, issue: Literal['pr', 'issue'] =
283295
logging.info(f"Listing open {issue}s for {repo_owner}")
284296

285297
# Construct the search URL
286-
search_url = f"https://api.github.com/search/issues?q=is:{issue}+is:open+{filtering}:{repo_owner}"
298+
search_url = f"https://api.github.com/search/issues?q=is:{issue}+is:open+{filtering}:{repo_owner}&per_page={per_page}&page={page}"
287299

288300
try:
289301
response = requests.get(search_url, headers=self._get_headers())

src/mcp_github/issues_pr_analyser.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import logging
2222
import traceback
2323
from os import getenv
24-
from typing import Any, Dict, List, Literal
24+
from typing import Annotated, Any, Dict, List, Literal
2525
from mcp.server.fastmcp import FastMCP
2626
from .github_integration import GitHubIntegration as GI
2727
from .ip_integration import IPIntegration as IP
@@ -210,7 +210,13 @@ async def add_github_pr_comment(repo_owner: str, repo_name: str, pr_number: int,
210210
return {"status": "error", "message": error_msg}
211211

212212
@self.mcp.tool()
213-
async def list_github_issues_prs(repo_owner: str, issue: Literal['pr', 'issue'] = 'pr', filtering: Literal['user', 'owner', 'involves'] = 'involves') -> dict[str, Any]:
213+
async def list_github_issues_prs(
214+
repo_owner: str,
215+
issue: Literal['pr', 'issue'] = 'pr',
216+
filtering: Literal['user', 'owner', 'involves'] = 'involves',
217+
per_page: Annotated[GI.PerPage, "Number of results per page (1-100)"] = 50,
218+
page: int = 1
219+
) -> dict[str, Any]: # type: ignore
214220
"""
215221
Lists open issues or pull requests for a specified GitHub repository.
216222
- Present the issues or pull requests in a markdown table format.
@@ -219,13 +225,15 @@ async def list_github_issues_prs(repo_owner: str, issue: Literal['pr', 'issue']
219225
repo_owner (str): The owner of the GitHub repository.
220226
issue (Literal['pr', 'issue']): The type of item to list, either 'pr' for pull requests or 'issue' for issues. Defaults to 'pr'.
221227
filtering (Literal['user', 'owner', 'involves']): The filtering criteria for the search. Defaults to 'involves'.
228+
per_page (Annotated[PerPage, "Number of results per page (1-100)"]): The number of results to return per page, range 1-100. Defaults to 50.
229+
page (int): The page number to retrieve. Defaults to 1.
222230
Returns:
223-
dict[str, Any]: A dictionary containing the list of open issues or pull requests.
224-
Returns an error message if an exception occurs during the listing process.
231+
dict[str, Any]: A dictionary containing the list of open issues or pull requests.
232+
Returns an error message if an exception occurs during the listing process.
225233
"""
226234
logging.info({"status": "info", "message": f"Listing open {issue} for {repo_owner}"})
227235
try:
228-
open_issues_prs = self.gi.list_open_issues_prs(repo_owner, issue, filtering)
236+
open_issues_prs = self.gi.list_open_issues_prs(repo_owner, issue, filtering, per_page=per_page, page=page)
229237
return open_issues_prs
230238
except Exception as e:
231239
error_msg = f"Error listing {issue} for {repo_owner}: {str(e)}"

0 commit comments

Comments
 (0)