Skip to content

46 add a reset development command#57

Open
abuzarmahmood wants to merge 3 commits intomainfrom
46-add-a-reset_development-command
Open

46 add a reset development command#57
abuzarmahmood wants to merge 3 commits intomainfrom
46-add-a-reset_development-command

Conversation

@abuzarmahmood
Copy link
Owner

  • feat: Add [ reset_development ] command to delete branches and tags
  • fix: Resolve undefined names and import missing classes/functions in bot_tools.py

@abuzarmahmood abuzarmahmood linked an issue Feb 19, 2025 that may be closed by this pull request
@abuzarmahmood
Copy link
Owner Author

Generated edit command:

  • Summary of User's Issues and Requests:
    The user has requested the addition of a [ reset_development ] command to a GitHub bot. This command should perform the following actions when triggered in an issue message:

    1. Delete branches and pull requests related to the issue.
    2. Remove the under_development tag from the issue.
  • Overview of Plan to Address the Issues:
    To implement the [ reset_development ] command, the following steps will be taken:

    1. Add a new trigger detection function in triggers.py to identify the [ reset_development ] command.
    2. Implement utility functions in bot_tools.py to handle branch and PR deletion, and tag removal.
    3. Ensure branch_handler.py supports branch deletion.
    4. Update git_utils.py to support label removal.
    5. Modify the process_issue function in response_agent.py to incorporate the new trigger and call the appropriate functions.
  • Specific Details of Changes to be Made:

  1. File: triggers.py

    • Add the following function to detect the [ reset_development ] trigger:
      def has_reset_development_trigger(issue: Issue) -> bool:
          comments = get_issue_comments(issue)
          if not comments:
              return False
          return "[ reset_development ]" in comments[-1].body
  2. File: bot_tools.py

    • Add functions to delete branches and remove tags:
      def delete_issue_branch_and_pr(issue: Issue, repo_path: str) -> None:
          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:
          for label in issue.labels:
              if label.name == "under_development":
                  issue.remove_from_labels(label)
  3. File: branch_handler.py

    • Ensure it includes a function to delete branches:
      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)
  4. File: git_utils.py

    • Add a function to remove labels from issues:
      def remove_label_from_issue(issue: Issue, label_name: str) -> None:
          for label in issue.labels:
              if label.name == label_name:
                  issue.remove_from_labels(label)
  5. File: response_agent.py

    • Update the check_triggers function to include the new trigger:
      def check_triggers(issue: Issue) -> str:
          if triggers.has_reset_development_trigger(issue):
              return "reset_development"
          # Other triggers...
    • Modify the process_issue function to handle the reset_development trigger:
      def process_issue(issue: Issue, repo_name: str, ignore_checks: bool = False) -> Tuple[bool, Optional[str]]:
          try:
              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
              # Other logic...
          except Exception as e:
              return False, f"Error processing issue: {traceback.format_exc()}"

These changes will enable the bot to recognize and process the [ reset_development ] command, performing the necessary actions as specified.

TERMINATE

Aider output:

Found OPENAI_API_KEY so using gpt-4o since no --model was specified.
Aider v0.74.2
Main model: gpt-4o with diff edit format
Weak model: gpt-4o-mini
Git repo: .git with 11 files
Repo-map: using 4096 tokens, auto refresh


src/bot_tools.py

src/branch_handler.py

src/git_utils.py

src/response_agent.py

src/triggers.py
To implement the [ reset_development ] command, we will make the following changes:                                                

 1 Add a new trigger detection function in triggers.py.                                                                            
 2 Implement utility functions in bot_tools.py to handle branch and PR deletion, and tag removal.                                  
 3 Ensure branch_handler.py supports branch deletion.                                                                              
 4 Update git_utils.py to support label removal.                                                                                   
 5 Modify the process_issue function in response_agent.py to incorporate the new trigger and call the appropriate functions.       

Here are the SEARCH/REPLACE blocks for each file:                                                                                  

1. triggers.py: Add a function to detect the [ reset_development ] trigger.                                                        

src/triggers.py                                                                                                                    

                                                                                                                                   
 <<<<<<< SEARCH                                                                                                                    
 def has_pull_request_trigger(issue: Issue) -> bool:                                                                               
 =======                                                                                                                           
 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:                                                                               
 >>>>>>> REPLACE                                                                                                                   
                                                                                                                                   

