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