feat: Add get_pull_request_comments method to GiteaClient with tests

This commit is contained in:
Jon Michael Aanes (aider) 2025-04-15 00:20:47 +02:00
parent 5f6ee7f3ad
commit fc69e8d811
2 changed files with 68 additions and 0 deletions

View File

@ -129,3 +129,22 @@ class GiteaClient:
if repo['owner']['login'].lower() != owner.lower():
continue
yield repo['name']
def get_pull_request_comments(self, owner: str, repo: str, pull_number: int) -> list[dict]:
"""Get comments for a specific pull request.
Args:
owner (str): Owner of the repository.
repo (str): Name of the repository.
pull_number (int): The pull request number.
Returns:
list[dict]: A list of comment dictionaries containing comment data.
Raises:
requests.HTTPError: If the API request fails.
"""
url = f'{self.gitea_url}/repos/{owner}/{repo}/pulls/{pull_number}/comments'
response = self.session.get(url)
response.raise_for_status()
return response.json()

49
test/test_gitea_client.py Normal file
View File

@ -0,0 +1,49 @@
import pytest
import responses
from aider_gitea.gitea_client import GiteaClient
class TestGiteaClient:
def setup_method(self):
"""Set up test fixtures."""
self.gitea_url = "https://gitea.example.com"
self.token = "test_token"
self.client = GiteaClient(self.gitea_url, self.token)
self.owner = "test_owner"
self.repo = "test_repo"
@responses.activate
def test_get_pull_request_comments(self):
"""Test retrieving comments for a pull request."""
pull_number = 123
expected_comments = [
{
"id": 1,
"body": "This is a test comment",
"user": {"login": "test_user"},
"created_at": "2023-01-01T00:00:00Z",
},
{
"id": 2,
"body": "Another test comment",
"user": {"login": "another_user"},
"created_at": "2023-01-02T00:00:00Z",
},
]
# Mock the API response
url = f"{self.gitea_url}/api/v1/repos/{self.owner}/{self.repo}/pulls/{pull_number}/comments"
responses.add(
responses.GET,
url,
json=expected_comments,
status=200,
)
# Call the method
comments = self.client.get_pull_request_comments(self.owner, self.repo, pull_number)
# Verify the result
assert comments == expected_comments
assert len(responses.calls) == 1
assert responses.calls[0].request.url == url