From 3c94c3cfac5c0a73cb067f96dddb8d7853e15930 Mon Sep 17 00:00:00 2001
From: meeks <mi222eh@noreply.github.com>
Date: Thu, 16 Jul 2026 14:33:58 +0200
Subject: [PATCH] refactor: remove duplicate add_comment and add_label methods
 from IssueTools

- Removed duplicate dd_comment method (kept dd_comment_to_issue)
- Removed duplicate dd_label method (kept dd_label_to_issue)
- Updated dispatcher.py to remove duplicate tool registrations
- Updated coding_prompt.py to reference only dd_comment_to_issue
- Removed corresponding duplicate tests from test_issue_tools.py

This addresses section 10.1 (Confusing Naming) in bad_code.md
---
 core/coding_prompt.py      |  2 +-
 core/dispatcher.py         |  2 --
 gitea/tools/issue_tools.py | 46 +++++++++++++++++++++-----------------
 tests/test_issue_tools.py  | 44 +++++-------------------------------
 4 files changed, 33 insertions(+), 61 deletions(-)

diff --git a/core/coding_prompt.py b/core/coding_prompt.py
index 5fe58d0..cdcabc3 100644
--- a/core/coding_prompt.py
+++ b/core/coding_prompt.py
@@ -119,7 +119,7 @@ Before writing any code or making any changes, you MUST:
    - Could multiple approaches work and you're unsure which to pick?
 
 3. **If ANY uncertainty exists** — STOP and ask before implementing:
