Skip to content

Commit ce9b759

Browse files
saidsefCopilot
andauthored
feat: enhance documentation, fix inline commenting, and improve consistency (#59)
* feat: enhance documentation, fix inline commenting, and improve consistency - Updated function docstrings with consistent British spellings (initialise vs initialize) - Enhanced PR and issue management with better inline commenting capabilities - Added updated_at and author fields to PR listing functionality - Improved error handling and logging consistency across GitHub integration - Standardised documentation format and removed redundant whitespace * chore: grammatical fix Co-authored-by: Copilot <[email protected]> --------- Co-authored-by: Copilot <[email protected]>
1 parent 5a5f454 commit ce9b759

File tree

4 files changed

+238
-245
lines changed

4 files changed

+238
-245
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.1"
3+
version = "2.3.2"
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: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
class GitHubIntegration:
3333
def __init__(self):
3434
"""
35-
Initialize the GitHubIntegration class.
35+
Initialise the GitHubIntegration class.
3636
3737
Returns:
3838
None
@@ -44,7 +44,7 @@ def __init__(self):
4444
if not self.github_token:
4545
raise ValueError("Missing GitHub GITHUB_TOKEN in environment variables")
4646

47-
logging.info("GitHub Integration initialized")
47+
logging.info("GitHub Integration Initialised")
4848

4949
def _get_headers(self):
5050
"""
@@ -299,6 +299,8 @@ def list_open_prs(self, repo_owner: str) -> Dict[str, Any]:
299299
"number": item['number'],
300300
"state": item['state'],
301301
"created_at": item['created_at'],
302+
"updated_at": item['updated_at'],
303+
"author": item['user']['login'],
302304
"label_names": [label['name'] for label in item.get('labels', [])]
303305
}
304306
for item in pr_data['items']

src/mcp_github/issues_pr_analyser.py

Lines changed: 33 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class PRIssueAnalyser:
3636
Methods
3737
-------
3838
__init__():
39-
Initializes the PRIssueAnalyser instance by setting up GitHub integration, IP processing, and the MCP server. Registers all MCP tools for PR and issue management.
39+
Initialises the PRIssueAnalyser instance by setting up GitHub integration, IP processing, and the MCP server. Registers all MCP tools for PR and issue management.
4040
Any exceptions during initialization are not explicitly handled and will propagate.
4141
_register_tools():
4242
Registers a set of asynchronous MCP tools for:
@@ -52,9 +52,9 @@ class PRIssueAnalyser:
5252
"""
5353
def __init__(self):
5454
"""
55-
Initializes the main components required for the Issue and PR Analyser.
55+
Initialises the main components required for the Issue and PR Analyser.
5656
This constructor performs the following actions:
57-
- Initializes the GitHub integration and issue processing components.
57+
- Initialises the GitHub integration and issue processing components.
5858
- Sets up the MCP (Multi-Component Platform) server for handling PR analysis, issue creation, and updates.
5959
- Registers the necessary MCP tools for further processing.
6060
- Logs the successful initialization of the MCP server.
@@ -66,8 +66,8 @@ def __init__(self):
6666

6767
# Initialize MCP Server
6868
self.mcp = FastMCP(
69-
name="GitHub PR Analyse, Issue Create and Update",
70-
instruction="Use the tools to analyze GitHub PRs, create and update issues, and manage tags and releases.",
69+
name="GitHub PR and Issue Analyser",
70+
instruction="You are a GitHub PR and Issue Analyser. You can fetch PR diffs, update PR descriptions, create and update issues, create tags and releases, and fetch IP information.",
7171
)
7272
logging.info("MCP Server initialized")
7373

