Compare commits

..

2 Commits

Author SHA1 Message Date
9e0adccdf4 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
2025-06-09 18:31:04 +02:00
2351469c51 Initial ruff pass 2025-06-09 18:27:08 +02:00
4 changed files with 144 additions and 68 deletions

View File

@ -499,12 +499,7 @@ def push_changes(
cmd = ['git', 'push', 'origin', branch_name, '--force']
run_cmd(cmd, cwd)
# Prepare assignees list
assignees = []
if repository_config.assignee:
assignees.append(repository_config.assignee)
# Then create the PR with the aider label and assignees
# Then create the PR with the aider label
pr_response = gitea_client.create_pull_request(
owner=repository_config.owner,
repo=repository_config.repo,
@ -513,39 +508,15 @@ def push_changes(
head=branch_name,
base=repository_config.base_branch,
labels=['aider'],
assignees=assignees if assignees else None,
assignee=repository_config.assignee,
reviewer=repository_config.reviewer,
)
# Extract PR number
pr_number = int(pr_response.get('number'))
# Assign reviewer if specified (must be done after PR creation)
if repository_config.reviewer:
try:
gitea_client.assign_reviewers(
owner=repository_config.owner,
repo=repository_config.repo,
pull_number=pr_number,
reviewers=[repository_config.reviewer],
)
logger.info(
'Assigned reviewer %s to PR #%s',
repository_config.reviewer,
pr_number,
)
except Exception:
logger.warning(
'Failed to assign reviewer %s to PR #%s',
repository_config.reviewer,
pr_number,
exc_info=True,
)
# Extract PR number and URL if available
return IssueResolution(
True,
pr_response.get('html_url'),
pr_number,
int(pr_response.get('number')),
)

View File

@ -58,12 +58,10 @@ def parse_args():
parser.add_argument(
'--assignee',
help='Username to assign as the assignee for created pull requests',
default=None,
)
parser.add_argument(
'--reviewer',
help='Username to assign as the reviewer for created pull requests',
default=None,
)
return parser.parse_args()

View File

@ -139,9 +139,10 @@ class GiteaClient:
head: str,
base: str,
labels: list[str] = None,
assignees: list[str] = None,
assignee: str | None = None,
reviewer: str | None = None,
) -> dict:
"""Create a pull request and optionally apply labels and assignees.
"""Create a pull request and optionally apply labels, assignee, and reviewer.
Args:
owner (str): Owner of the repository.
@ -151,7 +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.
assignees (list[str], optional): List of usernames to assign 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.
@ -167,8 +169,13 @@ class GiteaClient:
'base': base,
}
if assignees:
json_data['assignees'] = assignees
# 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
@ -190,34 +197,6 @@ class GiteaClient:
response.raise_for_status()
return response.json()
def assign_reviewers(
self,
owner: str,
repo: str,
pull_number: int,
reviewers: list[str],
) -> dict:
"""Assign reviewers to an existing pull request.
Args:
owner (str): Owner of the repository.
repo (str): Name of the repository.
pull_number (int): Number of the pull request.
reviewers (list[str]): List of usernames to assign as reviewers.
Returns:
dict: The response data from the API.
Raises:
requests.HTTPError: If the API request fails.
"""
url = f'{self.gitea_url}/repos/{owner}/{repo}/pulls/{pull_number}/requested_reviewers'
json_data = {'reviewers': reviewers}
response = self.session.post(url, json=json_data)
response.raise_for_status()
return response.json()
def get_failed_pipelines(self, owner: str, repo: str, pr_number: str) -> list[int]:
"""Fetch pipeline runs for a PR and return IDs of failed runs."""
url = f'{self.gitea_url}/repos/{owner}/{repo}/actions/runs'

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