Add GiteaClient get_pull_request_comments method #83
|
@ -283,8 +283,10 @@ def run_cmd(cmd: list[str], cwd: Path | None = None, check=True) -> bool:
|
||||||
result = subprocess.run(cmd, check=check, cwd=cwd)
|
result = subprocess.run(cmd, check=check, cwd=cwd)
|
||||||
return result.returncode == 0
|
return result.returncode == 0
|
||||||
|
|
||||||
|
|
||||||
SKIP_AIDER = False
|
SKIP_AIDER = False
|
||||||
|
|
||||||
|
|
||||||
def solve_issue_in_repository(
|
def solve_issue_in_repository(
|
||||||
args,
|
args,
|
||||||
tmpdirname: Path,
|
tmpdirname: Path,
|
||||||
|
@ -294,7 +296,7 @@ def solve_issue_in_repository(
|
||||||
issue_number: str,
|
issue_number: str,
|
||||||
gitea_client=None,
|
gitea_client=None,
|
||||||
) -> bool:
|
) -> bool:
|
||||||
logger.info("### %s #####", issue_title)
|
logger.info('### %s #####', issue_title)
|
||||||
|
|
||||||
repo_url = f'{args.gitea_url}:{args.owner}/{args.repo}.git'.replace(
|
repo_url = f'{args.gitea_url}:{args.owner}/{args.repo}.git'.replace(
|
||||||
'https://',
|
'https://',
|
||||||
|
@ -331,7 +333,7 @@ def solve_issue_in_repository(
|
||||||
check=False,
|
check=False,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
logger.warning("Skipping aider command (for testing)")
|
logger.warning('Skipping aider command (for testing)')
|
||||||
succeeded = True
|
succeeded = True
|
||||||
if not succeeded:
|
if not succeeded:
|
||||||
logger.error('Aider invocation failed for issue #%s', issue_number)
|
logger.error('Aider invocation failed for issue #%s', issue_number)
|
||||||
|
|
|
@ -168,3 +168,24 @@ class GiteaClient:
|
||||||
response = self.session.post(url, json=json_data)
|
response = self.session.post(url, json=json_data)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
return response.json()
|
return response.json()
|
||||||
|
|
||||||
|
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 for the pull request.
|
||||||
|
|
||||||
|
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()
|
||||||
|
|
71
test/test_gitea_client_pr_comments.py
Normal file
71
test/test_gitea_client_pr_comments.py
Normal file
|
@ -0,0 +1,71 @@
|
||||||
|
from unittest.mock import MagicMock, patch
|
||||||
|
|
||||||
|
from aider_gitea.gitea_client import GiteaClient
|
||||||
|
|
||||||
|
|
||||||
|
class TestGiteaClientPRComments:
|
||||||
|
def setup_method(self):
|
||||||
|
"""Set up test fixtures."""
|
||||||
|
self.client = GiteaClient('https://gitea.example.com', 'fake-token')
|
||||||
|
self.owner = 'test-owner'
|
||||||
|
self.repo = 'test-repo'
|
||||||
|
self.pull_number = 123
|
||||||
|
|
||||||
|
@patch('requests.Session.get')
|
||||||
|
def test_get_pull_request_comments(self, mock_get):
|
||||||
|
"""Test retrieving comments for a pull request."""
|
||||||
|
# Mock response data
|
||||||
|
mock_response = MagicMock()
|
||||||
|
mock_response.json.return_value = [
|
||||||
|
{
|
||||||
|
'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_get.return_value = mock_response
|
||||||
|
|
||||||
|
# Call the method
|
||||||
|
comments = self.client.get_pull_request_comments(
|
||||||
|
self.owner, self.repo, self.pull_number,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Verify the request was made correctly
|
||||||
|
mock_get.assert_called_once_with(
|
||||||
|
f'{self.client.gitea_url}/repos/{self.owner}/{self.repo}/pulls/{self.pull_number}/comments',
|
||||||
|
)
|
||||||
|
|
||||||
|
# Verify the response was processed correctly
|
||||||
|
assert len(comments) == 2
|
||||||
|
assert comments[0]['id'] == 1
|
||||||
|
assert comments[0]['body'] == 'This is a test comment'
|
||||||
|
assert comments[1]['id'] == 2
|
||||||
|
assert comments[1]['body'] == 'Another test comment'
|
||||||
|
|
||||||
|
@patch('requests.Session.get')
|
||||||
|
def test_get_pull_request_comments_empty(self, mock_get):
|
||||||
|
"""Test retrieving comments for a pull request with no comments."""
|
||||||
|
# Mock response data
|
||||||
|
mock_response = MagicMock()
|
||||||
|
mock_response.json.return_value = []
|
||||||
|
mock_get.return_value = mock_response
|
||||||
|
|
||||||
|
# Call the method
|
||||||
|
comments = self.client.get_pull_request_comments(
|
||||||
|
self.owner, self.repo, self.pull_number,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Verify the request was made correctly
|
||||||
|
mock_get.assert_called_once_with(
|
||||||
|
f'{self.client.gitea_url}/repos/{self.owner}/{self.repo}/pulls/{self.pull_number}/comments',
|
||||||
|
)
|
||||||
|
|
||||||
|
# Verify the response was processed correctly
|
||||||
|
assert len(comments) == 0
|
|
@ -24,7 +24,11 @@ class TestSolveIssueInRepository:
|
||||||
@patch('aider_gitea.push_changes')
|
@patch('aider_gitea.push_changes')
|
||||||
@patch('subprocess.run')
|
@patch('subprocess.run')
|
||||||
def test_solve_issue_with_aider_changes(
|
def test_solve_issue_with_aider_changes(
|
||||||
self, mock_subprocess_run, mock_push_changes, mock_run_cmd, mock_llm_api_key,
|
self,
|
||||||
|
mock_subprocess_run,
|
||||||
|
mock_push_changes,
|
||||||
|
mock_run_cmd,
|
||||||
|
mock_llm_api_key,
|
||||||
):
|
):
|
||||||
# Setup mocks
|
# Setup mocks
|
||||||
mock_run_cmd.return_value = True
|
mock_run_cmd.return_value = True
|
||||||
|
@ -34,7 +38,8 @@ class TestSolveIssueInRepository:
|
||||||
mock_subprocess_run.side_effect = [
|
mock_subprocess_run.side_effect = [
|
||||||
MagicMock(stdout='abc123\n', returncode=0), # First git rev-parse
|
MagicMock(stdout='abc123\n', returncode=0), # First git rev-parse
|
||||||
MagicMock(
|
MagicMock(
|
||||||
stdout='file1.py\nfile2.py\n', returncode=0,
|
stdout='file1.py\nfile2.py\n',
|
||||||
|
returncode=0,
|
||||||
), # git diff with changes
|
), # git diff with changes
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -59,7 +64,11 @@ class TestSolveIssueInRepository:
|
||||||
@patch('aider_gitea.push_changes')
|
@patch('aider_gitea.push_changes')
|
||||||
@patch('subprocess.run')
|
@patch('subprocess.run')
|
||||||
def test_solve_issue_without_aider_changes(
|
def test_solve_issue_without_aider_changes(
|
||||||
self, mock_subprocess_run, mock_push_changes, mock_run_cmd, mock_llm_api_key,
|
self,
|
||||||
|
mock_subprocess_run,
|
||||||
|
mock_push_changes,
|
||||||
|
mock_run_cmd,
|
||||||
|
mock_llm_api_key,
|
||||||
):
|
):
|
||||||
# Setup mocks
|
# Setup mocks
|
||||||
mock_run_cmd.return_value = True
|
mock_run_cmd.return_value = True
|
||||||
|
|
Loading…
Reference in New Issue
Block a user