From 5da0163f5382f4d228b57aaaf3a73cbd8b351229 Mon Sep 17 00:00:00 2001 From: "Abuzar Mahmood (aider)" Date: Wed, 2 Apr 2025 13:41:25 -0400 Subject: [PATCH] refactor: Remove redundant code and improve maintainability --- src/agents.py | 1 - src/bot_tools.py | 26 ++++++-------------------- src/branch_handler.py | 32 -------------------------------- src/response_agent.py | 3 --- src/triggers.py | 6 ++++-- 5 files changed, 10 insertions(+), 58 deletions(-) diff --git a/src/agents.py b/src/agents.py index 396cdf9..2bd7b27 100644 --- a/src/agents.py +++ b/src/agents.py @@ -3,7 +3,6 @@ """ import os import autogen -import subprocess from autogen import ConversableAgent, AssistantAgent, UserProxyAgent import bot_tools from git_utils import ( diff --git a/src/bot_tools.py b/src/bot_tools.py index ec89bf2..ce80136 100644 --- a/src/bot_tools.py +++ b/src/bot_tools.py @@ -78,20 +78,6 @@ def search_for_file( return "File not found" -def estimate_tokens(text: str) -> int: - """Estimate the number of tokens in text by splitting on whitespace - - Args: - text: Text to estimate tokens for - - Returns: - Estimated token count - """ - if not text: - return 0 - return len(text.split()) - - def readfile( filepath: str, ) -> str: @@ -123,9 +109,9 @@ def readfile( # Add line numbers numbered_lines = [f"{i:04}: {line}" for i, line in enumerate(data)] - # Check total tokens + # Check total tokens (estimate by splitting on whitespace) full_content = "".join(numbered_lines) - total_tokens = estimate_tokens(full_content) + total_tokens = len(full_content.split()) if full_content else 0 if total_tokens <= token_threshold: return full_content @@ -135,7 +121,7 @@ def readfile( included_lines = [] for line in numbered_lines: - line_tokens = estimate_tokens(line) + line_tokens = len(line.split()) if line else 0 if current_tokens + line_tokens > token_threshold: break included_lines.append(line) @@ -178,9 +164,9 @@ def readlines( numbered_lines = [f"{i+start_line:04}: {line}" for i, line in enumerate(lines)] - # Check total tokens + # Check total tokens (estimate by splitting on whitespace) full_content = "".join(numbered_lines) - total_tokens = estimate_tokens(full_content) + total_tokens = len(full_content.split()) if full_content else 0 if total_tokens <= token_threshold: return full_content @@ -190,7 +176,7 @@ def readlines( included_lines = [] for line in numbered_lines: - line_tokens = estimate_tokens(line) + line_tokens = len(line.split()) if line else 0 if current_tokens + line_tokens > token_threshold: break included_lines.append(line) diff --git a/src/branch_handler.py b/src/branch_handler.py index 6bc8c20..4911a23 100644 --- a/src/branch_handler.py +++ b/src/branch_handler.py @@ -72,38 +72,6 @@ def get_issue_related_branches( os.chdir(orig_dir) return related_branches -# def get_issue_related_branches(repo_path: str, issue_number: int) -> List[Tuple[str, bool]]: -# """ -# Find all branches (local and remote) related to an issue number -# -# Args: -# repo_path: Path to local git repository -# issue_number: GitHub issue number to search for -# -# Returns: -# List of tuples containing (branch_name, is_remote) -# """ -# repo = git.Repo(repo_path) -# related_branches = [] -# -# # Check local branches -# for branch in repo.heads: -# if str(issue_number) in branch.name: -# related_branches.append((branch.name, False)) -# -# # Check remote branches -# for remote in repo.remotes: -# for ref in remote.refs: -# # Skip HEAD ref -# if ref.name.endswith('/HEAD'): -# continue -# # Remove remote name prefix for comparison -# branch_name = ref.name.split('/', 1)[1] -# if str(issue_number) in branch_name: -# related_branches.append((branch_name, True)) -# -# return related_branches - def get_current_branch(repo_path: str) -> str: """ diff --git a/src/response_agent.py b/src/response_agent.py index 0c68f88..11b9428 100644 --- a/src/response_agent.py +++ b/src/response_agent.py @@ -78,9 +78,6 @@ def tab_print(x): - """ - Print with tab indentation for readability - """ """ Print with tab indentation for readability :param x: The object to print diff --git a/src/triggers.py b/src/triggers.py index d5f1da4..f91a53b 100644 --- a/src/triggers.py +++ b/src/triggers.py @@ -100,7 +100,7 @@ def has_pull_request_trigger(issue: Issue) -> bool: return "Created pull request" in comments[-1].body -def has_pr_creation_comment(issue: Issue) -> bool: +def has_pr_creation_comment(issue: Issue) -> tuple: """ Check if an issue has comments indicating a PR was created @@ -108,7 +108,9 @@ def has_pr_creation_comment(issue: Issue) -> bool: issue: The GitHub issue to check Returns: - True if the issue has PR comments, False otherwise + Tuple of (bool, comment_body or None) + - bool: True if the issue has PR comments, False otherwise + - comment_body: The body of the PR creation comment if found, None otherwise """ comments = get_issue_comments(issue) pr_comment_bool = any(