From 98c6ce91c3e72aca5e8a6a996dcde6524d73760c Mon Sep 17 00:00:00 2001 From: "abuzarmahmood (aider)" Date: Wed, 19 Feb 2025 18:03:50 +0000 Subject: [PATCH 1/3] feat: Add [ reset_development ] command to delete branches and tags --- src/bot_tools.py | 23 +++++++++++++++++++++++ src/branch_handler.py | 11 +++++++++++ src/git_utils.py | 12 ++++++++++++ src/response_agent.py | 12 ++++++++++-- src/triggers.py | 15 +++++++++++++++ 5 files changed, 71 insertions(+), 2 deletions(-) diff --git a/src/bot_tools.py b/src/bot_tools.py index ac9316d..2c60556 100644 --- a/src/bot_tools.py +++ b/src/bot_tools.py @@ -457,6 +457,29 @@ def run_python_script( return out +def delete_issue_branch_and_pr(issue: Issue, repo_path: str) -> None: + """ + Delete branches and pull requests related to an issue + + Args: + issue: The GitHub issue + repo_path: Path to the local repository + """ + branches = get_issue_related_branches(repo_path, issue.number) + for branch, _ in branches: + delete_branch(repo_path, branch, force=True) + +def remove_under_development_tag(issue: Issue) -> None: + """ + Remove the 'under_development' tag from an issue + + Args: + issue: The GitHub issue + """ + for label in issue.labels: + if label.name == "under_development": + issue.remove_from_labels(label) + def run_bash_script( script_path: str, ) -> str: diff --git a/src/branch_handler.py b/src/branch_handler.py index 6802bd4..5666bc3 100644 --- a/src/branch_handler.py +++ b/src/branch_handler.py @@ -112,6 +112,17 @@ def delete_branch(repo_path: str, branch_name: str, force: bool = False) -> None repo = git.Repo(repo_path) if branch_name in repo.heads: repo.delete_head(branch_name, force=force) + """ + Delete a git branch + + Args: + repo_path: Path to local git repository + branch_name: Name of branch to delete + force: If True, force delete even if not merged + """ + repo = git.Repo(repo_path) + if branch_name in repo.heads: + repo.delete_head(branch_name, force=force) def back_to_master_branch(repo_path: str) -> None: diff --git a/src/git_utils.py b/src/git_utils.py index 707d8c8..689dbdc 100644 --- a/src/git_utils.py +++ b/src/git_utils.py @@ -72,6 +72,18 @@ def search_issues(repo: Repository, query: str) -> List[Issue]: return list(repo.get_issues(state='all', labels=[query])) +def remove_label_from_issue(issue: Issue, label_name: str) -> None: + """ + Remove a label from an issue + + Args: + issue: The GitHub issue + label_name: The name of the label to remove + """ + for label in issue.labels: + if label.name == label_name: + issue.remove_from_labels(label) + def write_issue_response(issue: Issue, response_text: str) -> IssueComment: """ Write a response to an issue with the blech_bot signature diff --git a/src/response_agent.py b/src/response_agent.py index 06ff6a6..dcae69e 100644 --- a/src/response_agent.py +++ b/src/response_agent.py @@ -267,7 +267,8 @@ def check_triggers(issue: Issue) -> str: return "generate_edit_command" elif triggers.has_user_feedback(issue): return "feedback" - else: + elif triggers.has_reset_development_trigger(issue): + return "reset_development" return "new_response" @@ -307,7 +308,14 @@ def process_issue( if not ignore_checks: has_bot_mention = triggers.has_blech_bot_tag( issue) or "[ blech_bot ]" in issue.title.lower() - if not has_bot_mention: + if triggers.has_reset_development_trigger(issue): + repo_path = bot_tools.get_local_repo_path(repo_name) + bot_tools.delete_issue_branch_and_pr(issue, repo_path) + bot_tools.remove_under_development_tag(issue) + write_issue_response(issue, "Development reset successfully.") + return True, None + + elif not has_bot_mention: return False, "Issue does not have blech_bot tag or mention in title" if triggers.has_bot_response(issue) and not triggers.has_user_feedback(issue): return False, "Issue already has a bot response without feedback from user" diff --git a/src/triggers.py b/src/triggers.py index 2fb782c..2c6d6e5 100644 --- a/src/triggers.py +++ b/src/triggers.py @@ -84,6 +84,21 @@ def has_develop_issue_trigger(issue: Issue) -> bool: return "[ develop_issue ]" in comments[-1].body +def has_reset_development_trigger(issue: Issue) -> bool: + """ + Check if the latest comment contains the reset_development trigger + + Args: + issue: The GitHub issue to check + + Returns: + True if the latest comment contains "[ reset_development ]" + """ + comments = get_issue_comments(issue) + if not comments: + return False + return "[ reset_development ]" in comments[-1].body + def has_pull_request_trigger(issue: Issue) -> bool: """ Check if the latest comment contains the pull_request trigger From 0b074019a773007f2938f417363fba21005d5599 Mon Sep 17 00:00:00 2001 From: "abuzarmahmood (aider)" Date: Wed, 19 Feb 2025 18:04:00 +0000 Subject: [PATCH 2/3] fix: Resolve undefined names and import missing classes/functions in bot_tools.py --- src/bot_tools.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/bot_tools.py b/src/bot_tools.py index 2c60556..f7cd4b9 100644 --- a/src/bot_tools.py +++ b/src/bot_tools.py @@ -3,9 +3,12 @@ """ import os +from github.Issue import Issue import sys src_dir = os.path.dirname(os.path.abspath(__file__)) +from branch_handler import get_issue_related_branches, delete_branch + base_dir = os.path.dirname(src_dir) token_threshold = 100_000 @@ -286,7 +289,7 @@ def readfile( warning = (f"File exceeds token threshold of {token_threshold}. " f"Showing {len(included_lines)} of {len(data)} lines " f"({current_tokens}/{total_tokens} tokens). " - f"Use readlines({filepath}, start_line, end_line) " + f"Use readlines({file_path}, start_line, end_line) " f"to read specific ranges.") data = "".join(included_lines) From f609ded2aab15d6a999355257bbd14683afc3164 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 19 Feb 2025 18:05:01 +0000 Subject: [PATCH 3/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/bot_tools.py | 4 +++- src/git_utils.py | 1 + src/triggers.py | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/bot_tools.py b/src/bot_tools.py index f7cd4b9..b970507 100644 --- a/src/bot_tools.py +++ b/src/bot_tools.py @@ -2,12 +2,12 @@ Tools for the agents to use. """ +from branch_handler import get_issue_related_branches, delete_branch import os from github.Issue import Issue import sys src_dir = os.path.dirname(os.path.abspath(__file__)) -from branch_handler import get_issue_related_branches, delete_branch base_dir = os.path.dirname(src_dir) @@ -472,6 +472,7 @@ def delete_issue_branch_and_pr(issue: Issue, repo_path: str) -> None: for branch, _ in branches: delete_branch(repo_path, branch, force=True) + def remove_under_development_tag(issue: Issue) -> None: """ Remove the 'under_development' tag from an issue @@ -483,6 +484,7 @@ def remove_under_development_tag(issue: Issue) -> None: if label.name == "under_development": issue.remove_from_labels(label) + def run_bash_script( script_path: str, ) -> str: diff --git a/src/git_utils.py b/src/git_utils.py index 689dbdc..19aaefb 100644 --- a/src/git_utils.py +++ b/src/git_utils.py @@ -84,6 +84,7 @@ def remove_label_from_issue(issue: Issue, label_name: str) -> None: if label.name == label_name: issue.remove_from_labels(label) + def write_issue_response(issue: Issue, response_text: str) -> IssueComment: """ Write a response to an issue with the blech_bot signature diff --git a/src/triggers.py b/src/triggers.py index 2c6d6e5..77d86d2 100644 --- a/src/triggers.py +++ b/src/triggers.py @@ -99,6 +99,7 @@ def has_reset_development_trigger(issue: Issue) -> bool: return False return "[ reset_development ]" in comments[-1].body + def has_pull_request_trigger(issue: Issue) -> bool: """ Check if the latest comment contains the pull_request trigger