-   - Post a comment on the issue or PR (using `add_comment_to_issue` or `add_comment` tool) with your specific question(s).
+   - Post a comment on the issue or PR (using `add_comment_to_issue` tool) with your specific question(s).
    - List the approaches you are considering and ask which is preferred.
    - **Your comment MUST include the following marker on its own line at the very end:**
      ```
diff --git a/core/dispatcher.py b/core/dispatcher.py
index 1911f89..25b36b2 100644
--- a/core/dispatcher.py
+++ b/core/dispatcher.py
@@ -165,8 +165,6 @@ class TaskProcessor(ABC):
             self.pr_tools.close_pull_request,
             self.issue_tools.get_issue_comments,
             self.pr_tools.get_pull_request_comments,
-            self.issue_tools.add_comment,
-            self.issue_tools.add_label,
             self.file_tools.update_file,
             self.pr_tools.get_pull_request_diff,
             self.pr_tools.get_pull_request_patch,
diff --git a/gitea/tools/issue_tools.py b/gitea/tools/issue_tools.py
index 53994bc..5420329 100644
--- a/gitea/tools/issue_tools.py
+++ b/gitea/tools/issue_tools.py
@@ -9,7 +9,6 @@ from gitea.models import IssueModel, CommentModel, LabelModel
 logger: logging.Logger = logging.getLogger("gitea.tools.issue_tools")
 
 
-
 class IssueTools:
     """Tools for Gitea issue operations."""
 
@@ -70,7 +69,14 @@ class IssueTools:
                 repo_name = repo.name
                 issues = self._client.list_assigned_issues(owner, repo_name)
                 if issues:
-                    all_issues.extend([issue.model_dump() if hasattr(issue, 'model_dump') else issue for issue in issues])
+                    all_issues.extend(
+                        [
+                            issue.model_dump()
+                            if hasattr(issue, "model_dump")
+                            else issue
+                            for issue in issues
+                        ]
+                    )
             return all_issues
         except Exception as e:
             logger.error(f"Error listing assigned issues: {e}", exc_info=True)
@@ -86,37 +92,37 @@ class IssueTools:
         except Exception as e:
             return f"Error listing issues: {str(e)}"
 
-    def create_issue(self, owner: str, repo: str, title: str, body: str, labels: list[str] | None = None, assignees: list[str] | None = None) -> str:
+    def create_issue(
+        self,
+        owner: str,
+        repo: str,
+        title: str,
+        body: str,
+        labels: list[str] | None = None,
+        assignees: list[str] | None = None,
+    ) -> str:
         try:
-            issue = self._client.create_issue(owner, repo, title, body, labels, assignees)
+            issue = self._client.create_issue(
+                owner, repo, title, body, labels, assignees
+            )
             return f"Issue #{issue.number} created successfully in {owner}/{repo}."
         except Exception as e:
             return f"Error creating issue: {str(e)}"
 
-    def add_label_to_issue(self, owner: str, repo: str, issue_number: int, label: str) -> str:
+    def add_label_to_issue(
+        self, owner: str, repo: str, issue_number: int, label: str
+    ) -> str:
         try:
             self._client.add_label(owner, repo, issue_number, label)
             return f"Label '{label}' added to issue #{issue_number}."
         except Exception as e:
             return f"Error adding label to issue #{issue_number}: {e}"
 
-    def add_comment_to_issue(self, owner: str, repo: str, issue_number: int, body: str) -> str:
+    def add_comment_to_issue(
+        self, owner: str, repo: str, issue_number: int, body: str
+    ) -> str:
         try:
             self._client.add_comment(owner, repo, issue_number, body)
             return f"Comment added to issue #{issue_number}."
         except Exception as e:
             return f"Error adding comment to issue #{issue_number}: {e}"
-
-    def add_comment(self, owner: str, repo: str, issue_number: int, body: str) -> str:
-        try:
-            comment = self._client.add_comment(owner, repo, issue_number, body)
-            return f"Comment added to #{issue_number}."
-        except Exception as e:
-            return f"Error adding comment: {str(e)}"
-
-    def add_label(self, owner: str, repo: str, issue_number: int, label: str) -> str:
-        try:
-            self._client.add_label(owner, repo, issue_number, label)
-            return f"Label '{label}' added to #{issue_number}."
-        except Exception as e:
-            return f"Error adding label: {str(e)}"
diff --git a/tests/test_issue_tools.py b/tests/test_issue_tools.py
index de6dc3f..8b2a001 100644
--- a/tests/test_issue_tools.py
+++ b/tests/test_issue_tools.py
@@ -127,9 +127,13 @@ def test_create_issue_success() -> None:
     mock_client.create_issue.return_value = issue
 
     issue_tools: IssueTools = IssueTools(mock_client)
-    res: str = issue_tools.create_issue("owner", "repo", "Title", "Body", ["label1"], ["assignee1"])
+    res: str = issue_tools.create_issue(
+        "owner", "repo", "Title", "Body", ["label1"], ["assignee1"]
+    )
     assert res == "Issue #2 created successfully in owner/repo."
-    mock_client.create_issue.assert_called_once_with("owner", "repo", "Title", "Body", ["label1"], ["assignee1"])
+    mock_client.create_issue.assert_called_once_with(
+        "owner", "repo", "Title", "Body", ["label1"], ["assignee1"]
+    )
 
 
 def test_create_issue_failure() -> None:
@@ -175,39 +179,3 @@ def test_add_comment_to_issue_failure() -> None:
     issue_tools: IssueTools = IssueTools(mock_client)
     res: str = issue_tools.add_comment_to_issue("owner", "repo", 1, "body")
     assert "Error adding comment to issue #1: API Error" in res
-
-
-def test_add_comment_success() -> None:
-    mock_client: MagicMock = MagicMock(spec=GiteaClient)
-    mock_client.add_comment.return_value = CommentModel(id=1)
-
-    issue_tools: IssueTools = IssueTools(mock_client)
-    res: str = issue_tools.add_comment("owner", "repo", 1, "body")
-    assert res == "Comment added to #1."
-
-
-def test_add_comment_failure() -> None:
-    mock_client: MagicMock = MagicMock(spec=GiteaClient)
-    mock_client.add_comment.side_effect = Exception("API Error")
-
-    issue_tools: IssueTools = IssueTools(mock_client)
-    res: str = issue_tools.add_comment("owner", "repo", 1, "body")
-    assert "Error adding comment: API Error" in res
-
-
-def test_add_label_success() -> None:
-    mock_client: MagicMock = MagicMock(spec=GiteaClient)
-    mock_client.add_label.return_value = LabelModel(name="bug")
-
-    issue_tools: IssueTools = IssueTools(mock_client)
-    res: str = issue_tools.add_label("owner", "repo", 1, "bug")
-    assert res == "Label 'bug' added to #1."
-
-
-def test_add_label_failure() -> None:
-    mock_client: MagicMock = MagicMock(spec=GiteaClient)
-    mock_client.add_label.side_effect = Exception("API Error")
-
-    issue_tools: IssueTools = IssueTools(mock_client)
-    res: str = issue_tools.add_label("owner", "repo", 1, "bug")
-    assert "Error adding label: API Error" in res
