Skip to content

Commit 5a5f454

Browse files
saidsefCopilot
andauthored
feat: improve type and error handling (#57)
* feat: improve type and error handling - Update package version from 2.3.0 to 2.3.1 - Change return type of get_github_pr_content from Dict[str, Any] to str - Return consistent error strings instead of empty values - Improve error message formatting in logging - Alphabetise type imports in issues_pr_analyser.py * chore: update grammar Co-authored-by: Copilot <[email protected]> * chore: update grammar Co-authored-by: Copilot <[email protected]> * chore: return type fix Co-authored-by: Copilot <[email protected]> * chore: return type fix Co-authored-by: Copilot <[email protected]> * chore: return type fix Co-authored-by: Copilot <[email protected]> --------- Co-authored-by: Copilot <[email protected]>
1 parent dd3dc03 commit 5a5f454

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
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.3.0"
3+
version = "2.3.1"
44
description = "MCP GitHub Issues Create/Update and PR Analyse"
55
readme = "README.md"
66
requires-python = ">=3.12"

src/mcp_github/issues_pr_analyser.py

Lines changed: 13 additions & 11 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, List, Dict
24+
from typing import Any, Dict, List
2525
from mcp.server.fastmcp import FastMCP
2626
from .github_integration import GitHubIntegration as GI
2727
from .ip_integration import IPIntegration as IP
@@ -88,7 +88,7 @@ async def get_github_pr_diff(repo_owner: str, repo_name: str, pr_number: int) ->
8888
pr_number (int): The pull request number to fetch the diff for.
8989
9090
Returns:
91-
str: The diff of the pull request as a string. Returns an empty string if no changes are found,
91+
str: The diff of the pull request as a string. Returns a 'No changes' string if no changes are found,
9292
or an error message string if an exception occurs.
9393
9494
Error Handling:
@@ -98,8 +98,9 @@ async def get_github_pr_diff(repo_owner: str, repo_name: str, pr_number: int) ->
9898
try:
9999
pr_diff = self.gi.get_pr_diff(repo_owner, repo_name, pr_number)
100100
if pr_diff is None:
101-
logging.info("No changes returned from get_pr_diff")
102-
return ""
101+
no_changes = "No changes returned from get_pr_diff"
102+
logging.info(f"{no_changes}")
103+
return f"{no_changes}"
103104
logging.info(f"Successfully fetched PR diff")
104105
return pr_diff
105106
except Exception as e:
@@ -108,7 +109,7 @@ async def get_github_pr_diff(repo_owner: str, repo_name: str, pr_number: int) ->
108109
return str(e)
109110

110111
@self.mcp.tool()
111-
async def get_github_pr_content(repo_owner: str, repo_name: str, pr_number: int) -> Dict[str, Any]:
112+
async def get_github_pr_content(repo_owner: str, repo_name: str, pr_number: int) -> str:
112113
"""
113114
Use get_pr_diff to fetch the diff of a specific pull request from a GitHub repository.
114115
If you still need more context, then use this to fetch the content of the pull request.
@@ -118,22 +119,23 @@ async def get_github_pr_content(repo_owner: str, repo_name: str, pr_number: int)
118119
repo_name (str): The name of the GitHub repository.
119120
pr_number (int): The pull request number to fetch.
120121
Returns:
121-
Dict[str, Any]: A dictionary containing the pull request information if successful, or an empty dictionary if no information is found or an error occurs.
122+
str: A string containing the pull request information if successful, or a 'No changes' string if no information is found or an error occurs.
122123
Error Handling:
123-
Logs an error message and prints the traceback to stderr if an exception is raised during the fetch operation. Returns an empty dictionary in case of errors.
124+
Logs an error message and prints the traceback to stderr if an exception is raised during the fetch operation. Returns error string in case of errors.
124125
"""
125126
logging.info(f"Fetching PR #{pr_number} from {repo_owner}/{repo_name}")
126127
try:
127128
pr_info = self.gi.get_pr_content(repo_owner, repo_name, pr_number)
128129
if pr_info is None:
129-
logging.info("No changes returned from get_pr_content")
130-
return {}
130+
no_changes = "No changes returned from get_pr_content"
131+
logging.info(f"{no_changes}")
132+
return f"{no_changes}"
131133
logging.info(f"Successfully fetched PR information")
132-
return pr_info
134+
return str(pr_info)
133135
except Exception as e:
134136
logging.error(f"Error fetching PR: {str(e)}")
135137
traceback.print_exc(file=sys.stderr)
136-
return {}
138+
return str(e)
137139

138140
@self.mcp.tool()
139141
async def update_github_pr_description(repo_owner: str, repo_name: str, pr_number: int, new_title: str, new_description: str) -> str:

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)