From 9e0adccdf407bcb8c52887611cb1b42a1eb151a2 Mon Sep 17 00:00:00 2001 From: Jon Michael Aanes Date: Mon, 9 Jun 2025 18:31:04 +0200 Subject: [PATCH] Ruff after Claude Code --- aider_gitea/__init__.py | 4 + aider_gitea/__main__.py | 10 +++ aider_gitea/gitea_client.py | 14 ++- test/test_assignee_reviewer.py | 128 +++++++++++++++++++++++++++ test/test_claude_code_integration.py | 14 +-- 5 files changed, 163 insertions(+), 7 deletions(-) create mode 100644 test/test_assignee_reviewer.py diff --git a/aider_gitea/__init__.py b/aider_gitea/__init__.py index 9fe3f23..ebd4b57 100644 --- a/aider_gitea/__init__.py +++ b/aider_gitea/__init__.py @@ -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 diff --git a/aider_gitea/__main__.py b/aider_gitea/__main__.py index e9ab35e..83bc582 100644 --- a/aider_gitea/__main__.py +++ b/aider_gitea/__main__.py @@ -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 diff --git a/aider_gitea/gitea_client.py b/aider_gitea/gitea_client.py index bf90768..21badc8 100644 --- a/aider_gitea/gitea_client.py +++ b/aider_gitea/gitea_client.py @@ -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: diff --git a/test/test_assignee_reviewer.py b/test/test_assignee_reviewer.py new file mode 100644 index 0000000..8f427f3 --- /dev/null +++ b/test/test_assignee_reviewer.py @@ -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 diff --git a/test/test_claude_code_integration.py b/test/test_claude_code_integration.py index 9229225..ad83669 100644 --- a/test/test_claude_code_integration.py +++ b/test/test_claude_code_integration.py @@ -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,