Skip to content

Commit 4bb779f

Browse files
committed
feat: use IssueCommentDict schema in get_issue_comments method
- Simplify get_issue_comments to use schema parameter - Remove fallback logic (handled by schema) - Update tests to expect schema parameter - Remove tests for obsolete fallback logic
1 parent b5d7d4a commit 4bb779f

2 files changed

Lines changed: 8 additions & 63 deletions

File tree

src/youtrack_rocket_mcp/api/resources/issues.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ async def search_issues(self, query: str, limit: int = 10) -> list[Issue]:
402402

403403
return issues
404404

405-
async def get_issue_comments(self, issue_id: str) -> list[JSONDict]:
405+
async def get_issue_comments(self, issue_id: str) -> list[IssueCommentDict]:
406406
"""
407407
Get comments for an issue.
408408
@@ -414,19 +414,7 @@ async def get_issue_comments(self, issue_id: str) -> list[JSONDict]:
414414
"""
415415
# Request comments with detailed author information
416416
fields = 'id,created,text,author(id,login,name)'
417-
response = await self.client.get(f'issues/{issue_id}/comments?fields={fields}')
418-
419-
# The response should be a list of comments
420-
if isinstance(response, list):
421-
return response
422-
elif isinstance(response, dict) and 'comments' in response:
423-
return response['comments']
424-
else:
425-
# Fallback: try to get comments as part of issue data
426-
issue_response = await self.client.get(f'issues/{issue_id}?fields=comments({fields})')
427-
if isinstance(issue_response, dict) and 'comments' in issue_response:
428-
return issue_response['comments']
429-
return []
417+
return await self.client.get(f'issues/{issue_id}/comments?fields={fields}', schema=list[IssueCommentDict])
430418

431419
async def add_comment(self, issue_id: str, text: str) -> IssueCommentDict:
432420
"""

tests/test_issues_api.py

Lines changed: 6 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,8 @@ async def test_create_issue_handles_api_error(issues_client, mock_client):
223223
@pytest.mark.asyncio
224224
async def test_get_issue_comments(issues_client, mock_client):
225225
"""Test getting comments for an issue."""
226+
from youtrack_rocket_mcp.api.schemas import IssueCommentDict
227+
226228
mock_response = [
227229
{
228230
'id': 'comment-1',
@@ -241,9 +243,11 @@ async def test_get_issue_comments(issues_client, mock_client):
241243

242244
result = await issues_client.get_issue_comments('TEST-1')
243245

244-
# Check API was called correctly
246+
# Check API was called correctly with schema
245247
expected_fields = 'id,created,text,author(id,login,name)'
246-
mock_client.get.assert_called_once_with(f'issues/TEST-1/comments?fields={expected_fields}')
248+
mock_client.get.assert_called_once_with(
249+
f'issues/TEST-1/comments?fields={expected_fields}', schema=list[IssueCommentDict]
250+
)
247251

248252
# Check result
249253
assert result == mock_response
@@ -253,53 +257,6 @@ async def test_get_issue_comments(issues_client, mock_client):
253257
assert result[0]['author']['login'] == 'john.doe'
254258

255259

256-
@pytest.mark.asyncio
257-
async def test_get_issue_comments_nested_response(issues_client, mock_client):
258-
"""Test getting comments when API returns nested structure."""
259-
mock_comments = [{'id': 'comment-1', 'created': 1234567890, 'text': 'Test comment'}]
260-
mock_response = {'comments': mock_comments}
261-
mock_client.get.return_value = mock_response
262-
263-
result = await issues_client.get_issue_comments('TEST-1')
264-
265-
# Check result extracts comments from nested structure
266-
assert result == mock_comments
267-
268-
269-
@pytest.mark.asyncio
270-
async def test_get_issue_comments_fallback_to_issue_data(issues_client, mock_client):
271-
"""Test fallback to getting comments from issue data."""
272-
mock_comments = [{'id': 'comment-1', 'created': 1234567890, 'text': 'Test comment'}]
273-
274-
# First call returns invalid data, second call (fallback) returns issue with comments
275-
mock_client.get.side_effect = [
276-
'invalid_response', # First call fails
277-
{'comments': mock_comments}, # Fallback call succeeds
278-
]
279-
280-
result = await issues_client.get_issue_comments('TEST-1')
281-
282-
# Check both API calls were made
283-
assert mock_client.get.call_count == 2
284-
expected_fields = 'id,created,text,author(id,login,name)'
285-
mock_client.get.assert_any_call(f'issues/TEST-1/comments?fields={expected_fields}')
286-
mock_client.get.assert_any_call(f'issues/TEST-1?fields=comments({expected_fields})')
287-
288-
# Check result
289-
assert result == mock_comments
290-
291-
292-
@pytest.mark.asyncio
293-
async def test_get_issue_comments_empty_response(issues_client, mock_client):
294-
"""Test getting comments when no comments exist."""
295-
mock_client.get.side_effect = ['invalid_response', 'invalid_response']
296-
297-
result = await issues_client.get_issue_comments('TEST-1')
298-
299-
# Should return empty list when no valid response
300-
assert result == []
301-
302-
303260
@pytest.mark.asyncio
304261
async def test_add_comment(issues_client, mock_client):
305262
"""Test adding a comment to an issue."""

0 commit comments

Comments
 (0)