2. bot_tools.py: Add functions to delete branches and remove tags.                                                                 

src/bot_tools.py                                                                                                                   

                                                                                                                                   
 <<<<<<< SEARCH                                                                                                                    
 def run_bash_script(                                                                                                              
 =======                                                                                                                           
 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(                                                                                                              
 >>>>>>> REPLACE                                                                                                                   
                                                                                                                                   

3. branch_handler.py: Ensure it includes a function to delete branches.                                                            

src/branch_handler.py                                                                                                              

                                                                                                                                   
 <<<<<<< SEARCH                                                                                                                    
 def delete_branch(repo_path: str, branch_name: str, force: bool = False) -> None:                                                 
 =======                                                                                                                           
 def delete_branch(repo_path: str, branch_name: str, force: bool = False) -> None:                                                 
     """                                                                                                                           
     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)                                                                                
                                                                                                                                   
 >>>>>>> REPLACE                                                                                                                   
                                                                                                                                   

4. git_utils.py: Add a function to remove labels from issues.                                                                      

src/git_utils.py                                                                                                                   

                                                                                                                                   
 <<<<<<< SEARCH                                                                                                                    
 def write_issue_response(issue: Issue, response_text: str) -> IssueComment:                                                       
 =======                                                                                                                           
 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:                                                       
 >>>>>>> REPLACE                                                                                                                   
                                                                                                                                   

5. response_agent.py: Update the check_triggers and process_issue functions.                                                       

src/response_agent.py                                                                                                              

                                                                                                                                   
 <<<<<<< SEARCH                                                                                                                    
     else:                                                                                                                         
 =======                                                                                                                           
     elif triggers.has_reset_development_trigger(issue):                                                                           
         return "reset_development"                                                                                                
 >>>>>>> REPLACE                                                                                                                   
                                                                                                                                   

src/response_agent.py                                                                                                              

                                                                                                                                   
 <<<<<<< SEARCH                                                                                                                    
             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:                                                                                             
 >>>>>>> REPLACE                                                                                                                   
                                                                                                                                   

These changes will enable the bot to recognize and process the [ reset_development ] command, performing the necessary actions as  
specified.                                                                                                                         

Tokens: 14k sent, 950 received. Cost: $0.04 message, $0.04 session.
Applied edit to src/response_agent.py
Applied edit to src/triggers.py
Applied edit to src/bot_tools.py
Applied edit to src/git_utils.py
Applied edit to src/branch_handler.py
Commit 98c6ce9 feat: Add [ reset_development ] command to delete branches and tags

# Fix any errors below, if possible.

## Running: /home/exouser/.local/share/uv/tools/aider-chat/bin/python -m flake8 
--select=E9,F821,F823,F831,F406,F407,F701,F702,F704,F706 --show-source --isolated src/bot_tools.py

src/bot_tools.py:346:33: F821 undefined name 'filepath'
               f"Use readlines({filepath}, start_line, end_line) "
                                ^
src/bot_tools.py:460:39: F821 undefined name 'Issue'
def delete_issue_branch_and_pr(issue: Issue, repo_path: str) -> None:
                                      ^
src/bot_tools.py:468:16: F821 undefined name 'get_issue_related_branches'
    branches = get_issue_related_branches(repo_path, issue.number)
               ^
src/bot_tools.py:470:9: F821 undefined name 'delete_branch'
        delete_branch(repo_path, branch, force=True)
        ^
src/bot_tools.py:472:41: F821 undefined name 'Issue'
def remove_under_development_tag(issue: Issue) -> None:
                                        ^

## See relevant lines below marked with █.

src/bot_tools.py:
...⋮...
298│def readlines(
299│        file_path: str,
300│        start_line: int,
301│        end_line: int,
302│) -> str:
303│    """
304│    Read lines from a file
305│
306│    Inputs:
307│        - file_path : Path to file
308│        - start_line : Start line
309│        - end_line : End line
310│
311│    Returns:
312│        - Lines from file
...⋮...
343│    warning = (f"Selected lines exceed token threshold of {token_threshold}. "
344│               f"Showing lines {start_line} to {start_line + n_included} "
345│               f"({current_tokens}/{total_tokens} tokens). "
346█               f"Use readlines({filepath}, start_line, end_line) "
347│               f"to read specific ranges.")
348│
349│    data = "".join(included_lines)
...⋮...
457│    return out
458│
459│
460█def delete_issue_branch_and_pr(issue: Issue, repo_path: str) -> None:
461│    """
462│    Delete branches and pull requests related to an issue
463│
464│    Args:
465│        issue: The GitHub issue
466│        repo_path: Path to the local repository
467│    """
468█    branches = get_issue_related_branches(repo_path, issue.number)
469│    for branch, _ in branches:
470█        delete_branch(repo_path, branch, force=True)
471│
472█def remove_under_development_tag(issue: Issue) -> None:
473│    """
474│    Remove the 'under_development' tag from an issue
475│
...⋮...


To fix the errors, we need to:                                                                                                     

 1 Correct the undefined variable filepath to file_path in the readlines function.                                                 
 2 Import the Issue class from the github module in bot_tools.py.                                                                  
 3 Import the get_issue_related_branches and delete_branch functions in bot_tools.py.                                              

Here are the SEARCH/REPLACE blocks:                                                                                                

1. Correct the undefined variable filepath to file_path.                                                                           

src/bot_tools.py                                                                                                                   

                                                                                                                                   
 <<<<<<< SEARCH                                                                                                                    
                f"Use readlines({filepath}, start_line, end_line) "                                                                
 =======                                                                                                                           
                f"Use readlines({file_path}, start_line, end_line) "                                                               
 >>>>>>> REPLACE                                                                                                                   
                                                                                                                                   

2. Import the Issue class from the github module.                                                                                  

src/bot_tools.py                                                                                                                   

                                                                                                                                   
 <<<<<<< SEARCH                                                                                                                    
 import os                                                                                                                         
 =======                                                                                                                           
 import os                                                                                                                         
 from github.Issue import Issue                                                                                                    
 >>>>>>> REPLACE                                                                                                                   
                                                                                                                                   

3. Import the get_issue_related_branches and delete_branch functions.                                                              

src/bot_tools.py                                                                                                                   

                                                                                                                                   
 <<<<<<< SEARCH                                                                                                                    
 base_dir = os.path.dirname(src_dir)                                                                                               
 =======                                                                                                                           
 from branch_handler import get_issue_related_branches, delete_branch                                                              
                                                                                                                                   
 base_dir = os.path.dirname(src_dir)                                                                                               
 >>>>>>> REPLACE                                                                                                                   
                                                                                                                                   

These changes will resolve the errors reported by Flake8.                                                                          

Tokens: 16k sent, 280 received. Cost: $0.04 message, $0.09 session.
Applied edit to src/bot_tools.py
Commit 0b07401 fix: Resolve undefined names and import missing classes/functions in bot_tools.py

# Fix any errors below, if possible.

## Running: /home/exouser/.local/share/uv/tools/aider-chat/bin/python -m flake8 
--select=E9,F821,F823,F831,F406,F407,F701,F702,F704,F706 --show-source --isolated src/bot_tools.py

src/bot_tools.py:292:33: F821 undefined name 'file_path'
               f"Use readlines({file_path}, start_line, end_line) "
                                ^
src/bot_tools.py:349:33: F821 undefined name 'filepath'
               f"Use readlines({filepath}, start_line, end_line) "
                                ^

## See relevant lines below marked with █.

src/bot_tools.py:
...⋮...
240│def readfile(
241│        filepath: str,
242│) -> str:
243│    """Read a file and return its contents with line numbers.
244│    Will return partial content if token threshold is exceeded.
245│
246│    Args:
247│        filepath: Path to file to read
248│
249│    Returns:
250│        Tuple of:
251│        - File contents with line numbers (may be truncated if exceeds threshold)
252│        - Warning message if content was truncated, None otherwise
253│
...⋮...
289│    warning = (f"File exceeds token threshold of {token_threshold}. "
290│               f"Showing {len(included_lines)} of {len(data)} lines "
291│               f"({current_tokens}/{total_tokens} tokens). "
292█               f"Use readlines({file_path}, start_line, end_line) "
293│               f"to read specific ranges.")
294│
295│    data = "".join(included_lines)
...⋮...
301│def readlines(
302│        file_path: str,
303│        start_line: int,
304│        end_line: int,
305│) -> str:
306│    """
307│    Read lines from a file
308│
309│    Inputs:
310│        - file_path : Path to file
311│        - start_line : Start line
312│        - end_line : End line
313│
314│    Returns:
315│        - Lines from file
...⋮...
346│    warning = (f"Selected lines exceed token threshold of {token_threshold}. "
347│               f"Showing lines {start_line} to {start_line + n_included} "
348│               f"({current_tokens}/{total_tokens} tokens). "
349█               f"Use readlines({filepath}, start_line, end_line) "
350│               f"to read specific ranges.")
351│
352│    data = "".join(included_lines)
...⋮...


To fix the undefined name errors, we need to ensure that the correct variable names are used in the warning messages. Here are the 
changes:                                                                                                                           

 1 Correct the undefined variable file_path to filepath in the readfile function.                                                  
 2 Correct the undefined variable filepath to file_path in the readlines function.                                                 

Here are the SEARCH/REPLACE blocks:                                                                                                

1. Correct the undefined variable file_path to filepath in the readfile function.                                                  

src/bot_tools.py                                                                                                                   

                                                                                                                                   
 <<<<<<< SEARCH                                                                                                                    
                f"Use readlines({file_path}, start_line, end_line) "                                                               
 =======                                                                                                                           
                f"Use readlines({filepath}, start_line, end_line) "                                                                
 >>>>>>> REPLACE                                                                                                                   
                                                                                                                                   

2. Correct the undefined variable filepath to file_path in the readlines function.                                                 

src/bot_tools.py                                                                                                                   

                                                                                                                                   
 <<<<<<< SEARCH                                                                                                                    
                f"Use readlines({filepath}, start_line, end_line) "                                                                
 =======                                                                                                                           
                f"Use readlines({file_path}, start_line, end_line) "                                                               
 >>>>>>> REPLACE                                                                                                                   
                                                                                                                                   

These changes will resolve the undefined name errors in src/bot_tools.py.                                                          

Tokens: 17k sent, 249 received. Cost: $0.04 message, $0.13 session.
Applied edit to src/bot_tools.py

# Fix any errors below, if possible.

## Running: /home/exouser/.local/share/uv/tools/aider-chat/bin/python -m flake8 
--select=E9,F821,F823,F831,F406,F407,F701,F702,F704,F706 --show-source --isolated src/bot_tools.py

src/bot_tools.py:292:33: F821 undefined name 'file_path'
               f"Use readlines({file_path}, start_line, end_line) "
                                ^
src/bot_tools.py:349:33: F821 undefined name 'filepath'
               f"Use readlines({filepath}, start_line, end_line) "
                                ^

## See relevant lines below marked with █.

src/bot_tools.py:
...⋮...
240│def readfile(
241│        filepath: str,
242│) -> str:
243│    """Read a file and return its contents with line numbers.
244│    Will return partial content if token threshold is exceeded.
245│
246│    Args:
247│        filepath: Path to file to read
248│
249│    Returns:
250│        Tuple of:
251│        - File contents with line numbers (may be truncated if exceeds threshold)
252│        - Warning message if content was truncated, None otherwise
253│
...⋮...
289│    warning = (f"File exceeds token threshold of {token_threshold}. "
290│               f"Showing {len(included_lines)} of {len(data)} lines "
291│               f"({current_tokens}/{total_tokens} tokens). "
292█               f"Use readlines({file_path}, start_line, end_line) "
293│               f"to read specific ranges.")
294│
295│    data = "".join(included_lines)
...⋮...
301│def readlines(
302│        file_path: str,
303│        start_line: int,
304│        end_line: int,
305│) -> str:
306│    """
307│    Read lines from a file
308│
309│    Inputs:
310│        - file_path : Path to file
311│        - start_line : Start line
312│        - end_line : End line
313│
314│    Returns:
315│        - Lines from file
...⋮...
346│    warning = (f"Selected lines exceed token threshold of {token_threshold}. "
347│               f"Showing lines {start_line} to {start_line + n_included} "
348│               f"({current_tokens}/{total_tokens} tokens). "
349█               f"Use readlines({filepath}, start_line, end_line) "
350│               f"to read specific ranges.")
351│
352│    data = "".join(included_lines)
...⋮...


To fix the undefined name errors, we need to ensure that the correct variable names are used in the warning messages. Here are the 
changes:                                                                                                                           

 1 Correct the undefined variable file_path to filepath in the readfile function.                                                  
 2 Correct the undefined variable filepath to file_path in the readlines function.                                                 

Here are the SEARCH/REPLACE blocks:                                                                                                

1. Correct the undefined variable file_path to filepath in the readfile function.                                                  

src/bot_tools.py                                                                                                                   

                                                                                                                                   
 <<<<<<< SEARCH                                                                                                                    
                f"Use readlines({file_path}, start_line, end_line) "                                                               
 =======                                                                                                                           
                f"Use readlines({filepath}, start_line, end_line) "                                                                
 >>>>>>> REPLACE                                                                                                                   
                                                                                                                                   

2. Correct the undefined variable filepath to file_path in the readlines function.                                                 

src/bot_tools.py                                                                                                                   

                                                                                                                                   
 <<<<<<< SEARCH                                                                                                                    
                f"Use readlines({filepath}, start_line, end_line) "                                                                
 =======                                                                                                                           
                f"Use readlines({file_path}, start_line, end_line) "                                                               
 >>>>>>> REPLACE                                                                                                                   
                                                                                                                                   

These changes will resolve the undefined name errors in src/bot_tools.py.                                                          

Tokens: 18k sent, 249 received. Cost: $0.05 message, $0.18 session.
Applied edit to src/bot_tools.py

# Fix any errors below, if possible.

## Running: /home/exouser/.local/share/uv/tools/aider-chat/bin/python -m flake8 
--select=E9,F821,F823,F831,F406,F407,F701,F702,F704,F706 --show-source --isolated src/bot_tools.py

src/bot_tools.py:292:33: F821 undefined name 'file_path'
               f"Use readlines({file_path}, start_line, end_line) "
                                ^
src/bot_tools.py:349:33: F821 undefined name 'filepath'
               f"Use readlines({filepath}, start_line, end_line) "
                                ^

## See relevant lines below marked with █.

src/bot_tools.py:
...⋮...
240│def readfile(
241│        filepath: str,
242│) -> str:
243│    """Read a file and return its contents with line numbers.
244│    Will return partial content if token threshold is exceeded.
245│
246│    Args:
247│        filepath: Path to file to read
248│
249│    Returns:
250│        Tuple of:
251│        - File contents with line numbers (may be truncated if exceeds threshold)
252│        - Warning message if content was truncated, None otherwise
253│
...⋮...
289│    warning = (f"File exceeds token threshold of {token_threshold}. "
290│               f"Showing {len(included_lines)} of {len(data)} lines "
291│               f"({current_tokens}/{total_tokens} tokens). "
292█               f"Use readlines({file_path}, start_line, end_line) "
293│               f"to read specific ranges.")
294│
295│    data = "".join(included_lines)
...⋮...
301│def readlines(
302│        file_path: str,
303│        start_line: int,
304│        end_line: int,
305│) -> str:
306│    """
307│    Read lines from a file
308│
309│    Inputs:
310│        - file_path : Path to file
311│        - start_line : Start line
312│        - end_line : End line
313│
314│    Returns:
315│        - Lines from file
...⋮...
346│    warning = (f"Selected lines exceed token threshold of {token_threshold}. "
347│               f"Showing lines {start_line} to {start_line + n_included} "
348│               f"({current_tokens}/{total_tokens} tokens). "
349█               f"Use readlines({filepath}, start_line, end_line) "
350│               f"to read specific ranges.")
351│
352│    data = "".join(included_lines)
...⋮...


Only 3 reflections allowed, stopping.

This response was automatically generated by blech_bot

@abuzarmahmood
Copy link
Owner Author

Skipped PR #57: PR #57 does not have blech_bot label


This response was automatically generated by blech_bot using model gpt-4o

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a [ reset_development ] command

1 participant