Ruff after aider
Some checks failed
Run Python tests (through Pytest) / Test (push) Failing after 25s
Verify Python project can be installed, loaded and have version checked / Test (push) Successful in 22s

This commit is contained in:
Jon Michael Aanes 2025-04-15 23:38:17 +02:00
parent 7651f44dab
commit 3065e2c3b0
4 changed files with 63 additions and 34 deletions

View File

@ -240,7 +240,9 @@ def push_changes(
# Get commit messages for PR description
commit_messages = get_commit_messages(
cwd, repository_config.base_branch, branch_name,
cwd,
repository_config.base_branch,
branch_name,
)
description = f'This pull request resolves #{issue_number}\n\n'
@ -254,17 +256,19 @@ def push_changes(
push_success = run_cmd(cmd, cwd, check=False)
if not push_success:
error_message = f"Failed to push branch `{branch_name}`. The changes could not be uploaded to the repository."
error_message = f'Failed to push branch `{branch_name}`. The changes could not be uploaded to the repository.'
logger.error(error_message)
try:
gitea_client.create_issue_comment(
owner=owner,
repo=repo,
issue_number=issue_number,
body=f"❌ **Automated Solution Failed**\n\n{error_message}\n\nPlease check repository permissions and try again."
body=f'❌ **Automated Solution Failed**\n\n{error_message}\n\nPlease check repository permissions and try again.',
)
except Exception as e:
logger.exception(f"Failed to comment on issue #{issue_number} after push failure: {e}")
logger.exception(
f'Failed to comment on issue #{issue_number} after push failure: {e}',
)
return False
# Then create the PR with the aider label
@ -280,7 +284,9 @@ def push_changes(
# Extract PR number and URL if available
return IssueResolution(
True, str(pr_response.get('number')), pr_response.get('html_url'),
True,
str(pr_response.get('number')),
pr_response.get('html_url'),
)
@ -402,7 +408,9 @@ def solve_issue_in_repository(
def solve_issues_in_repository(
repository_config: RepositoryConfig, client, seen_issues_db,
repository_config: RepositoryConfig,
client,
seen_issues_db,
):
"""Process all open issues with the 'aider' label.

View File

@ -169,7 +169,13 @@ class GiteaClient:
response.raise_for_status()
return response.json()
def create_issue_comment(self, owner: str, repo: str, issue_number: str, body: str) -> dict:
def create_issue_comment(
self,
owner: str,
repo: str,
issue_number: str,
body: str,
) -> dict:
"""Create a comment on an issue.
Args:

View File

@ -23,7 +23,9 @@ class TestHasCommitsOnBranch:
# Verify get_commit_messages was called with correct arguments
mock_get_commit_messages.assert_called_once_with(
self.cwd, self.base_branch, self.current_branch,
self.cwd,
self.base_branch,
self.current_branch,
)
@patch('aider_gitea.get_commit_messages')
@ -39,7 +41,9 @@ class TestHasCommitsOnBranch:
# Verify get_commit_messages was called with correct arguments
mock_get_commit_messages.assert_called_once_with(
self.cwd, self.base_branch, self.current_branch,
self.cwd,
self.base_branch,
self.current_branch,
)
@patch('aider_gitea.get_commit_messages')

View File

@ -1,6 +1,5 @@
import pytest
from unittest.mock import MagicMock, patch
from pathlib import Path
from unittest.mock import MagicMock, patch
from aider_gitea import push_changes
@ -19,7 +18,12 @@ class TestIssueCommentOnFailure:
@patch('aider_gitea.has_commits_on_branch', return_value=True)
@patch('aider_gitea.get_commit_messages', return_value=['Test commit'])
@patch('aider_gitea.run_cmd')
def test_comment_on_push_failure(self, mock_run_cmd, mock_get_commit_messages, mock_has_commits):
def test_comment_on_push_failure(
self,
mock_run_cmd,
mock_get_commit_messages,
mock_has_commits,
):
# Setup run_cmd to fail on git push
mock_run_cmd.return_value = False
@ -32,7 +36,7 @@ class TestIssueCommentOnFailure:
self.base_branch,
self.gitea_client,
self.owner,
self.repo
self.repo,
)
# Verify result is False
@ -44,18 +48,25 @@ class TestIssueCommentOnFailure:
assert kwargs['owner'] == self.owner
assert kwargs['repo'] == self.repo
assert kwargs['issue_number'] == self.issue_number
assert "Failed to push branch" in kwargs['body']
assert "❌ **Automated Solution Failed**" in kwargs['body']
assert 'Failed to push branch' in kwargs['body']
assert '❌ **Automated Solution Failed**' in kwargs['body']
@patch('aider_gitea.has_commits_on_branch', return_value=True)
@patch('aider_gitea.get_commit_messages', return_value=['Test commit'])
@patch('aider_gitea.run_cmd')
def test_comment_on_pr_creation_failure(self, mock_run_cmd, mock_get_commit_messages, mock_has_commits):
def test_comment_on_pr_creation_failure(
self,
mock_run_cmd,
mock_get_commit_messages,
mock_has_commits,
):
# Setup run_cmd to succeed on git push
mock_run_cmd.return_value = True
# Setup create_pull_request to fail
self.gitea_client.create_pull_request.side_effect = Exception("PR creation failed")
self.gitea_client.create_pull_request.side_effect = Exception(
'PR creation failed',
)
# Call push_changes
result = push_changes(
@ -66,7 +77,7 @@ class TestIssueCommentOnFailure:
self.base_branch,
self.gitea_client,
self.owner,
self.repo
self.repo,
)
# Verify result is False
@ -78,6 +89,6 @@ class TestIssueCommentOnFailure:
assert kwargs['owner'] == self.owner
assert kwargs['repo'] == self.repo
assert kwargs['issue_number'] == self.issue_number
assert "Failed to create pull request" in kwargs['body']
assert "⚠️ **Partial Automation Success**" in kwargs['body']
assert 'Failed to create pull request' in kwargs['body']
assert '⚠️ **Partial Automation Success**' in kwargs['body']
assert self.branch_name in kwargs['body']