Compare commits
2 Commits
9e0adccdf4
...
bfcdd1b2e5
Author | SHA1 | Date | |
---|---|---|---|
bfcdd1b2e5 | |||
9a17b6143a |
|
@ -509,9 +509,17 @@ def push_changes(
|
|||
base=repository_config.base_branch,
|
||||
labels=['aider'],
|
||||
assignee=repository_config.assignee,
|
||||
reviewer=repository_config.reviewer,
|
||||
)
|
||||
|
||||
# Add reviewer if specified (requires separate API call after PR creation)
|
||||
if repository_config.reviewer and pr_response.get('number'):
|
||||
gitea_client.add_pull_request_reviewer(
|
||||
owner=repository_config.owner,
|
||||
repo=repository_config.repo,
|
||||
pr_number=int(pr_response.get('number')),
|
||||
reviewer=repository_config.reviewer,
|
||||
)
|
||||
|
||||
# Extract PR number and URL if available
|
||||
return IssueResolution(
|
||||
True,
|
||||
|
|
|
@ -57,11 +57,11 @@ def parse_args():
|
|||
)
|
||||
parser.add_argument(
|
||||
'--assignee',
|
||||
help='Username to assign as the assignee for created pull requests',
|
||||
help='Username to automatically assign as assignee for created pull requests',
|
||||
)
|
||||
parser.add_argument(
|
||||
'--reviewer',
|
||||
help='Username to assign as the reviewer for created pull requests',
|
||||
help='Username to automatically assign as reviewer for created pull requests',
|
||||
)
|
||||
return parser.parse_args()
|
||||
|
||||
|
|
|
@ -139,10 +139,9 @@ class GiteaClient:
|
|||
head: str,
|
||||
base: str,
|
||||
labels: list[str] = None,
|
||||
assignee: str | None = None,
|
||||
reviewer: str | None = None,
|
||||
assignee: str = None,
|
||||
) -> dict:
|
||||
"""Create a pull request and optionally apply labels, assignee, and reviewer.
|
||||
"""Create a pull request and optionally apply labels.
|
||||
|
||||
Args:
|
||||
owner (str): Owner of the repository.
|
||||
|
@ -152,8 +151,7 @@ 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.
|
||||
assignee (str, optional): Username to assign as assignee for the pull request.
|
||||
|
||||
Returns:
|
||||
dict: The created pull request data.
|
||||
|
@ -169,14 +167,9 @@ 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:
|
||||
|
@ -197,6 +190,36 @@ class GiteaClient:
|
|||
response.raise_for_status()
|
||||
return response.json()
|
||||
|
||||
def add_pull_request_reviewer(
|
||||
self,
|
||||
owner: str,
|
||||
repo: str,
|
||||
pr_number: int,
|
||||
reviewer: str,
|
||||
) -> bool:
|
||||
"""Add a reviewer to an existing pull request.
|
||||
|
||||
Args:
|
||||
owner (str): Owner of the repository.
|
||||
repo (str): Name of the repository.
|
||||
pr_number (int): Number of the pull request.
|
||||
reviewer (str): Username to assign as reviewer.
|
||||
|
||||
Returns:
|
||||
bool: True if the reviewer was added successfully, False otherwise.
|
||||
|
||||
Raises:
|
||||
requests.HTTPError: If the API request fails.
|
||||
"""
|
||||
url = f'{self.gitea_url}/repos/{owner}/{repo}/pulls/{pr_number}/requested_reviewers'
|
||||
json_data = {'reviewers': [reviewer]}
|
||||
response = self.session.post(url, json=json_data)
|
||||
if response.status_code == 422:
|
||||
logger.warning('Failed to add reviewer %s to PR #%s', reviewer, pr_number)
|
||||
return False
|
||||
response.raise_for_status()
|
||||
return True
|
||||
|
||||
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'
|
||||
|
|
|
@ -1,128 +0,0 @@
|
|||
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,10 +69,9 @@ class TestClaudeCodeIntegration:
|
|||
'claude',
|
||||
'-p',
|
||||
'--output-format',
|
||||
'stream-json',
|
||||
'--debug',
|
||||
'--verbose',
|
||||
'--dangerously-skip-permissions',
|
||||
'json',
|
||||
'--max-turns',
|
||||
'10',
|
||||
issue,
|
||||
]
|
||||
assert cmd == expected
|
||||
|
@ -85,10 +84,9 @@ class TestClaudeCodeIntegration:
|
|||
'claude',
|
||||
'-p',
|
||||
'--output-format',
|
||||
'stream-json',
|
||||
'--debug',
|
||||
'--verbose',
|
||||
'--dangerously-skip-permissions',
|
||||
'json',
|
||||
'--max-turns',
|
||||
'10',
|
||||
'--model',
|
||||
'claude-3-sonnet',
|
||||
issue,
|
||||
|
|
Loading…
Reference in New Issue
Block a user