fix: improve prompts, error messages, and workspace concurrency
- Externalize coordinator, notification, and planning prompts to separate files - Add workspace mutex for concurrent file operations - Improve error messages across file_tools, issue_tools, and pr_tools - Add logging to tool modules for better debugging - Update tests to match new error message strings
This commit is contained in:
+71
-11
@@ -40,11 +40,15 @@ class PRTools:
|
||||
def __init__(self, client: GiteaClient) -> None:
|
||||
self._client = client
|
||||
|
||||
def get_pull_request(self, owner: str, repo: str, pull_number: int) -> PullRequestModel:
|
||||
def get_pull_request(
|
||||
self, owner: str, repo: str, pull_number: int
|
||||
) -> PullRequestModel:
|
||||
try:
|
||||
return self._client.prs.get_pull_request(owner, repo, pull_number)
|
||||
except Exception as e:
|
||||
logger.error(f"Error getting pull request #{pull_number}: {e}", exc_info=True)
|
||||
logger.error(
|
||||
f"Error getting pull request #{pull_number}: {e}", exc_info=True
|
||||
)
|
||||
raise
|
||||
|
||||
def close_pull_request(self, owner: str, repo: str, pull_number: int) -> str:
|
||||
@@ -52,7 +56,14 @@ class PRTools:
|
||||
self._client.prs.close_pull_request(owner, repo, pull_number)
|
||||
return f"Pull request #{pull_number} closed successfully."
|
||||
except Exception as e:
|
||||
return f"Error closing pull request: {str(e)}"
|
||||
logger.error(
|
||||
f"Failed to close PR #{pull_number} in {owner}/{repo}: {e}",
|
||||
exc_info=True,
|
||||
)
|
||||
return (
|
||||
f"Error: Could not close PR #{pull_number} in {owner}/{repo}. "
|
||||
f"Check permissions or if the PR is already closed. Details: {e}"
|
||||
)
|
||||
|
||||
def get_pull_request_comments(
|
||||
self,
|
||||
@@ -83,7 +94,14 @@ class PRTools:
|
||||
)
|
||||
return result
|
||||
except Exception as e:
|
||||
return f"Error getting PR comments: {str(e)}"
|
||||
logger.error(
|
||||
f"Failed to get comments for PR #{pull_number} in {owner}/{repo}: {e}",
|
||||
exc_info=True,
|
||||
)
|
||||
return (
|
||||
f"Error: Could not retrieve comments for PR #{pull_number} in {owner}/{repo}. "
|
||||
f"Verify the PR exists and you have access. Details: {e}"
|
||||
)
|
||||
|
||||
def list_assigned_pull_requests(self) -> list[dict[str, Any]]:
|
||||
try:
|
||||
@@ -111,11 +129,18 @@ class PRTools:
|
||||
try:
|
||||
prs = self._client.prs.list_repo_pull_requests(owner, repo, state)
|
||||
if not prs:
|
||||
return f"No PRs in {owner}/{repo}."
|
||||
return f"No {state} PRs in {owner}/{repo}."
|
||||
summary = [f"#{pr.number}: {pr.title}" for pr in prs]
|
||||
return "\n".join(summary)
|
||||
except Exception as e:
|
||||
return f"Error listing PRs: {str(e)}"
|
||||
logger.error(
|
||||
f"Failed to list {state} PRs in {owner}/{repo}: {e}",
|
||||
exc_info=True,
|
||||
)
|
||||
return (
|
||||
f"Error: Could not list PRs for {owner}/{repo}. "
|
||||
f"Verify the repository exists and you have access. Details: {e}"
|
||||
)
|
||||
|
||||
def create_pull_request(
|
||||
self,
|
||||
@@ -156,7 +181,14 @@ class PRTools:
|
||||
self._client.prs.add_label_pr(owner, repo, pr_number, label)
|
||||
return f"Label '{label}' added to PR #{pr_number}."
|
||||
except Exception as e:
|
||||
return f"Error adding label to PR #{pr_number}: {e}"
|
||||
logger.error(
|
||||
f"Failed to add label '{label}' to PR #{pr_number} in {owner}/{repo}: {e}",
|
||||
exc_info=True,
|
||||
)
|
||||
return (
|
||||
f"Error: Could not add label '{label}' to PR #{pr_number} in {owner}/{repo}. "
|
||||
f"Verify the label exists in the repository. Details: {e}"
|
||||
)
|
||||
|
||||
def get_pull_request_diff(
|
||||
self,
|
||||
@@ -177,7 +209,14 @@ class PRTools:
|
||||
diff: str = self._client.prs.get_pull_request_diff(owner, repo, pull_number)
|
||||
return _truncate_diff(diff, max_chars, char_offset)
|
||||
except Exception as e:
|
||||
return f"Error getting PR diff: {str(e)}"
|
||||
logger.error(
|
||||
f"Failed to get diff for PR #{pull_number} in {owner}/{repo}: {e}",
|
||||
exc_info=True,
|
||||
)
|
||||
return (
|
||||
f"Error: Could not retrieve diff for PR #{pull_number} in {owner}/{repo}. "
|
||||
f"The PR may have no changes or the API is unavailable. Details: {e}"
|
||||
)
|
||||
|
||||
def get_pull_request_patch(
|
||||
self,
|
||||
@@ -200,7 +239,14 @@ class PRTools:
|
||||
)
|
||||
return _truncate_diff(patch, max_chars, char_offset)
|
||||
except Exception as e:
|
||||
return f"Error getting PR patch: {str(e)}"
|
||||
logger.error(
|
||||
f"Failed to get patch for PR #{pull_number} in {owner}/{repo}: {e}",
|
||||
exc_info=True,
|
||||
)
|
||||
return (
|
||||
f"Error: Could not retrieve patch for PR #{pull_number} in {owner}/{repo}. "
|
||||
f"The PR may have no changes or the API is unavailable. Details: {e}"
|
||||
)
|
||||
|
||||
def approve_pull_request(
|
||||
self, owner: str, repo: str, pull_number: int, comment: str
|
||||
@@ -209,7 +255,14 @@ class PRTools:
|
||||
self._client.prs.approve_pr(owner, repo, pull_number, comment)
|
||||
return f"Approved PR #{pull_number}."
|
||||
except Exception as e:
|
||||
return f"Error approving PR: {str(e)}"
|
||||
logger.error(
|
||||
f"Failed to approve PR #{pull_number} in {owner}/{repo}: {e}",
|
||||
exc_info=True,
|
||||
)
|
||||
return (
|
||||
f"Error: Could not approve PR #{pull_number} in {owner}/{repo}. "
|
||||
f"Check that you have review permissions. Details: {e}"
|
||||
)
|
||||
|
||||
def request_changes(
|
||||
self, owner: str, repo: str, pull_number: int, comment: str
|
||||
@@ -218,4 +271,11 @@ class PRTools:
|
||||
self._client.prs.request_changes_pr(owner, repo, pull_number, comment)
|
||||
return f"Requested changes on PR #{pull_number}."
|
||||
except Exception as e:
|
||||
return f"Error requesting changes: {str(e)}"
|
||||
logger.error(
|
||||
f"Failed to request changes on PR #{pull_number} in {owner}/{repo}: {e}",
|
||||
exc_info=True,
|
||||
)
|
||||
return (
|
||||
f"Error: Could not request changes on PR #{pull_number} in {owner}/{repo}. "
|
||||
f"Check that you have review permissions. Details: {e}"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user