Ruff after aider
This commit is contained in:
parent
31f9964d1f
commit
7bc60d42af
|
@ -238,10 +238,12 @@ def push_changes(
|
||||||
owner=owner,
|
owner=owner,
|
||||||
repo=repo,
|
repo=repo,
|
||||||
issue_number=issue_number,
|
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:
|
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
|
return False
|
||||||
|
|
||||||
# Then create the PR with the aider label
|
# Then create the PR with the aider label
|
||||||
|
@ -257,17 +259,21 @@ def push_changes(
|
||||||
)
|
)
|
||||||
return True
|
return True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
error_message = f"Failed to create pull request for branch '{branch_name}': {str(e)}"
|
error_message = (
|
||||||
|
f"Failed to create pull request for branch '{branch_name}': {str(e)}"
|
||||||
|
)
|
||||||
logger.exception(error_message)
|
logger.exception(error_message)
|
||||||
try:
|
try:
|
||||||
gitea_client.create_issue_comment(
|
gitea_client.create_issue_comment(
|
||||||
owner=owner,
|
owner=owner,
|
||||||
repo=repo,
|
repo=repo,
|
||||||
issue_number=issue_number,
|
issue_number=issue_number,
|
||||||
body=f"❌ **Automated Solution Failed**\n\n{error_message}\n\nThe changes were pushed to branch `{branch_name}` but creating a pull request failed."
|
body=f'❌ **Automated Solution Failed**\n\n{error_message}\n\nThe changes were pushed to branch `{branch_name}` but creating a pull request failed.',
|
||||||
)
|
)
|
||||||
except Exception as comment_error:
|
except Exception as comment_error:
|
||||||
logger.exception(f"Failed to comment on issue #{issue_number} after PR creation failure: {comment_error}")
|
logger.exception(
|
||||||
|
f'Failed to comment on issue #{issue_number} after PR creation failure: {comment_error}',
|
||||||
|
)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -170,7 +170,9 @@ class GiteaClient:
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
return response.json()
|
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.
|
"""Create a comment on an issue.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import pytest
|
|
||||||
from unittest.mock import MagicMock, patch
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from unittest.mock import MagicMock, patch
|
||||||
|
|
||||||
from aider_gitea import push_changes
|
from aider_gitea import push_changes
|
||||||
|
|
||||||
|
@ -19,7 +18,9 @@ class TestIssueCommentOnFailure:
|
||||||
@patch('aider_gitea.run_cmd', return_value=False)
|
@patch('aider_gitea.run_cmd', return_value=False)
|
||||||
@patch('aider_gitea.has_commits_on_branch', return_value=True)
|
@patch('aider_gitea.has_commits_on_branch', return_value=True)
|
||||||
@patch('aider_gitea.get_commit_messages', return_value=['Test commit'])
|
@patch('aider_gitea.get_commit_messages', return_value=['Test commit'])
|
||||||
def test_comment_on_push_failure(self, mock_get_commit_messages, mock_has_commits, mock_run_cmd):
|
def test_comment_on_push_failure(
|
||||||
|
self, mock_get_commit_messages, mock_has_commits, mock_run_cmd,
|
||||||
|
):
|
||||||
"""Test that a comment is added to the issue when git push fails."""
|
"""Test that a comment is added to the issue when git push fails."""
|
||||||
result = push_changes(
|
result = push_changes(
|
||||||
self.cwd,
|
self.cwd,
|
||||||
|
@ -35,15 +36,19 @@ class TestIssueCommentOnFailure:
|
||||||
assert result is False
|
assert result is False
|
||||||
self.gitea_client.create_issue_comment.assert_called_once()
|
self.gitea_client.create_issue_comment.assert_called_once()
|
||||||
comment_body = self.gitea_client.create_issue_comment.call_args[1]['body']
|
comment_body = self.gitea_client.create_issue_comment.call_args[1]['body']
|
||||||
assert "Failed to push branch" in comment_body
|
assert 'Failed to push branch' in comment_body
|
||||||
assert "❌ **Automated Solution Failed**" in comment_body
|
assert '❌ **Automated Solution Failed**' in comment_body
|
||||||
|
|
||||||
@patch('aider_gitea.run_cmd', return_value=True)
|
@patch('aider_gitea.run_cmd', return_value=True)
|
||||||
@patch('aider_gitea.has_commits_on_branch', return_value=True)
|
@patch('aider_gitea.has_commits_on_branch', return_value=True)
|
||||||
@patch('aider_gitea.get_commit_messages', return_value=['Test commit'])
|
@patch('aider_gitea.get_commit_messages', return_value=['Test commit'])
|
||||||
def test_comment_on_pr_creation_failure(self, mock_get_commit_messages, mock_has_commits, mock_run_cmd):
|
def test_comment_on_pr_creation_failure(
|
||||||
|
self, mock_get_commit_messages, mock_has_commits, mock_run_cmd,
|
||||||
|
):
|
||||||
"""Test that a comment is added to the issue when PR creation fails."""
|
"""Test that a comment is added to the issue when PR creation fails."""
|
||||||
self.gitea_client.create_pull_request.side_effect = Exception("PR creation failed")
|
self.gitea_client.create_pull_request.side_effect = Exception(
|
||||||
|
'PR creation failed',
|
||||||
|
)
|
||||||
|
|
||||||
result = push_changes(
|
result = push_changes(
|
||||||
self.cwd,
|
self.cwd,
|
||||||
|
@ -59,17 +64,23 @@ class TestIssueCommentOnFailure:
|
||||||
assert result is False
|
assert result is False
|
||||||
self.gitea_client.create_issue_comment.assert_called_once()
|
self.gitea_client.create_issue_comment.assert_called_once()
|
||||||
comment_body = self.gitea_client.create_issue_comment.call_args[1]['body']
|
comment_body = self.gitea_client.create_issue_comment.call_args[1]['body']
|
||||||
assert "Failed to create pull request" in comment_body
|
assert 'Failed to create pull request' in comment_body
|
||||||
assert "❌ **Automated Solution Failed**" in comment_body
|
assert '❌ **Automated Solution Failed**' in comment_body
|
||||||
assert self.branch_name in comment_body
|
assert self.branch_name in comment_body
|
||||||
|
|
||||||
@patch('aider_gitea.run_cmd', return_value=True)
|
@patch('aider_gitea.run_cmd', return_value=True)
|
||||||
@patch('aider_gitea.has_commits_on_branch', return_value=True)
|
@patch('aider_gitea.has_commits_on_branch', return_value=True)
|
||||||
@patch('aider_gitea.get_commit_messages', return_value=['Test commit'])
|
@patch('aider_gitea.get_commit_messages', return_value=['Test commit'])
|
||||||
def test_comment_failure_handled(self, mock_get_commit_messages, mock_has_commits, mock_run_cmd):
|
def test_comment_failure_handled(
|
||||||
|
self, mock_get_commit_messages, mock_has_commits, mock_run_cmd,
|
||||||
|
):
|
||||||
"""Test that exceptions during commenting are properly handled."""
|
"""Test that exceptions during commenting are properly handled."""
|
||||||
self.gitea_client.create_pull_request.side_effect = Exception("PR creation failed")
|
self.gitea_client.create_pull_request.side_effect = Exception(
|
||||||
self.gitea_client.create_issue_comment.side_effect = Exception("Comment creation failed")
|
'PR creation failed',
|
||||||
|
)
|
||||||
|
self.gitea_client.create_issue_comment.side_effect = Exception(
|
||||||
|
'Comment creation failed',
|
||||||
|
)
|
||||||
|
|
||||||
# This should not raise an exception
|
# This should not raise an exception
|
||||||
result = push_changes(
|
result = push_changes(
|
||||||
|
|
Loading…
Reference in New Issue
Block a user