Ruff after Claude Code
This commit is contained in:
parent
2351469c51
commit
9e0adccdf4
|
@ -156,6 +156,8 @@ class RepositoryConfig:
|
||||||
owner: str
|
owner: str
|
||||||
repo: str
|
repo: str
|
||||||
base_branch: str
|
base_branch: str
|
||||||
|
assignee: str | None = None
|
||||||
|
reviewer: str | None = None
|
||||||
|
|
||||||
def repo_url(self) -> str:
|
def repo_url(self) -> str:
|
||||||
return f'{self.gitea_url}:{self.owner}/{self.repo}.git'.replace(
|
return f'{self.gitea_url}:{self.owner}/{self.repo}.git'.replace(
|
||||||
|
@ -506,6 +508,8 @@ def push_changes(
|
||||||
head=branch_name,
|
head=branch_name,
|
||||||
base=repository_config.base_branch,
|
base=repository_config.base_branch,
|
||||||
labels=['aider'],
|
labels=['aider'],
|
||||||
|
assignee=repository_config.assignee,
|
||||||
|
reviewer=repository_config.reviewer,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Extract PR number and URL if available
|
# Extract PR number and URL if available
|
||||||
|
|
|
@ -55,6 +55,14 @@ def parse_args():
|
||||||
help='Model to use for evaluating code (overrides default)',
|
help='Model to use for evaluating code (overrides default)',
|
||||||
default=None,
|
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()
|
return parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
|
@ -84,6 +92,8 @@ def main():
|
||||||
owner=args.owner,
|
owner=args.owner,
|
||||||
repo=repo,
|
repo=repo,
|
||||||
base_branch=args.base_branch,
|
base_branch=args.base_branch,
|
||||||
|
assignee=args.assignee,
|
||||||
|
reviewer=args.reviewer,
|
||||||
)
|
)
|
||||||
solve_issues_in_repository(repository_config, client, seen_issues_db)
|
solve_issues_in_repository(repository_config, client, seen_issues_db)
|
||||||
del repo
|
del repo
|
||||||
|
|
|
@ -139,8 +139,10 @@ class GiteaClient:
|
||||||
head: str,
|
head: str,
|
||||||
base: str,
|
base: str,
|
||||||
labels: list[str] = None,
|
labels: list[str] = None,
|
||||||
|
assignee: str | None = None,
|
||||||
|
reviewer: str | None = None,
|
||||||
) -> dict:
|
) -> dict:
|
||||||
"""Create a pull request and optionally apply labels.
|
"""Create a pull request and optionally apply labels, assignee, and reviewer.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
owner (str): Owner of the repository.
|
owner (str): Owner of the repository.
|
||||||
|
@ -150,6 +152,8 @@ class GiteaClient:
|
||||||
head (str): The name of the branch where changes are implemented.
|
head (str): The name of the branch where changes are implemented.
|
||||||
base (str): The name of the branch you want the changes pulled into.
|
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.
|
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:
|
Returns:
|
||||||
dict: The created pull request data.
|
dict: The created pull request data.
|
||||||
|
@ -165,6 +169,14 @@ class GiteaClient:
|
||||||
'base': base,
|
'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)
|
response = self.session.post(url, json=json_data)
|
||||||
# If a pull request for this head/base already exists, return it instead of crashing
|
# If a pull request for this head/base already exists, return it instead of crashing
|
||||||
if response.status_code == 409:
|
if response.status_code == 409:
|
||||||
|
|
128
test/test_assignee_reviewer.py
Normal file
128
test/test_assignee_reviewer.py
Normal 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
|
|
@ -69,9 +69,10 @@ class TestClaudeCodeIntegration:
|
||||||
'claude',
|
'claude',
|
||||||
'-p',
|
'-p',
|
||||||
'--output-format',
|
'--output-format',
|
||||||
'json',
|
'stream-json',
|
||||||
'--max-turns',
|
'--debug',
|
||||||
'10',
|
'--verbose',
|
||||||
|
'--dangerously-skip-permissions',
|
||||||
issue,
|
issue,
|
||||||
]
|
]
|
||||||
assert cmd == expected
|
assert cmd == expected
|
||||||
|
@ -84,9 +85,10 @@ class TestClaudeCodeIntegration:
|
||||||
'claude',
|
'claude',
|
||||||
'-p',
|
'-p',
|
||||||
'--output-format',
|
'--output-format',
|
||||||
'json',
|
'stream-json',
|
||||||
'--max-turns',
|
'--debug',
|
||||||
'10',
|
'--verbose',
|
||||||
|
'--dangerously-skip-permissions',
|
||||||
'--model',
|
'--model',
|
||||||
'claude-3-sonnet',
|
'claude-3-sonnet',
|
||||||
issue,
|
issue,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user