Ruff
This commit is contained in:
parent
2bb7a378ab
commit
07fca9b3c2
|
@ -237,7 +237,7 @@ def push_changes(
|
|||
body=description,
|
||||
head=branch_name,
|
||||
base=base_branch,
|
||||
labels=['aider']
|
||||
labels=['aider'],
|
||||
)
|
||||
return True
|
||||
else:
|
||||
|
|
|
@ -138,7 +138,7 @@ class GiteaClient:
|
|||
body: str,
|
||||
head: str,
|
||||
base: str,
|
||||
labels: list[str] = None
|
||||
labels: list[str] = None,
|
||||
) -> dict:
|
||||
"""Create a pull request and optionally apply labels.
|
||||
|
||||
|
@ -158,12 +158,7 @@ class GiteaClient:
|
|||
requests.HTTPError: If the API request fails.
|
||||
"""
|
||||
url = f'{self.gitea_url}/repos/{owner}/{repo}/pulls'
|
||||
json_data = {
|
||||
'title': title,
|
||||
'body': body,
|
||||
'head': head,
|
||||
'base': base
|
||||
}
|
||||
json_data = {'title': title, 'body': body, 'head': head, 'base': base}
|
||||
|
||||
response = self.session.post(url, json=json_data)
|
||||
response.raise_for_status()
|
||||
|
@ -176,11 +171,7 @@ class GiteaClient:
|
|||
return pull_request
|
||||
|
||||
def add_labels_to_pull_request(
|
||||
self,
|
||||
owner: str,
|
||||
repo: str,
|
||||
pull_number: int,
|
||||
labels: list[str]
|
||||
self, owner: str, repo: str, pull_number: int, labels: list[str],
|
||||
) -> bool:
|
||||
"""Add labels to an existing pull request.
|
||||
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
import pytest
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from aider_gitea.gitea_client import GiteaClient
|
||||
|
||||
|
||||
class TestGiteaClientPRLabels:
|
||||
def setup_method(self):
|
||||
self.client = GiteaClient("https://gitea.example.com", "fake_token")
|
||||
self.client = GiteaClient('https://gitea.example.com', 'fake_token')
|
||||
|
||||
@patch('requests.Session.post')
|
||||
def test_create_pull_request_with_labels(self, mock_post):
|
||||
|
@ -15,7 +15,7 @@ class TestGiteaClientPRLabels:
|
|||
pr_response.json.return_value = {
|
||||
'number': 123,
|
||||
'title': 'Test PR',
|
||||
'html_url': 'https://gitea.example.com/owner/repo/pulls/123'
|
||||
'html_url': 'https://gitea.example.com/owner/repo/pulls/123',
|
||||
}
|
||||
|
||||
# Mock the label addition response
|
||||
|
@ -27,24 +27,30 @@ class TestGiteaClientPRLabels:
|
|||
|
||||
# Call the method with labels
|
||||
result = self.client.create_pull_request(
|
||||
owner="owner",
|
||||
repo="repo",
|
||||
title="Test PR",
|
||||
body="Test body",
|
||||
head="feature-branch",
|
||||
base="main",
|
||||
labels=["aider"]
|
||||
owner='owner',
|
||||
repo='repo',
|
||||
title='Test PR',
|
||||
body='Test body',
|
||||
head='feature-branch',
|
||||
base='main',
|
||||
labels=['aider'],
|
||||
)
|
||||
|
||||
# Verify PR creation call
|
||||
assert mock_post.call_count == 2
|
||||
pr_call_args = mock_post.call_args_list[0]
|
||||
assert pr_call_args[0][0] == 'https://gitea.example.com/api/v1/repos/owner/repo/pulls'
|
||||
assert (
|
||||
pr_call_args[0][0]
|
||||
== 'https://gitea.example.com/api/v1/repos/owner/repo/pulls'
|
||||
)
|
||||
assert pr_call_args[1]['json']['title'] == 'Test PR'
|
||||
|
||||
# Verify label addition call
|
||||
label_call_args = mock_post.call_args_list[1]
|
||||
assert label_call_args[0][0] == 'https://gitea.example.com/api/v1/repos/owner/repo/issues/123/labels'
|
||||
assert (
|
||||
label_call_args[0][0]
|
||||
== 'https://gitea.example.com/api/v1/repos/owner/repo/issues/123/labels'
|
||||
)
|
||||
assert label_call_args[1]['json']['labels'] == ['aider']
|
||||
|
||||
# Verify the result
|
||||
|
@ -60,16 +66,16 @@ class TestGiteaClientPRLabels:
|
|||
|
||||
# Call the method
|
||||
result = self.client.add_labels_to_pull_request(
|
||||
owner="owner",
|
||||
repo="repo",
|
||||
pull_number=123,
|
||||
labels=["aider", "bug"]
|
||||
owner='owner', repo='repo', pull_number=123, labels=['aider', 'bug'],
|
||||
)
|
||||
|
||||
# Verify the call
|
||||
mock_post.assert_called_once()
|
||||
call_args = mock_post.call_args
|
||||
assert call_args[0][0] == 'https://gitea.example.com/api/v1/repos/owner/repo/issues/123/labels'
|
||||
assert (
|
||||
call_args[0][0]
|
||||
== 'https://gitea.example.com/api/v1/repos/owner/repo/issues/123/labels'
|
||||
)
|
||||
assert call_args[1]['json']['labels'] == ['aider', 'bug']
|
||||
|
||||
# Verify the result
|
||||
|
|
Loading…
Reference in New Issue
Block a user