Skip to content

Commit 2dd9fb3

Browse files
authored
feat: Add filtering option to list_open_issues_prs and improve type hints (#83)
* feat(github): add filtering option to list_open_issues_prs method Add filtering parameter to list_open_issues_prs to support 'user', 'owner', or 'involves' filters. Update corresponding tool in PRIssueAnalyser to accept and pass the filtering argument. Bump version to 2.6.0. * chore: func signature issue set to literal Function signature - suggest keeping Literal type for better hints
1 parent 89470af commit 2dd9fb3

File tree

4 files changed

+251
-249
lines changed

4 files changed

+251
-249
lines changed

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.5.1"
3+
version = "2.6.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: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,12 +267,13 @@ def update_pr_description(self, repo_owner: str, repo_name: str, pr_number: int,
267267
traceback.print_exc()
268268
return None
269269

270-
def list_open_issues_prs(self, repo_owner: str, issue: Literal['pr', 'issue'] = 'pr') -> Dict[str, Any]:
270+
def list_open_issues_prs(self, repo_owner: str, issue: Literal['pr', 'issue'] = 'pr', filtering: Literal['user', 'owner', 'involves'] = 'involves') -> Dict[str, Any]:
271271
"""
272272
Lists all open Issues or Pull Requests for a given repository owner.
273273
Args:
274274
repo_owner (str): The owner of the repository.
275275
issue (Literal['pr', 'issue']): The type of items to list, either 'pr' for pull requests or 'issue' for issues. Defaults to 'pr'.
276+
filtering (Literal['user', 'owner', 'involves']): The filtering criteria for the search. Defaults to 'involves'.
276277
Returns:
277278
Dict[str, Any]: A dictionary containing the list of open pull requests or issues, depending on the value of the `issue` parameter.
278279
None: If an error occurs during the request.
@@ -282,7 +283,7 @@ def list_open_issues_prs(self, repo_owner: str, issue: Literal['pr', 'issue'] =
282283
logging.info(f"Listing open {issue}s for {repo_owner}")
283284

284285
# Construct the search URL
285-
search_url = f"https://api.github.com/search/issues?q=is:{issue}+is:open+user:{repo_owner}"
286+
search_url = f"https://api.github.com/search/issues?q=is:{issue}+is:open+{filtering}:{repo_owner}"
286287

287288
try:
288289
response = requests.get(search_url, headers=self._get_headers())

src/mcp_github/issues_pr_analyser.py

Lines changed: 5 additions & 4 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
24+
from typing import 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,21 +210,22 @@ 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: str) -> dict[str, Any]:
213+
async def list_github_issues_prs(repo_owner: str, issue: Literal['pr', 'issue'] = 'pr', filtering: Literal['user', 'owner', 'involves'] = 'involves') -> dict[str, Any]:
214214
"""
215215
Lists open issues or pull requests for a specified GitHub repository.
216216
- Present the issues or pull requests in a markdown table format.
217217
- Add index column to the table, and make the title link to the issue or pull request.
218218
Args:
219219
repo_owner (str): The owner of the GitHub repository.
220-
issue (str): The type of items to list, either 'pr' for pull requests or 'issue' for issues. Defaults to 'pr'.
220+
issue (Literal['pr', 'issue']): The type of item to list, either 'pr' for pull requests or 'issue' for issues. Defaults to 'pr'.
221+
filtering (Literal['user', 'owner', 'involves']): The filtering criteria for the search. Defaults to 'involves'.
221222
Returns:
222223
dict[str, Any]: A dictionary containing the list of open issues or pull requests.
223224
Returns an error message if an exception occurs during the listing process.
224225
"""
225226
logging.info({"status": "info", "message": f"Listing open {issue} for {repo_owner}"})
226227
try:
227-
open_issues_prs = self.gi.list_open_issues_prs(repo_owner, issue)
228+
open_issues_prs = self.gi.list_open_issues_prs(repo_owner, issue, filtering)
228229
return open_issues_prs
229230
except Exception as e:
230231
error_msg = f"Error listing {issue} for {repo_owner}: {str(e)}"

0 commit comments

Comments
 (0)