@@ -81,18 +81,17 @@ def _register_tools(self):
8181
async def get_github_pr_diff(repo_owner: str, repo_name: str, pr_number: int) -> str:
8282
"""
8383
Fetches the diff of a specific pull request from a GitHub repository.
84-
84+
Use only get_pr_diff to fetch the diff of a specific pull request from a GitHub repository.
8585
Args:
8686
repo_owner (str): The owner of the GitHub repository.
8787
repo_name (str): The name of the GitHub repository.
8888
pr_number (int): The pull request number to fetch the diff for.
89-
9089
Returns:
9190
str: The diff of the pull request as a string. Returns a 'No changes' string if no changes are found,
9291
or an error message string if an exception occurs.
93-
9492
Error Handling:
9593
Logs and returns the error message if an exception is raised during the fetch operation.
94+
The exception traceback is also printed to stderr for debugging purposes.
9695
"""
9796
logging.info(f"Fetching PR #{pr_number} diff from {repo_owner}/{repo_name}")
9897
try:
@@ -111,17 +110,17 @@ async def get_github_pr_diff(repo_owner: str, repo_name: str, pr_number: int) ->
111110
@self.mcp.tool()
112111
async def get_github_pr_content(repo_owner: str, repo_name: str, pr_number: int) -> str:
113112
"""
114-
Use get_pr_diff to fetch the diff of a specific pull request from a GitHub repository.
115-
If you still need more context, then use this to fetch the content of the pull request.
116-
Fetches the content of a GitHub pull request for a given repository and PR number.
113+
Fetches the content of a specific pull request from a GitHub repository.
114+
Use only get_pr_diff to fetch the diff of a specific pull request from a GitHub repository.
117115
Args:
118116
repo_owner (str): The owner of the GitHub repository.
119117
repo_name (str): The name of the GitHub repository.
120-
pr_number (int): The pull request number to fetch.
118+
pr_number (int): The pull request number to fetch the content for.
121119
Returns:
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.
120+
str: The content of the pull request as a string. Returns a 'No changes' string if no changes are found,
121+
or an error message string if an exception occurs.
123122
Error Handling:
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.
123+
Logs and returns the error message if an exception is raised during the fetch operation.
125124
"""
126125
logging.info(f"Fetching PR #{pr_number} from {repo_owner}/{repo_name}")
127126
try:
@@ -140,18 +139,15 @@ async def get_github_pr_content(repo_owner: str, repo_name: str, pr_number: int)
140139
@self.mcp.tool()
141140
async def update_github_pr_description(repo_owner: str, repo_name: str, pr_number: int, new_title: str, new_description: str) -> str:
142141
"""
143-
Updates the title and description of a GitHub pull request.
144-
142+
Updates the description of a GitHub pull request with a new title and description.
145143
Args:
146-
repo_owner (str): The owner of the repository.
147-
repo_name (str): The name of the repository.
144+
repo_owner (str): The owner of the GitHub repository.
145+
repo_name (str): The name of the GitHub repository.
148146
pr_number (int): The pull request number to update.
149147
new_title (str): The new title for the pull request.
150148
new_description (str): The new description for the pull request.
151-
152149
Returns:
153150
str: A message indicating the result of the update operation. Returns a success message if the update is successful, or an error message if an exception occurs.
154-
155151
Error Handling:
156152
Catches and logs any exceptions that occur during the update process. If an error is encountered, the error message is logged and returned.
157153
"""
@@ -169,21 +165,19 @@ async def update_github_pr_description(repo_owner: str, repo_name: str, pr_numbe
169165
@self.mcp.tool()
170166
async def add_github_pr_inline_comment(repo_owner: str, repo_name: str, pr_number: int, path: str, line: int, comment_body: str) -> str:
171167
"""
172-
Adds an inline review comment to a specific line in a GitHub pull request file.
173-
Only comment if there is an issue with the code, otherwise do not comment.
168+
Adds an inline review comment to a specific line in a pull request on GitHub.
169+
Only comment if there are issues with the code, otherwise do not comment.
174170
Args:
175-
repo_owner (str): The owner of the repository.
176-
repo_name (str): The name of the repository.
171+
repo_owner (str): The owner of the GitHub repository.
172+
repo_name (str): The name of the GitHub repository.
177173
pr_number (int): The pull request number to add the comment to.
178-
path (str): The relative path to the file (e.g., 'src/main.py').
179-
line (int): The line number in the file to comment on.
180-
comment_body (str): The content of the review comment.
181-
174+
path (str): The file path in the pull request where the comment should be added.
175+
line (int): The line number in the file where the comment should be added.
176+
comment_body (str): The content of the comment to be added.
182177
Returns:
183-
str: A message indicating the result of the comment addition. Returns a success message if the comment is added successfully, or an error message if an exception occurs.
184-
178+
str: A message indicating the result of the inline comment addition. Returns a success message if the comment is added successfully, or an error message if an exception occurs.
185179
Error Handling:
186-
Catches and logs any exceptions that occur during the comment addition process. If an error is encountered, the error message is logged and returned.
180+
Catches and logs any exceptions that occur during the inline comment addition process. If an error is encountered, the error message is logged and returned.
187181
"""
188182
logging.info(f"Adding inline review comment to PR #{pr_number}")
189183
try:
@@ -200,16 +194,13 @@ async def add_github_pr_inline_comment(repo_owner: str, repo_name: str, pr_numbe
200194
async def add_github_pr_comment(repo_owner: str, repo_name: str, pr_number: int, comment: str) -> str:
201195
"""
202196
Adds a comment to a GitHub pull request.
203-
204197
Args:
205-
repo_owner (str): The owner of the repository.
206-
repo_name (str): The name of the repository.
198+
repo_owner (str): The owner of the GitHub repository.
199+
repo_name (str): The name of the GitHub repository.
207200
pr_number (int): The pull request number to add the comment to.
208-
comment (str): The comment text to be added.
209-
201+
comment (str): The content of the comment to be added.
210202
Returns:
211203
str: A message indicating the result of the comment addition. Returns a success message if the comment is added successfully, or an error message if an exception occurs.
212-
213204
Error Handling:
214205
Catches and logs any exceptions that occur during the comment addition process. If an error is encountered, the error message is logged and returned.
215206
"""
@@ -227,13 +218,13 @@ async def add_github_pr_comment(repo_owner: str, repo_name: str, pr_number: int,
227218
@self.mcp.tool()
228219
async def list_github_prs(repo_owner: str) -> str:
229220
"""
230-
Lists all open pull requests for a given repository owner.
221+
Lists all open pull requests for a given GitHub repository owner.
231222
Args:
232-
repo_owner (str): The owner of the repository.
223+
repo_owner (str): The owner of the GitHub repository.
233224
Returns:
234-
Dict[str, Any]: A dictionary containing the list of open pull requests.
225+
str: A message indicating the result of the PR listing. Returns a success message with the list of open PRs if successful, or an error message if an exception occurs.
235226
Error Handling:
236-
Catches and logs any exceptions that occur during the fetch operation. If an error is encountered, the error message is logged and an empty dictionary is returned.
227+
Catches and logs any exceptions that occur during the PR listing process. If an error is encountered, the error message is logged and returned.
237228
"""
238229
logging.info(f"Listing open PRs for {repo_owner}")
239230
try:
@@ -410,7 +401,7 @@ def run(self):
410401
def main():
411402
"""
412403
Main entry point for the PR and Issue Analyzer.
413-
This function initializes the PRIssueAnalyser and executes its main logic.
404+
This function Initialises the PRIssueAnalyser and executes its main logic.
414405
If an exception occurs during execution, it logs the error, prints the traceback,
415406
and exits the program with a non-zero status code.
416407
Returns:

0 commit comments

Comments
 (0)