Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion src/bot_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
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__))

base_dir = os.path.dirname(src_dir)

token_threshold = 100_000
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -457,6 +460,31 @@ 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:
Expand Down
11 changes: 11 additions & 0 deletions src/branch_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
13 changes: 13 additions & 0 deletions src/git_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,19 @@ 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
Expand Down
12 changes: 10 additions & 2 deletions src/response_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"


Expand Down Expand Up @@ -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"
Expand Down
16 changes: 16 additions & 0 deletions src/triggers.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,22 @@ 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
Expand Down