Compare commits
2 Commits
bfcdd1b2e5
...
9e0adccdf4
Author | SHA1 | Date | |
---|---|---|---|
9e0adccdf4 | |||
2351469c51 |
|
@ -509,17 +509,9 @@ def push_changes(
|
||||||
base=repository_config.base_branch,
|
base=repository_config.base_branch,
|
||||||
labels=['aider'],
|
labels=['aider'],
|
||||||
assignee=repository_config.assignee,
|
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
|
# Extract PR number and URL if available
|
||||||
return IssueResolution(
|
return IssueResolution(
|
||||||
True,
|
True,
|
||||||
|
|
|
@ -57,11 +57,11 @@ def parse_args():
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--assignee',
|
'--assignee',
|
||||||
help='Username to automatically assign as assignee for created pull requests',
|
help='Username to assign as the assignee for created pull requests',
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--reviewer',
|
'--reviewer',
|
||||||
help='Username to automatically assign as reviewer for created pull requests',
|
help='Username to assign as the reviewer for created pull requests',
|
||||||
)
|
)
|
||||||
return parser.parse_args()
|
return parser.parse_args()
|
||||||
|
|
||||||
|
|
|
@ -139,9 +139,10 @@ class GiteaClient:
|
||||||
head: str,
|
head: str,
|
||||||
base: str,
|
base: str,
|
||||||
labels: list[str] = None,
|
labels: list[str] = None,
|
||||||
assignee: 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.
|
||||||
|
@ -151,7 +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 assignee for 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.
|
||||||
|
@ -167,9 +169,14 @@ class GiteaClient:
|
||||||
'base': base,
|
'base': base,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Add assignee if provided
|
||||||
if assignee:
|
if assignee:
|
||||||
json_data['assignee'] = 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:
|
||||||
|
@ -190,36 +197,6 @@ class GiteaClient:
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
return response.json()
|
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]:
|
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."""
|
"""Fetch pipeline runs for a PR and return IDs of failed runs."""
|
||||||
url = f'{self.gitea_url}/repos/{owner}/{repo}/actions/runs'
|
url = f'{self.gitea_url}/repos/{owner}/{repo}/actions/runs'
|
||||||
|
|
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