refactor: break up create_gitea_issue_via_mcp into helpers (#647)
Co-authored-by: Kimi Agent <kimi@timmy.local> Co-committed-by: Kimi Agent <kimi@timmy.local>
This commit is contained in:
@@ -205,9 +205,9 @@ def _bridge_to_work_order(title: str, body: str, category: str) -> None:
|
||||
|
||||
|
||||
async def _ensure_issue_session():
|
||||
"""Lazily create and connect the module-level MCP issue session.
|
||||
"""Get or create the cached MCP session, connecting if needed.
|
||||
|
||||
Returns the connected ``MCPTools`` instance or raises on failure.
|
||||
Returns the connected ``MCPTools`` instance.
|
||||
"""
|
||||
from agno.tools.mcp import MCPTools
|
||||
|
||||
@@ -226,18 +226,18 @@ async def _ensure_issue_session():
|
||||
return _issue_session
|
||||
|
||||
|
||||
def _build_issue_args(title: str, body: str) -> dict:
|
||||
"""Build the ``issue_write`` tool arguments dict.
|
||||
|
||||
Appends the auto-filing signature and parses owner/repo from settings.
|
||||
"""
|
||||
def _build_issue_body(body: str) -> str:
|
||||
"""Append the auto-filing signature to the issue body."""
|
||||
full_body = body
|
||||
if full_body:
|
||||
full_body += "\n\n"
|
||||
full_body += "---\n*Auto-filed by Timmy's thinking engine*"
|
||||
return full_body
|
||||
|
||||
|
||||
def _build_issue_args(title: str, full_body: str) -> dict:
|
||||
"""Build MCP tool arguments for ``issue_write`` with method=create."""
|
||||
owner, repo = settings.gitea_repo.split("/", 1)
|
||||
|
||||
return {
|
||||
"method": "create",
|
||||
"owner": owner,
|
||||
@@ -272,7 +272,9 @@ async def create_gitea_issue_via_mcp(title: str, body: str = "", labels: str = "
|
||||
|
||||
try:
|
||||
session = await _ensure_issue_session()
|
||||
args = _build_issue_args(title, body)
|
||||
full_body = _build_issue_body(body)
|
||||
args = _build_issue_args(title, full_body)
|
||||
|
||||
result = await session.session.call_tool("issue_write", arguments=args)
|
||||
|
||||
_bridge_to_work_order(title, body, _category_from_labels(labels))
|
||||
|
||||
@@ -6,6 +6,9 @@ import pytest
|
||||
|
||||
from timmy.mcp_tools import (
|
||||
_bridge_to_work_order,
|
||||
_build_issue_args,
|
||||
_build_issue_body,
|
||||
_category_from_labels,
|
||||
_generate_avatar_image,
|
||||
_parse_command,
|
||||
close_mcp_sessions,
|
||||
@@ -132,6 +135,49 @@ def test_filesystem_mcp_returns_tools():
|
||||
assert "/home/user/project" in params_kwargs["args"]
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# _build_issue_body / _build_issue_args / _category_from_labels
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
def test_build_issue_body_appends_signature():
|
||||
"""_build_issue_body appends the auto-filing signature."""
|
||||
result = _build_issue_body("Some description")
|
||||
assert result.startswith("Some description\n\n")
|
||||
assert "Auto-filed by Timmy" in result
|
||||
|
||||
|
||||
def test_build_issue_body_empty():
|
||||
"""_build_issue_body handles empty body."""
|
||||
result = _build_issue_body("")
|
||||
assert result.startswith("---\n")
|
||||
|
||||
|
||||
def test_build_issue_args():
|
||||
"""_build_issue_args returns correct MCP arguments."""
|
||||
with patch("timmy.mcp_tools.settings") as mock_settings:
|
||||
mock_settings.gitea_repo = "owner/repo"
|
||||
result = _build_issue_args("Title", "Body")
|
||||
assert result == {
|
||||
"method": "create",
|
||||
"owner": "owner",
|
||||
"repo": "repo",
|
||||
"title": "Title",
|
||||
"body": "Body",
|
||||
}
|
||||
|
||||
|
||||
def test_category_from_labels_bug():
|
||||
"""_category_from_labels returns 'bug' when labels contain bug."""
|
||||
assert _category_from_labels("bug, enhancement") == "bug"
|
||||
|
||||
|
||||
def test_category_from_labels_default():
|
||||
"""_category_from_labels returns 'suggestion' by default."""
|
||||
assert _category_from_labels("enhancement") == "suggestion"
|
||||
assert _category_from_labels("") == "suggestion"
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# create_gitea_issue_via_mcp
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user