fix 5.4: return structured types from get_issue/get_pull_request/create_pull_request/update_pull_request
- IssueTools.get_issue now returns IssueModel instead of JSON string - PRTools.get_pull_request now returns PullRequestModel instead of JSON string - PRTools.create_pull_request now returns PullRequestModel instead of JSON string - PRTools.update_pull_request now returns PullRequestModel instead of JSON string - All methods have proper return type hints and raise exceptions on error - Updated tests to verify model objects are returned directly - Marked issue 5.4 as resolved in bad_code.md
This commit is contained in:
+12
-14
@@ -40,14 +40,12 @@ class PRTools:
|
||||
def __init__(self, client: GiteaClient) -> None:
|
||||
self._client = client
|
||||
|
||||
def get_pull_request(self, owner: str, repo: str, pull_number: int) -> str:
|
||||
def get_pull_request(self, owner: str, repo: str, pull_number: int) -> PullRequestModel:
|
||||
try:
|
||||
pr: PullRequestModel = self._client.prs.get_pull_request(
|
||||
owner, repo, pull_number
|
||||
)
|
||||
return pr.model_dump_json(indent=2)
|
||||
return self._client.prs.get_pull_request(owner, repo, pull_number)
|
||||
except Exception as e:
|
||||
return f"Error getting pull request: {str(e)}"
|
||||
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:
|
||||
try:
|
||||
@@ -127,14 +125,14 @@ class PRTools:
|
||||
base: str,
|
||||
title: str,
|
||||
description: str = "",
|
||||
) -> str:
|
||||
) -> PullRequestModel:
|
||||
try:
|
||||
pr = self._client.prs.create_pr_via_tea(
|
||||
return self._client.prs.create_pr_via_tea(
|
||||
owner, repo, title, description, head, base
|
||||
)
|
||||
return pr.model_dump_json(indent=2)
|
||||
except Exception as e:
|
||||
return f"Error creating PR: {str(e)}"
|
||||
logger.error(f"Error creating PR in {owner}/{repo}: {e}", exc_info=True)
|
||||
raise
|
||||
|
||||
def update_pull_request(
|
||||
self,
|
||||
@@ -144,14 +142,14 @@ class PRTools:
|
||||
title: str | None = None,
|
||||
body: str | None = None,
|
||||
state: str | None = None,
|
||||
) -> str:
|
||||
) -> PullRequestModel:
|
||||
try:
|
||||
pr = self._client.prs.update_pull_request(
|
||||
return self._client.prs.update_pull_request(
|
||||
owner, repo, pull_number, title, body, state
|
||||
)
|
||||
return pr.model_dump_json(indent=2)
|
||||
except Exception as e:
|
||||
return f"Error updating PR #{pull_number}: {str(e)}"
|
||||
logger.error(f"Error updating PR #{pull_number}: {e}", exc_info=True)
|
||||
raise
|
||||
|
||||
def add_label_to_pr(self, owner: str, repo: str, pr_number: int, label: str) -> str:
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user