Ruff
This commit is contained in:
parent
34c89c0e5f
commit
ab4aef11e6
|
@ -262,6 +262,7 @@ def get_current_commit_hash(cwd: Path) -> str:
|
||||||
logger.exception('Failed to get current commit hash')
|
logger.exception('Failed to get current commit hash')
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
|
|
||||||
def has_changes_since_commit(cwd: Path, commit_hash: str) -> bool:
|
def has_changes_since_commit(cwd: Path, commit_hash: str) -> bool:
|
||||||
"""Check if there are any changes since the specified commit.
|
"""Check if there are any changes since the specified commit.
|
||||||
|
|
||||||
|
@ -285,6 +286,7 @@ def has_changes_since_commit(cwd: Path, commit_hash: str) -> bool:
|
||||||
logger.exception('Failed to check for changes since commit %s', commit_hash)
|
logger.exception('Failed to check for changes since commit %s', commit_hash)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def has_commits_on_branch(cwd: Path, base_branch: str, current_branch: str) -> bool:
|
def has_commits_on_branch(cwd: Path, base_branch: str, current_branch: str) -> bool:
|
||||||
"""Check if there are any commits on the current branch that aren't in the base branch.
|
"""Check if there are any commits on the current branch that aren't in the base branch.
|
||||||
|
|
||||||
|
@ -371,7 +373,10 @@ def solve_issue_in_repository(
|
||||||
|
|
||||||
# Check if aider made any changes beyond the initial ruff pass
|
# Check if aider made any changes beyond the initial ruff pass
|
||||||
if not has_changes_since_commit(tmpdirname, pre_aider_commit):
|
if not has_changes_since_commit(tmpdirname, pre_aider_commit):
|
||||||
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
|
||||||
|
|
|
@ -171,7 +171,11 @@ class GiteaClient:
|
||||||
return pull_request
|
return pull_request
|
||||||
|
|
||||||
def add_labels_to_pull_request(
|
def add_labels_to_pull_request(
|
||||||
self, owner: str, repo: str, pull_number: int, labels: list[str],
|
self,
|
||||||
|
owner: str,
|
||||||
|
repo: str,
|
||||||
|
pull_number: int,
|
||||||
|
labels: list[str],
|
||||||
) -> bool:
|
) -> bool:
|
||||||
"""Add labels to an existing pull request.
|
"""Add labels to an existing pull request.
|
||||||
|
|
||||||
|
|
|
@ -66,7 +66,10 @@ class TestGiteaClientPRLabels:
|
||||||
|
|
||||||
# Call the method
|
# Call the method
|
||||||
result = self.client.add_labels_to_pull_request(
|
result = self.client.add_labels_to_pull_request(
|
||||||
owner='owner', repo='repo', pull_number=123, labels=['aider', 'bug'],
|
owner='owner',
|
||||||
|
repo='repo',
|
||||||
|
pull_number=123,
|
||||||
|
labels=['aider', 'bug'],
|
||||||
)
|
)
|
||||||
|
|
||||||
# Verify the call
|
# Verify the call
|
||||||
|
|
|
@ -1,28 +1,28 @@
|
||||||
import os
|
|
||||||
import tempfile
|
import tempfile
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from unittest.mock import patch, MagicMock
|
from unittest.mock import MagicMock, patch
|
||||||
|
|
||||||
import pytest
|
|
||||||
|
|
||||||
def test_init():
|
def test_init():
|
||||||
import aider_gitea # noqa: F401
|
import aider_gitea # noqa: F401
|
||||||
import aider_gitea.secrets # noqa: F401
|
import aider_gitea.secrets # noqa: F401
|
||||||
|
|
||||||
|
|
||||||
def test_get_current_commit_hash():
|
def test_get_current_commit_hash():
|
||||||
from aider_gitea import get_current_commit_hash
|
from aider_gitea import get_current_commit_hash
|
||||||
|
|
||||||
with tempfile.TemporaryDirectory() as tmpdirname:
|
with tempfile.TemporaryDirectory() as tmpdirname:
|
||||||
with patch('subprocess.run') as mock_run:
|
with patch('subprocess.run') as mock_run:
|
||||||
mock_result = MagicMock()
|
mock_result = MagicMock()
|
||||||
mock_result.stdout = "abcdef1234567890"
|
mock_result.stdout = 'abcdef1234567890'
|
||||||
mock_run.return_value = mock_result
|
mock_run.return_value = mock_result
|
||||||
|
|
||||||
result = get_current_commit_hash(Path(tmpdirname))
|
result = get_current_commit_hash(Path(tmpdirname))
|
||||||
|
|
||||||
assert result == "abcdef1234567890"
|
assert result == 'abcdef1234567890'
|
||||||
mock_run.assert_called_once()
|
mock_run.assert_called_once()
|
||||||
|
|
||||||
|
|
||||||
def test_has_changes_since_commit():
|
def test_has_changes_since_commit():
|
||||||
from aider_gitea import has_changes_since_commit
|
from aider_gitea import has_changes_since_commit
|
||||||
|
|
||||||
|
@ -30,10 +30,10 @@ def test_has_changes_since_commit():
|
||||||
# Test with changes
|
# Test with changes
|
||||||
with patch('subprocess.run') as mock_run:
|
with patch('subprocess.run') as mock_run:
|
||||||
mock_result = MagicMock()
|
mock_result = MagicMock()
|
||||||
mock_result.stdout = "file1.py\nfile2.py"
|
mock_result.stdout = 'file1.py\nfile2.py'
|
||||||
mock_run.return_value = mock_result
|
mock_run.return_value = mock_result
|
||||||
|
|
||||||
result = has_changes_since_commit(Path(tmpdirname), "abcdef")
|
result = has_changes_since_commit(Path(tmpdirname), 'abcdef')
|
||||||
|
|
||||||
assert result is True
|
assert result is True
|
||||||
mock_run.assert_called_once()
|
mock_run.assert_called_once()
|
||||||
|
@ -41,42 +41,52 @@ def test_has_changes_since_commit():
|
||||||
# Test without changes
|
# Test without changes
|
||||||
with patch('subprocess.run') as mock_run:
|
with patch('subprocess.run') as mock_run:
|
||||||
mock_result = MagicMock()
|
mock_result = MagicMock()
|
||||||
mock_result.stdout = ""
|
mock_result.stdout = ''
|
||||||
mock_run.return_value = mock_result
|
mock_run.return_value = mock_result
|
||||||
|
|
||||||
result = has_changes_since_commit(Path(tmpdirname), "abcdef")
|
result = has_changes_since_commit(Path(tmpdirname), 'abcdef')
|
||||||
|
|
||||||
assert result is False
|
assert result is False
|
||||||
mock_run.assert_called_once()
|
mock_run.assert_called_once()
|
||||||
|
|
||||||
|
|
||||||
def test_solve_issue_with_no_aider_changes():
|
def test_solve_issue_with_no_aider_changes():
|
||||||
from aider_gitea import solve_issue_in_repository
|
from aider_gitea import solve_issue_in_repository
|
||||||
|
|
||||||
with tempfile.TemporaryDirectory() as tmpdirname:
|
with tempfile.TemporaryDirectory() as tmpdirname:
|
||||||
args = MagicMock()
|
args = MagicMock()
|
||||||
args.gitea_url = "https://gitea.example.com"
|
args.gitea_url = 'https://gitea.example.com'
|
||||||
args.owner = "test-owner"
|
args.owner = 'test-owner'
|
||||||
args.repo = "test-repo"
|
args.repo = 'test-repo'
|
||||||
args.base_branch = "main"
|
args.base_branch = 'main'
|
||||||
|
|
||||||
with patch('aider_gitea.run_cmd', return_value=True) as mock_run_cmd, \
|
|
||||||
patch('aider_gitea.get_current_commit_hash', return_value="abcdef") as mock_get_hash, \
|
|
||||||
patch('aider_gitea.has_changes_since_commit', return_value=False) as mock_has_changes, \
|
|
||||||
patch('aider_gitea.create_aider_command', return_value=["mock_aider_command"]) as mock_create_aider:
|
|
||||||
|
|
||||||
|
with (
|
||||||
|
patch('aider_gitea.run_cmd', return_value=True) as mock_run_cmd,
|
||||||
|
patch(
|
||||||
|
'aider_gitea.get_current_commit_hash', return_value='abcdef',
|
||||||
|
) as mock_get_hash,
|
||||||
|
patch(
|
||||||
|
'aider_gitea.has_changes_since_commit', return_value=False,
|
||||||
|
) as mock_has_changes,
|
||||||
|
patch(
|
||||||
|
'aider_gitea.create_aider_command', return_value=['mock_aider_command'],
|
||||||
|
) as mock_create_aider,
|
||||||
|
):
|
||||||
result = solve_issue_in_repository(
|
result = solve_issue_in_repository(
|
||||||
args,
|
args,
|
||||||
Path(tmpdirname),
|
Path(tmpdirname),
|
||||||
"issue-123-test",
|
'issue-123-test',
|
||||||
"Test Issue",
|
'Test Issue',
|
||||||
"Test Description",
|
'Test Description',
|
||||||
"123",
|
'123',
|
||||||
None
|
None,
|
||||||
)
|
)
|
||||||
|
|
||||||
assert result is False
|
assert result is False
|
||||||
mock_get_hash.assert_called_once()
|
mock_get_hash.assert_called_once()
|
||||||
mock_has_changes.assert_called_once_with(Path(tmpdirname), "abcdef")
|
mock_has_changes.assert_called_once_with(Path(tmpdirname), 'abcdef')
|
||||||
# Verify that the initial ruff pass was run
|
# Verify that the initial ruff pass was run
|
||||||
assert any(call_args[0][0] == ['bash', '-c', RUFF_FORMAT_AND_AUTO_FIX]
|
assert any(
|
||||||
for call_args in mock_run_cmd.call_args_list)
|
call_args[0][0] == ['bash', '-c', RUFF_FORMAT_AND_AUTO_FIX]
|
||||||
|
for call_args in mock_run_cmd.call_args_list
|
||||||
|
)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user