Compare commits
No commits in common. "issue-74-comment-on-issue-when-pull-request-fails-to-be-created" and "main" have entirely different histories.
issue-74-c
...
main
|
@ -240,9 +240,7 @@ def push_changes(
|
||||||
|
|
||||||
# Get commit messages for PR description
|
# Get commit messages for PR description
|
||||||
commit_messages = get_commit_messages(
|
commit_messages = get_commit_messages(
|
||||||
cwd,
|
cwd, repository_config.base_branch, branch_name,
|
||||||
repository_config.base_branch,
|
|
||||||
branch_name,
|
|
||||||
)
|
)
|
||||||
description = f'This pull request resolves #{issue_number}\n\n'
|
description = f'This pull request resolves #{issue_number}\n\n'
|
||||||
|
|
||||||
|
@ -253,23 +251,7 @@ def push_changes(
|
||||||
|
|
||||||
# First push the branch without creating a PR
|
# First push the branch without creating a PR
|
||||||
cmd = ['git', 'push', 'origin', branch_name, '--force']
|
cmd = ['git', 'push', 'origin', branch_name, '--force']
|
||||||
push_success = run_cmd(cmd, cwd, check=False)
|
run_cmd(cmd, cwd)
|
||||||
|
|
||||||
if not push_success:
|
|
||||||
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.',
|
|
||||||
)
|
|
||||||
except Exception as 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
|
# Then create the PR with the aider label
|
||||||
pr_response = gitea_client.create_pull_request(
|
pr_response = gitea_client.create_pull_request(
|
||||||
|
@ -284,9 +266,7 @@ def push_changes(
|
||||||
|
|
||||||
# Extract PR number and URL if available
|
# Extract PR number and URL if available
|
||||||
return IssueResolution(
|
return IssueResolution(
|
||||||
True,
|
True, str(pr_response.get('number')), pr_response.get('html_url'),
|
||||||
str(pr_response.get('number')),
|
|
||||||
pr_response.get('html_url'),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -408,9 +388,7 @@ def solve_issue_in_repository(
|
||||||
|
|
||||||
|
|
||||||
def solve_issues_in_repository(
|
def solve_issues_in_repository(
|
||||||
repository_config: RepositoryConfig,
|
repository_config: RepositoryConfig, client, seen_issues_db,
|
||||||
client,
|
|
||||||
seen_issues_db,
|
|
||||||
):
|
):
|
||||||
"""Process all open issues with the 'aider' label.
|
"""Process all open issues with the 'aider' label.
|
||||||
|
|
||||||
|
|
|
@ -168,31 +168,3 @@ 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 create_issue_comment(
|
|
||||||
self,
|
|
||||||
owner: str,
|
|
||||||
repo: str,
|
|
||||||
issue_number: str,
|
|
||||||
body: str,
|
|
||||||
) -> dict:
|
|
||||||
"""Create a comment on an issue.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
owner (str): Owner of the repository.
|
|
||||||
repo (str): Name of the repository.
|
|
||||||
issue_number (str): The issue number to comment on.
|
|
||||||
body (str): The content of the comment.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
dict: The created comment data.
|
|
||||||
|
|
||||||
Raises:
|
|
||||||
requests.HTTPError: If the API request fails.
|
|
||||||
"""
|
|
||||||
url = f'{self.gitea_url}/repos/{owner}/{repo}/issues/{issue_number}/comments'
|
|
||||||
json_data = {'body': body}
|
|
||||||
|
|
||||||
response = self.session.post(url, json=json_data)
|
|
||||||
response.raise_for_status()
|
|
||||||
return response.json()
|
|
||||||
|
|
|
@ -23,9 +23,7 @@ class TestHasCommitsOnBranch:
|
||||||
|
|
||||||
# Verify get_commit_messages was called with correct arguments
|
# Verify get_commit_messages was called with correct arguments
|
||||||
mock_get_commit_messages.assert_called_once_with(
|
mock_get_commit_messages.assert_called_once_with(
|
||||||
self.cwd,
|
self.cwd, self.base_branch, self.current_branch,
|
||||||
self.base_branch,
|
|
||||||
self.current_branch,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
@patch('aider_gitea.get_commit_messages')
|
@patch('aider_gitea.get_commit_messages')
|
||||||
|
@ -41,9 +39,7 @@ class TestHasCommitsOnBranch:
|
||||||
|
|
||||||
# Verify get_commit_messages was called with correct arguments
|
# Verify get_commit_messages was called with correct arguments
|
||||||
mock_get_commit_messages.assert_called_once_with(
|
mock_get_commit_messages.assert_called_once_with(
|
||||||
self.cwd,
|
self.cwd, self.base_branch, self.current_branch,
|
||||||
self.base_branch,
|
|
||||||
self.current_branch,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
@patch('aider_gitea.get_commit_messages')
|
@patch('aider_gitea.get_commit_messages')
|
||||||
|
|
|
@ -1,94 +0,0 @@
|
||||||
from pathlib import Path
|
|
||||||
from unittest.mock import MagicMock, patch
|
|
||||||
|
|
||||||
from aider_gitea import push_changes
|
|
||||||
|
|
||||||
|
|
||||||
class TestIssueCommentOnFailure:
|
|
||||||
def setup_method(self):
|
|
||||||
self.cwd = Path('/tmp/test-repo')
|
|
||||||
self.branch_name = 'issue-123-test-branch'
|
|
||||||
self.issue_number = '123'
|
|
||||||
self.issue_title = 'Test Issue'
|
|
||||||
self.base_branch = 'main'
|
|
||||||
self.gitea_client = MagicMock()
|
|
||||||
self.owner = 'test-owner'
|
|
||||||
self.repo = 'test-repo'
|
|
||||||
|
|
||||||
@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,
|
|
||||||
):
|
|
||||||
# Setup run_cmd to fail on git push
|
|
||||||
mock_run_cmd.return_value = False
|
|
||||||
|
|
||||||
# Call push_changes
|
|
||||||
result = push_changes(
|
|
||||||
self.cwd,
|
|
||||||
self.branch_name,
|
|
||||||
self.issue_number,
|
|
||||||
self.issue_title,
|
|
||||||
self.base_branch,
|
|
||||||
self.gitea_client,
|
|
||||||
self.owner,
|
|
||||||
self.repo,
|
|
||||||
)
|
|
||||||
|
|
||||||
# Verify result is False
|
|
||||||
assert result is False
|
|
||||||
|
|
||||||
# Verify create_issue_comment was called with appropriate message
|
|
||||||
self.gitea_client.create_issue_comment.assert_called_once()
|
|
||||||
args, kwargs = self.gitea_client.create_issue_comment.call_args
|
|
||||||
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']
|
|
||||||
|
|
||||||
@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,
|
|
||||||
):
|
|
||||||
# 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',
|
|
||||||
)
|
|
||||||
|
|
||||||
# Call push_changes
|
|
||||||
result = push_changes(
|
|
||||||
self.cwd,
|
|
||||||
self.branch_name,
|
|
||||||
self.issue_number,
|
|
||||||
self.issue_title,
|
|
||||||
self.base_branch,
|
|
||||||
self.gitea_client,
|
|
||||||
self.owner,
|
|
||||||
self.repo,
|
|
||||||
)
|
|
||||||
|
|
||||||
# Verify result is False
|
|
||||||
assert result is False
|
|
||||||
|
|
||||||
# Verify create_issue_comment was called with appropriate message
|
|
||||||
self.gitea_client.create_issue_comment.assert_called_once()
|
|
||||||
args, kwargs = self.gitea_client.create_issue_comment.call_args
|
|
||||||
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 self.branch_name in kwargs['body']
|
|
Loading…
Reference in New Issue
Block a user