Ruff
This commit is contained in:
parent
6c4e17999b
commit
8d67641381
|
@ -342,7 +342,10 @@ def solve_issue_in_repository(
|
||||||
files_changed = result.stdout.strip()
|
files_changed = result.stdout.strip()
|
||||||
|
|
||||||
if not files_changed:
|
if not files_changed:
|
||||||
logger.info('Aider did not make any changes beyond the initial ruff pass for issue #%s', issue_number)
|
logger.info(
|
||||||
|
'Aider did not make any changes beyond the initial ruff pass for issue #%s',
|
||||||
|
issue_number,
|
||||||
|
)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# Push changes
|
# Push changes
|
||||||
|
|
|
@ -158,7 +158,13 @@ class GiteaClient:
|
||||||
requests.HTTPError: If the API request fails.
|
requests.HTTPError: If the API request fails.
|
||||||
"""
|
"""
|
||||||
url = f'{self.gitea_url}/repos/{owner}/{repo}/pulls'
|
url = f'{self.gitea_url}/repos/{owner}/{repo}/pulls'
|
||||||
json_data = {'title': title, 'body': body, 'head': head, 'base': base, 'labels': labels}
|
json_data = {
|
||||||
|
'title': title,
|
||||||
|
'body': body,
|
||||||
|
'head': head,
|
||||||
|
'base': base,
|
||||||
|
'labels': labels,
|
||||||
|
}
|
||||||
|
|
||||||
response = self.session.post(url, json=json_data)
|
response = self.session.post(url, json=json_data)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
|
|
|
@ -1,41 +1,41 @@
|
||||||
import subprocess
|
|
||||||
import tempfile
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from unittest.mock import MagicMock, patch
|
from unittest.mock import MagicMock, patch
|
||||||
|
|
||||||
import pytest
|
|
||||||
|
|
||||||
from aider_gitea import solve_issue_in_repository
|
from aider_gitea import solve_issue_in_repository
|
||||||
|
|
||||||
|
|
||||||
class TestSolveIssueInRepository:
|
class TestSolveIssueInRepository:
|
||||||
def setup_method(self):
|
def setup_method(self):
|
||||||
self.args = MagicMock()
|
self.args = MagicMock()
|
||||||
self.args.gitea_url = "https://gitea.example.com"
|
self.args.gitea_url = 'https://gitea.example.com'
|
||||||
self.args.owner = "test-owner"
|
self.args.owner = 'test-owner'
|
||||||
self.args.repo = "test-repo"
|
self.args.repo = 'test-repo'
|
||||||
self.args.base_branch = "main"
|
self.args.base_branch = 'main'
|
||||||
|
|
||||||
self.gitea_client = MagicMock()
|
self.gitea_client = MagicMock()
|
||||||
self.tmpdirname = Path("/tmp/test-repo")
|
self.tmpdirname = Path('/tmp/test-repo')
|
||||||
self.branch_name = "issue-123-test-branch"
|
self.branch_name = 'issue-123-test-branch'
|
||||||
self.issue_title = "Test Issue"
|
self.issue_title = 'Test Issue'
|
||||||
self.issue_description = "This is a test issue"
|
self.issue_description = 'This is a test issue'
|
||||||
self.issue_number = "123"
|
self.issue_number = '123'
|
||||||
|
|
||||||
@patch('aider_gitea.secrets.llm_api_key', return_value="fake-api-key")
|
@patch('aider_gitea.secrets.llm_api_key', return_value='fake-api-key')
|
||||||
@patch('aider_gitea.run_cmd')
|
@patch('aider_gitea.run_cmd')
|
||||||
@patch('aider_gitea.push_changes')
|
@patch('aider_gitea.push_changes')
|
||||||
@patch('subprocess.run')
|
@patch('subprocess.run')
|
||||||
def test_solve_issue_with_aider_changes(self, mock_subprocess_run, mock_push_changes, mock_run_cmd, mock_llm_api_key):
|
def test_solve_issue_with_aider_changes(
|
||||||
|
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
|
||||||
mock_push_changes.return_value = True
|
mock_push_changes.return_value = True
|
||||||
|
|
||||||
# Mock subprocess.run to return different commit hashes and file changes
|
# Mock subprocess.run to return different commit hashes and file changes
|
||||||
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(stdout="file1.py\nfile2.py\n", returncode=0), # git diff with changes
|
MagicMock(
|
||||||
|
stdout='file1.py\nfile2.py\n', returncode=0,
|
||||||
|
), # git diff with changes
|
||||||
]
|
]
|
||||||
|
|
||||||
# Call the function
|
# Call the function
|
||||||
|
@ -46,7 +46,7 @@ class TestSolveIssueInRepository:
|
||||||
self.issue_title,
|
self.issue_title,
|
||||||
self.issue_description,
|
self.issue_description,
|
||||||
self.issue_number,
|
self.issue_number,
|
||||||
self.gitea_client
|
self.gitea_client,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Verify results
|
# Verify results
|
||||||
|
@ -54,18 +54,20 @@ class TestSolveIssueInRepository:
|
||||||
assert mock_run_cmd.call_count >= 8 # Verify all expected commands were run
|
assert mock_run_cmd.call_count >= 8 # Verify all expected commands were run
|
||||||
mock_push_changes.assert_called_once()
|
mock_push_changes.assert_called_once()
|
||||||
|
|
||||||
@patch('aider_gitea.secrets.llm_api_key', return_value="fake-api-key")
|
@patch('aider_gitea.secrets.llm_api_key', return_value='fake-api-key')
|
||||||
@patch('aider_gitea.run_cmd')
|
@patch('aider_gitea.run_cmd')
|
||||||
@patch('aider_gitea.push_changes')
|
@patch('aider_gitea.push_changes')
|
||||||
@patch('subprocess.run')
|
@patch('subprocess.run')
|
||||||
def test_solve_issue_without_aider_changes(self, mock_subprocess_run, mock_push_changes, mock_run_cmd, mock_llm_api_key):
|
def test_solve_issue_without_aider_changes(
|
||||||
|
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
|
||||||
|
|
||||||
# Mock subprocess.run to return same commit hash and no file changes
|
# Mock subprocess.run to return same commit hash and no file changes
|
||||||
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(stdout="", returncode=0), # git diff with no changes
|
MagicMock(stdout='', returncode=0), # git diff with no changes
|
||||||
]
|
]
|
||||||
|
|
||||||
# Call the function
|
# Call the function
|
||||||
|
@ -76,7 +78,7 @@ class TestSolveIssueInRepository:
|
||||||
self.issue_title,
|
self.issue_title,
|
||||||
self.issue_description,
|
self.issue_description,
|
||||||
self.issue_number,
|
self.issue_number,
|
||||||
self.gitea_client
|
self.gitea_client,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Verify results
|
# Verify results
|
||||||
|
|
Loading…
Reference in New Issue
Block a user