Ruff after Claude Code
All checks were successful
Run Python tests (through Pytest) / Test (push) Successful in 26s
Verify Python project can be installed, loaded and have version checked / Test (push) Successful in 23s

This commit is contained in:
Jon Michael Aanes 2025-06-09 18:31:04 +02:00
parent 2351469c51
commit 9e0adccdf4
5 changed files with 163 additions and 7 deletions

View File

@ -156,6 +156,8 @@ class RepositoryConfig:
owner: str
repo: str
base_branch: str
assignee: str | None = None
reviewer: str | None = None
def repo_url(self) -> str:
return f'{self.gitea_url}:{self.owner}/{self.repo}.git'.replace(
@ -506,6 +508,8 @@ def push_changes(
head=branch_name,
base=repository_config.base_branch,
labels=['aider'],
assignee=repository_config.assignee,
reviewer=repository_config.reviewer,
)
# Extract PR number and URL if available

View File

@ -55,6 +55,14 @@ def parse_args():
help='Model to use for evaluating code (overrides default)',
default=None,
)
parser.add_argument(
'--assignee',
help='Username to assign as the assignee for created pull requests',
)
parser.add_argument(
'--reviewer',
help='Username to assign as the reviewer for created pull requests',
)
return parser.parse_args()
@ -84,6 +92,8 @@ def main():
owner=args.owner,
repo=repo,
base_branch=args.base_branch,
assignee=args.assignee,
reviewer=args.reviewer,
)
solve_issues_in_repository(repository_config, client, seen_issues_db)
del repo

View File

@ -139,8 +139,10 @@ class GiteaClient:
head: str,
base: str,
labels: list[str] = None,
assignee: str | None = None,
reviewer: str | None = None,
) -> dict:
"""Create a pull request and optionally apply labels.
"""Create a pull request and optionally apply labels, assignee, and reviewer.
Args:
owner (str): Owner of the repository.
@ -150,6 +152,8 @@ class GiteaClient:
head (str): The name of the branch where changes are implemented.
base (str): The name of the branch you want the changes pulled into.
labels (list[str], optional): List of label names to apply to the pull request.
assignee (str, optional): Username to assign as the assignee.
reviewer (str, optional): Username to assign as the reviewer.
Returns:
dict: The created pull request data.
@ -165,6 +169,14 @@ class GiteaClient:
'base': base,
}
# Add assignee if provided
if assignee:
json_data['assignee'] = assignee
# Add reviewer if provided
if reviewer:
json_data['reviewers'] = [reviewer]
response = self.session.post(url, json=json_data)
# If a pull request for this head/base already exists, return it instead of crashing
if response.status_code == 409:

View File

@ -0,0 +1,128 @@
from unittest.mock import MagicMock, patch
from aider_gitea.gitea_client import GiteaClient
class TestAssigneeReviewer:
def setup_method(self):
self.client = GiteaClient('https://gitea.example.com', 'fake_token')
@patch('requests.Session.post')
def test_create_pull_request_with_assignee_and_reviewer(self, mock_post):
"""Test that pull requests can be created with assignee and reviewer."""
# Mock the PR creation response
pr_response = MagicMock()
pr_response.status_code = 201
expected_result = {
'number': 123,
'title': 'Test PR',
'html_url': 'https://gitea.example.com/owner/repo/pulls/123',
}
pr_response.json.return_value = expected_result
mock_post.return_value = pr_response
# Call the method with assignee and reviewer
result = self.client.create_pull_request(
owner='owner',
repo='repo',
title='Test PR',
body='Test body',
head='feature-branch',
base='main',
assignee='john_doe',
reviewer='jane_smith',
)
# Verify PR creation call
assert mock_post.call_count == 1
pr_call_args = mock_post.call_args_list[0]
# Check URL
assert (
pr_call_args[0][0]
== 'https://gitea.example.com/api/v1/repos/owner/repo/pulls'
)
# Check request body
json_data = pr_call_args[1]['json']
assert json_data['title'] == 'Test PR'
assert json_data['assignee'] == 'john_doe'
assert json_data['reviewers'] == ['jane_smith']
# Verify the result
assert result == expected_result
@patch('requests.Session.post')
def test_create_pull_request_without_assignee_reviewer(self, mock_post):
"""Test that pull requests can be created without assignee/reviewer."""
# Mock the PR creation response
pr_response = MagicMock()
pr_response.status_code = 201
expected_result = {
'number': 124,
'title': 'Test PR',
'html_url': 'https://gitea.example.com/owner/repo/pulls/124',
}
pr_response.json.return_value = expected_result
mock_post.return_value = pr_response
# Call the method without assignee and reviewer
result = self.client.create_pull_request(
owner='owner',
repo='repo',
title='Test PR',
body='Test body',
head='feature-branch',
base='main',
)
# Verify PR creation call
assert mock_post.call_count == 1
pr_call_args = mock_post.call_args_list[0]
# Check request body
json_data = pr_call_args[1]['json']
assert json_data['title'] == 'Test PR'
assert 'assignee' not in json_data
assert 'reviewers' not in json_data
# Verify the result
assert result == expected_result
@patch('requests.Session.post')
def test_create_pull_request_with_only_assignee(self, mock_post):
"""Test that pull requests can be created with only assignee."""
# Mock the PR creation response
pr_response = MagicMock()
pr_response.status_code = 201
expected_result = {
'number': 125,
'title': 'Test PR',
'html_url': 'https://gitea.example.com/owner/repo/pulls/125',
}
pr_response.json.return_value = expected_result
mock_post.return_value = pr_response
# Call the method with only assignee
result = self.client.create_pull_request(
owner='owner',
repo='repo',
title='Test PR',
body='Test body',
head='feature-branch',
base='main',
assignee='john_doe',
)
# Verify PR creation call
assert mock_post.call_count == 1
pr_call_args = mock_post.call_args_list[0]
# Check request body
json_data = pr_call_args[1]['json']
assert json_data['title'] == 'Test PR'
assert json_data['assignee'] == 'john_doe'
assert 'reviewers' not in json_data
# Verify the result
assert result == expected_result

View File

@ -69,9 +69,10 @@ class TestClaudeCodeIntegration:
'claude',
'-p',
'--output-format',
'json',
'--max-turns',
'10',
'stream-json',
'--debug',
'--verbose',
'--dangerously-skip-permissions',
issue,
]
assert cmd == expected
@ -84,9 +85,10 @@ class TestClaudeCodeIntegration:
'claude',
'-p',
'--output-format',
'json',
'--max-turns',
'10',
'stream-json',
'--debug',
'--verbose',
'--dangerously-skip-permissions',
'--model',
'claude-3-sonnet',
issue,