Skip to content

80 instead of checking comments and tags independently on every run compare issue timeline to cached version to detect changes#81

Open
abuzarmahmood wants to merge 3 commits intomainfrom
80-instead-of-checking-comments-and-tags-independently-on-every-run-compare-issue-timeline-to-cached-version-to-detect-changes
Open

80 instead of checking comments and tags independently on every run compare issue timeline to cached version to detect changes#81
abuzarmahmood wants to merge 3 commits intomainfrom
80-instead-of-checking-comments-and-tags-independently-on-every-run-compare-issue-timeline-to-cached-version-to-detect-changes

Conversation

@abuzarmahmood
Copy link
Owner

  • feat: Implement issue timeline caching mechanism for efficient GitHub issue processing
  • fix: Replace undefined pull_request with out_thread in error handling

@abuzarmahmood
Copy link
Owner Author

Generated edit command:

  • Summary of User's Issues and Requests:
    The user wants to optimize the process of checking comments and tags on GitHub issues by comparing the issue timeline to a cached version to detect changes. If changes are detected, the rest of the detailed trigger checks should be executed.

  • Overview of Plan to Address the Issues:

    1. Implement a caching mechanism to store the timeline of an issue.
    2. Compare the current timeline with the cached version to detect changes.
    3. If changes are detected, proceed with the detailed trigger checks.
    4. Add logic to save and load cached timelines for each issue to maintain the cache across different runs.
  • Specific Details of Changes to be Made:

    1. Implement Caching Mechanism:

      • File: git_utils.py
      • Description: Implement a function to cache the timeline of an issue and compare it with the current timeline to detect changes.
      • Code Snippet:
        def cache_issue_timeline(issue: Issue, cache: Dict[int, List]) -> bool:
            """
            Cache the timeline of an issue and compare with the current timeline.
        
            Args:
                issue: The GitHub issue to check
                cache: A dictionary to store cached timelines
        
            Returns:
                True if changes are detected, False otherwise
            """
            current_timeline = list(issue.get_timeline())
            issue_number = issue.number
        
            if issue_number not in cache:
                cache[issue_number] = current_timeline
                return True
        
            cached_timeline = cache[issue_number]
            if current_timeline != cached_timeline:
                cache[issue_number] = current_timeline
                return True
        
            return False
    2. Integrate Caching in Trigger Checks:

      • File: triggers.py
      • Description: Use the caching function to determine if detailed trigger checks should be executed.
      • Code Snippet:
        from git_utils import cache_issue_timeline
        
        def should_run_detailed_checks(issue: Issue, cache: Dict[int, List]) -> bool:
            """
            Determine if detailed trigger checks should be run based on timeline changes.
        
            Args:
                issue: The GitHub issue to check
                cache: A dictionary to store cached timelines
        
            Returns:
                True if detailed checks should be run, False otherwise
            """
            return cache_issue_timeline(issue, cache)
    3. Update Main Execution Logic:

      • File: triggers.py
      • Description: Integrate the caching mechanism into the main execution flow to decide when to run detailed checks.
      • Code Snippet:
        def main():
            client = get_github_client()
            repo = get_repository(client, 'abuzarmahmood/blech_github_bot')
            issues = get_open_issues(repo)
            cache = {}
        
            for issue in issues:
                if should_run_detailed_checks(issue, cache):
                    # Run detailed trigger checks
                    pass
    4. Implement Cache Persistence:

      • File: git_utils.py
      • Description: Implement functions to save the cache to a file and load it from a file.
      • Code Snippet:
        import json
        import os
        
        CACHE_FILE = 'issue_cache.json'
        
        def save_cache_to_file(cache: Dict[int, List]) -> None:
            """Save the cache to a file."""
            with open(CACHE_FILE, 'w') as f:
                json.dump(cache, f)
        
        def load_cache_from_file() -> Dict[int, List]:
            """Load the cache from a file."""
            if os.path.exists(CACHE_FILE):
                with open(CACHE_FILE, 'r') as f:
                    return json.load(f)
            return {}
    5. Integrate Cache Persistence in Trigger Checks:

      • File: triggers.py
      • Description: Use the cache persistence functions to load the cache at the start and save it at the end of the script.
      • Code Snippet:
        from git_utils import cache_issue_timeline, save_cache_to_file, load_cache_from_file
        
        def should_run_detailed_checks(issue: Issue, cache: Dict[int, List]) -> bool:
            """
            Determine if detailed trigger checks should be run based on timeline changes.
        
            Args:
                issue: The GitHub issue to check
                cache: A dictionary to store cached timelines
        
            Returns:
                True if detailed checks should be run, False otherwise
            """
            return cache_issue_timeline(issue, cache)
        
        def main():
            client = get_github_client()
            repo = get_repository(client, 'abuzarmahmood/blech_github_bot')
            issues = get_open_issues(repo)
            cache = load_cache_from_file()
        
            for issue in issues:
                if should_run_detailed_checks(issue, cache):
                    # Run detailed trigger checks
                    pass
        
            save_cache_to_file(cache)

These changes aim to ensure that the system efficiently detects changes in issue timelines and maintains the cache across different runs, optimizing performance and resource usage.

TERMINATE

Aider output:

Aider v0.75.1
Main model: anthropic/claude-3-7-sonnet-20250219 with diff edit format, infinite output
Weak model: anthropic/claude-3-5-haiku-20241022
Git repo: .git with 11 files
Repo-map: using 4096 tokens, auto refresh


src/git_utils.py

src/triggers.py
I'll implement the caching mechanism to optimize the process of checking comments and tags on GitHub issues. The changes will focus on comparing the issue timeline to a cached version to detect changes, and only executing detailed trigger   
checks when necessary.                                                                                                                                                                                                                           

Let's make the following changes:                                                                                                                                                                                                                

 1 First, let's add the caching functions to git_utils.py:                                                                                                                                                                                       

src/git_utils.py                                                                                                                                                                                                                                 

                                                                                                                                                                                                                                                 
 <<<<<<< SEARCH                                                                                                                                                                                                                                  
 """                                                                                                                                                                                                                                             
 Utility functions for interacting with GitHub API                                                                                                                                                                                               
 """                                                                                                                                                                                                                                             
 from typing import List, Dict, Optional, Tuple                                                                                                                                                                                                  
 =======                                                                                                                                                                                                                                         
 """                                                                                                                                                                                                                                             
 Utility functions for interacting with GitHub API                                                                                                                                                                                               
 """                                                                                                                                                                                                                                             
 from typing import List, Dict, Optional, Tuple, Any                                                                                                                                                                                             
 import json                                                                                                                                                                                                                                     
 import pickle                                                                                                                                                                                                                                   
 =======                                                                                                                                                                                                                                         
 >>>>>>> REPLACE                                                                                                                                                                                                                                 
                                                                                                                                                                                                                                                 

src/git_utils.py                                                                                                                                                                                                                                 

                                                                                                                                                                                                                                                 
 <<<<<<< SEARCH                                                                                                                                                                                                                                  
 if __name__ == '__main__':                                                                                                                                                                                                                      
     client = get_github_client()                                                                                                                                                                                                                
     repo = get_repository(client, 'katzlabbrandeis/blech_clust')                                                                                                                                                                                
     issues = get_open_issues(repo)                                                                                                                                                                                                              
     print(f"Found {len(issues)} open issues")                                                                                                                                                                                                   
     for issue in issues:                                                                                                                                                                                                                        
         print(get_issue_details(issue))                                                                                                                                                                                                         
         comments = get_issue_comments(issue)                                                                                                                                                                                                    
         for comment in comments:                                                                                                                                                                                                                
             print(f"Comment by {comment.user.login}: {comment.body}")                                                                                                                                                                           
 =======                                                                                                                                                                                                                                         
 def get_issue_timeline_hash(issue: Issue) -> str:                                                                                                                                                                                               
     """                                                                                                                                                                                                                                         
     Generate a hash representing the current state of an issue's timeline                                                                                                                                                                       
                                                                                                                                                                                                                                                 
     Args:                                                                                                                                                                                                                                       
         issue: The GitHub issue to check                                                                                                                                                                                                        
                                                                                                                                                                                                                                                 
     Returns:                                                                                                                                                                                                                                    
         A string hash representing the current state of the issue's timeline                                                                                                                                                                    
     """                                                                                                                                                                                                                                         
     # Get comments and their timestamps                                                                                                                                                                                                         
     comments = get_issue_comments(issue)                                                                                                                                                                                                        
     comment_data = [(c.id, c.updated_at.timestamp()) for c in comments]                                                                                                                                                                         
                                                                                                                                                                                                                                                 
     # Get issue details that might change                                                                                                                                                                                                       
     issue_data = {                                                                                                                                                                                                                              
         'updated_at': issue.updated_at.timestamp(),                                                                                                                                                                                             
         'state': issue.state,                                                                                                                                                                                                                   
         'labels': [label.name for label in issue.labels],                                                                                                                                                                                       
         'comments_count': issue.comments                                                                                                                                                                                                        
     }                                                                                                                                                                                                                                           
                                                                                                                                                                                                                                                 
     # Combine all data and create a hash                                                                                                                                                                                                        
     import hashlib                                                                                                                                                                                                                              
     combined_data = str(comment_data) + str(issue_data)                                                                                                                                                                                         
     return hashlib.md5(combined_data.encode()).hexdigest()                                                                                                                                                                                      
                                                                                                                                                                                                                                                 
                                                                                                                                                                                                                                                 
 def cache_issue_timeline(issue: Issue, cache: Dict[int, str]) -> bool:                                                                                                                                                                          
     """                                                                                                                                                                                                                                         
     Cache the timeline of an issue and compare with the current timeline.                                                                                                                                                                       
                                                                                                                                                                                                                                                 
     Args:                                                                                                                                                                                                                                       
         issue: The GitHub issue to check                                                                                                                                                                                                        
         cache: A dictionary to store cached timeline hashes                                                                                                                                                                                     
                                                                                                                                                                                                                                                 
     Returns:                                                                                                                                                                                                                                    
         True if changes are detected, False otherwise                                                                                                                                                                                           
     """                                                                                                                                                                                                                                         
     issue_number = issue.number                                                                                                                                                                                                                 
     current_hash = get_issue_timeline_hash(issue)                                                                                                                                                                                               
                                                                                                                                                                                                                                                 
     if issue_number not in cache:                                                                                                                                                                                                               
         cache[issue_number] = current_hash                                                                                                                                                                                                      
         return True                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                 
     cached_hash = cache[issue_number]                                                                                                                                                                                                           
     if current_hash != cached_hash:                                                                                                                                                                                                             
         cache[issue_number] = current_hash                                                                                                                                                                                                      
         return True                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                 
     return False                                                                                                                                                                                                                                
                                                                                                                                                                                                                                                 
                                                                                                                                                                                                                                                 
 def save_cache_to_file(cache: Dict[int, str], filename: str = 'issue_cache.pkl') -> None:                                                                                                                                                       
     """                                                                                                                                                                                                                                         
     Save the cache to a file.                                                                                                                                                                                                                   
                                                                                                                                                                                                                                                 
     Args:                                                                                                                                                                                                                                       
         cache: The cache dictionary to save                                                                                                                                                                                                     
         filename: The name of the file to save the cache to                                                                                                                                                                                     
     """                                                                                                                                                                                                                                         
     with open(filename, 'wb') as f:                                                                                                                                                                                                             
         pickle.dump(cache, f)                                                                                                                                                                                                                   
                                                                                                                                                                                                                                                 
                                                                                                                                                                                                                                                 
 def load_cache_from_file(filename: str = 'issue_cache.pkl') -> Dict[int, str]:                                                                                                                                                                  
     """                                                                                                                                                                                                                                         
     Load the cache from a file.                                                                                                                                                                                                                 
                                                                                                                                                                                                                                                 
     Args:                                                                                                                                                                                                                                       
         filename: The name of the file to load the cache from                                                                                                                                                                                   
                                                                                                                                                                                                                                                 
     Returns:                                                                                                                                                                                                                                    
         The loaded cache dictionary, or an empty dictionary if the file doesn't exist                                                                                                                                                           
     """                                                                                                                                                                                                                                         
     import os                                                                                                                                                                                                                                   
     if os.path.exists(filename):                                                                                                                                                                                                                
         try:                                                                                                                                                                                                                                    
             with open(filename, 'rb') as f:                                                                                                                                                                                                     
                 return pickle.load(f)                                                                                                                                                                                                           
         except (pickle.PickleError, EOFError):                                                                                                                                                                                                  
             return {}                                                                                                                                                                                                                           
     return {}                                                                                                                                                                                                                                   
                                                                                                                                                                                                                                                 
                                                                                                                                                                                                                                                 
 if __name__ == '__main__':                                                                                                                                                                                                                      
     client = get_github_client()                                                                                                                                                                                                                
     repo = get_repository(client, 'katzlabbrandeis/blech_clust')                                                                                                                                                                                
     issues = get_open_issues(repo)                                                                                                                                                                                                              
     print(f"Found {len(issues)} open issues")                                                                                                                                                                                                   
     for issue in issues:                                                                                                                                                                                                                        
         print(get_issue_details(issue))                                                                                                                                                                                                         
         comments = get_issue_comments(issue)                                                                                                                                                                                                    
         for comment in comments:                                                                                                                                                                                                                
             print(f"Comment by {comment.user.login}: {comment.body}")                                                                                                                                                                           
 >>>>>>> REPLACE                                                                                                                                                                                                                                 
                                                                                                                                                                                                                                                 

 2 Now, let's add the trigger optimization functions to triggers.py:                                                                                                                                                                             

src/triggers.py                                                                                                                                                                                                                                  

                                                                                                                                                                                                                                                 
 <<<<<<< SEARCH                                                                                                                                                                                                                                  
 """                                                                                                                                                                                                                                             
 Functions to check specific conditions                                                                                                                                                                                                          
 """                                                                                                                                                                                                                                             
 from github import Issue                                                                                                                                                                                                                        
 from git_utils import get_issue_comments                                                                                                                                                                                                        
 =======                                                                                                                                                                                                                                         
 """                                                                                                                                                                                                                                             
 Functions to check specific conditions                                                                                                                                                                                                          
 """                                                                                                                                                                                                                                             
 from github import Issue                                                                                                                                                                                                                        
 from git_utils import (                                                                                                                                                                                                                         
     get_issue_comments,                                                                                                                                                                                                                         
     cache_issue_timeline,                                                                                                                                                                                                                       
     save_cache_to_file,                                                                                                                                                                                                                         
     load_cache_from_file                                                                                                                                                                                                                        
 )                                                                                                                                                                                                                                               
 >>>>>>> REPLACE                                                                                                                                                                                                                                 
                                                                                                                                                                                                                                                 

src/triggers.py                                                                                                                                                                                                                                  

                                                                                                                                                                                                                                                 
 <<<<<<< SEARCH                                                                                                                                                                                                                                  
 def has_user_comment_on_pr(issue: Issue) -> bool:                                                                                                                                                                                               
     """                                                                                                                                                                                                                                         
     Check if there is a user comment on a pull request that needs processing                                                                                                                                                                    
                                                                                                                                                                                                                                                 
     Args:                                                                                                                                                                                                                                       
         issue: The GitHub issue to check                                                                                                                                                                                                        
                                                                                                                                                                                                                                                 
     Returns:                                                                                                                                                                                                                                    
         True if there is a user comment on a PR that needs processing                                                                                                                                                                           
     """                                                                                                                                                                                                                                         
     comments = get_issue_comments(issue)                                                                                                                                                                                                        
     if not comments:                                                                                                                                                                                                                            
         return False                                                                                                                                                                                                                            
                                                                                                                                                                                                                                                 
     # Look for most recent non-bot comment                                                                                                                                                                                                      
     for comment in reversed(comments):                                                                                                                                                                                                          
         if "generated by blech_bot" not in comment.body:                                                                                                                                                                                        
             return True                                                                                                                                                                                                                         
     return False                                                                                                                                                                                                                                
 =======                                                                                                                                                                                                                                         
 def has_user_comment_on_pr(issue: Issue) -> bool:                                                                                                                                                                                               
     """                                                                                                                                                                                                                                         
     Check if there is a user comment on a pull request that needs processing                                                                                                                                                                    
                                                                                                                                                                                                                                                 
     Args:                                                                                                                                                                                                                                       
         issue: The GitHub issue to check                                                                                                                                                                                                        
                                                                                                                                                                                                                                                 
     Returns:                                                                                                                                                                                                                                    
         True if there is a user comment on a PR that needs processing                                                                                                                                                                           
     """                                                                                                                                                                                                                                         
     comments = get_issue_comments(issue)                                                                                                                                                                                                        
     if not comments:                                                                                                                                                                                                                            
         return False                                                                                                                                                                                                                            
                                                                                                                                                                                                                                                 
     # Look for most recent non-bot comment                                                                                                                                                                                                      
     for comment in reversed(comments):                                                                                                                                                                                                          
         if "generated by blech_bot" not in comment.body:                                                                                                                                                                                        
             return True                                                                                                                                                                                                                         
     return False                                                                                                                                                                                                                                
                                                                                                                                                                                                                                                 
                                                                                                                                                                                                                                                 
 def should_run_detailed_checks(issue: Issue, cache: dict) -> bool:                                                                                                                                                                              
     """                                                                                                                                                                                                                                         
     Determine if detailed trigger checks should be run based on timeline changes.                                                                                                                                                               
                                                                                                                                                                                                                                                 
     This function checks if there have been any changes to the issue timeline                                                                                                                                                                   
     since the last check. If changes are detected, it updates the cache and                                                                                                                                                                     
     returns True to indicate that detailed checks should be run.                                                                                                                                                                                
                                                                                                                                                                                                                                                 
     Args:                                                                                                                                                                                                                                       
         issue: The GitHub issue to check                                                                                                                                                                                                        
         cache: A dictionary to store cached timeline hashes                                                                                                                                                                                     
                                                                                                                                                                                                                                                 
     Returns:                                                                                                                                                                                                                                    
         True if detailed checks should be run, False otherwise                                                                                                                                                                                  
     """                                                                                                                                                                                                                                         
     return cache_issue_timeline(issue, cache)                                                                                                                                                                                                   
 >>>>>>> REPLACE                                                                                                                                                                                                                                 
                                                                                                                                                                                                                                                 

 3 Let's create a new file for the main execution logic that uses our caching mechanism:                                                                                                                                                         

src/check_issues.py                                                                                                                                                                                                                              

                                                                                                                                                                                                                                                 
 <<<<<<< SEARCH                                                                                                                                                                                                                                  
 =======                                                                                                                                                                                                                                         
 """                                                                                                                                                                                                                                             
 Main script to check GitHub issues with caching optimization                                                                                                                                                                                    
 """                                                                                                                                                                                                                                             
 import os                                                                                                                                                                                                                                       
 import sys                                                                                                                                                                                                                                      
 from typing import Dict, List                                                                                                                                                                                                                   
                                                                                                                                                                                                                                                 
 # Add the src directory to the path if needed                                                                                                                                                                                                   
 sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))                                                                                                                                                                    
                                                                                                                                                                                                                                                 
 from github import Issue                                                                                                                                                                                                                        
 from git_utils import (                                                                                                                                                                                                                         
     get_github_client,                                                                                                                                                                                                                          
     get_repository,                                                                                                                                                                                                                             
     get_open_issues,                                                                                                                                                                                                                            
     load_cache_from_file,                                                                                                                                                                                                                       
     save_cache_to_file                                                                                                                                                                                                                          
 )                                                                                                                                                                                                                                               
 from triggers import (                                                                                                                                                                                                                          
     should_run_detailed_checks,                                                                                                                                                                                                                 
     has_blech_bot_tag,                                                                                                                                                                                                                          
     has_generate_edit_command_trigger,                                                                                                                                                                                                          
     has_bot_response,                                                                                                                                                                                                                           
     has_user_feedback,                                                                                                                                                                                                                          
     has_develop_issue_trigger,                                                                                                                                                                                                                  
     has_pull_request_trigger,                                                                                                                                                                                                                   
     has_pr_creation_comment,                                                                                                                                                                                                                    
     has_user_comment_on_pr                                                                                                                                                                                                                      
 )                                                                                                                                                                                                                                               
 from response_agent import process_issue                                                                                                                                                                                                        
                                                                                                                                                                                                                                                 
                                                                                                                                                                                                                                                 
 def check_all_triggers(issue: Issue) -> Dict[str, bool]:                                                                                                                                                                                        
     """                                                                                                                                                                                                                                         
     Run all trigger checks on an issue                                                                                                                                                                                                          
                                                                                                                                                                                                                                                 
     Args:                                                                                                                                                                                                                                       
         issue: The GitHub issue to check                                                                                                                                                                                                        
                                                                                                                                                                                                                                                 
     Returns:                                                                                                                                                                                                                                    
         Dictionary with trigger names as keys and boolean results as values                                                                                                                                                                     
     """                                                                                                                                                                                                                                         
     return {                                                                                                                                                                                                                                    
         'has_blech_bot_tag': has_blech_bot_tag(issue),                                                                                                                                                                                          
         'has_generate_edit_command_trigger': has_generate_edit_command_trigger(issue),                                                                                                                                                          
         'has_bot_response': has_bot_response(issue),                                                                                                                                                                                            
         'has_user_feedback': has_user_feedback(issue),                                                                                                                                                                                          
         'has_develop_issue_trigger': has_develop_issue_trigger(issue),                                                                                                                                                                          
         'has_pull_request_trigger': has_pull_request_trigger(issue),                                                                                                                                                                            
         'has_pr_creation_comment': has_pr_creation_comment(issue)[0],                                                                                                                                                                           
         'has_user_comment_on_pr': has_user_comment_on_pr(issue)                                                                                                                                                                                 
     }                                                                                                                                                                                                                                           
                                                                                                                                                                                                                                                 
                                                                                                                                                                                                                                                 
 def main():                                                                                                                                                                                                                                     
     """Main function to check issues with caching optimization"""                                                                                                                                                                               
     # Load the cache from file                                                                                                                                                                                                                  
     cache = load_cache_from_file()                                                                                                                                                                                                              
                                                                                                                                                                                                                                                 
     # Initialize GitHub client and get repository                                                                                                                                                                                               
     client = get_github_client()                                                                                                                                                                                                                
                                                                                                                                                                                                                                                 
     # Get repositories from config file                                                                                                                                                                                                         
     repo_names = []                                                                                                                                                                                                                             
     with open('config/repos.txt', 'r') as f:                                                                                                                                                                                                    
         repo_names = [line.strip() for line in f if line.strip()]                                                                                                                                                                               
                                                                                                                                                                                                                                                 
     for repo_name in repo_names:                                                                                                                                                                                                                
         try:                                                                                                                                                                                                                                    
             repo = get_repository(client, repo_name)                                                                                                                                                                                            
             issues = get_open_issues(repo)                                                                                                                                                                                                      
                                                                                                                                                                                                                                                 
             print(f"Checking {len(issues)} open issues in {repo_name}")                                                                                                                                                                         
                                                                                                                                                                                                                                                 
             for issue in issues:                                                                                                                                                                                                                
                 # Check if we need to run detailed checks                                                                                                                                                                                       
                 if should_run_detailed_checks(issue, cache):                                                                                                                                                                                    
                     print(f"Changes detected in issue #{issue.number}, running detailed checks")                                                                                                                                                
                                                                                                                                                                                                                                                 
                     # Run all trigger checks                                                                                                                                                                                                    
                     trigger_results = check_all_triggers(issue)                                                                                                                                                                                 
                                                                                                                                                                                                                                                 
                     # Process the issue based on trigger results                                                                                                                                                                                
                     if any(trigger_results.values()):                                                                                                                                                                                           
                         print(f"Processing issue #{issue.number} with active triggers: {[k for k, v in trigger_results.items() if v]}")                                                                                                         
                         process_issue(issue, repo_name)                                                                                                                                                                                         
                     else:                                                                                                                                                                                                                       
                         print(f"No active triggers for issue #{issue.number}")                                                                                                                                                                  
                 else:                                                                                                                                                                                                                           
                     print(f"No changes detected in issue #{issue.number}, skipping detailed checks")                                                                                                                                            
                                                                                                                                                                                                                                                 
         except Exception as e:                                                                                                                                                                                                                  
             print(f"Error processing repository {repo_name}: {str(e)}")                                                                                                                                                                         
                                                                                                                                                                                                                                                 
     # Save the updated cache to file                                                                                                                                                                                                            
     save_cache_to_file(cache)                                                                                                                                                                                                                   
     print("Cache saved successfully")                                                                                                                                                                                                           
                                                                                                                                                                                                                                                 
                                                                                                                                                                                                                                                 
 if __name__ == "__main__":                                                                                                                                                                                                                      
     main()                                                                                                                                                                                                                                      
 >>>>>>> REPLACE                                                                                                                                                                                                                                 
                                                                                                                                                                                                                                                 

These changes implement a caching mechanism that:                                                                                                                                                                                                

 1 Generates a hash of the issue timeline (comments, labels, state, etc.)                                                                                                                                                                        
 2 Compares the current hash with the cached hash to detect changes                                                                                                                                                                              
 3 Only runs detailed trigger checks when changes are detected                                                                                                                                                                                   
 4 Persists the cache between runs using pickle serialization                                                                                                                                                                                    
 5 Provides a main script that uses this optimization to efficiently process issues                                                                                                                                                              

The implementation is designed to be efficient and maintainable, with clear separation of concerns between the caching mechanism, trigger checks, and main execution logic.                                                                      

                                                                                                                                                                                                                                                 
 python src/check_issues.py                                                                                                                                                                                                                      
                                                                                                                                                                                                                                                 

Tokens: 7.5k sent, 2.2k received. Cost: $0.06 message, $0.06 session.

src/check_issues.py
Applied edit to src/check_issues.py
Applied edit to src/git_utils.py
Applied edit to src/triggers.py
Commit 8000b21 feat: Implement issue timeline caching mechanism for efficient GitHub issue processing

# 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/git_utils.py

src/git_utils.py:340:32: F821 undefined name 'pull_request'
            pr_comments = list(pull_request.get_issue_comments())
                               ^
src/git_utils.py:342:17: F821 undefined name 'pull_request'
                pull_request.create_issue_comment(error_msg)
                ^

## See relevant lines below marked with █.

src/git_utils.py:
...⋮...
 301│def push_changes_with_authentication(
 302│        repo_path: str,
 303│        # pull_request: PullRequest,
 304│        out_thread: IssueComment | PullRequest,
 305│        branch_name: Optional[str] = None
 306│) -> Tuple[bool, Optional[str]]:
 307│    """
 308│    Push changes to the remote repository with authentication.
 309│
 310│    Args:
 311│        repo_path: Path to the local git repository
 312│        branch_name: Name of the branch to push (default: current branch)
...⋮...
 331│    try:
...⋮...
 335│    except git.GitCommandError as e:
 336│        error_msg = f"Failed to push changes: {e.stderr.strip()}"
 337│        if isinstance(out_thread, IssueComment):
 338│            write_issue_response(out_thread, error_msg)
 339│        elif isinstance(out_thread, PullRequest):
 340█            pr_comments = list(pull_request.get_issue_comments())
 341│            if 'Failed to push changes' not in pr_comments[-1].body:
 342█                pull_request.create_issue_comment(error_msg)
 343│        else:
 344│            raise ValueError(
 345│                "Invalid output thread type, must be IssueComment or PullRequest")
...⋮...


I'll fix the undefined name errors in the push_changes_with_authentication function. The issue is that the function is using pull_request variable which is not defined - it should be using the out_thread parameter instead.                   

src/git_utils.py                                                                                                                                                                                                                                 

                                                                                                                                                                                                                                                 
 <<<<<<< SEARCH                                                                                                                                                                                                                                  
         elif isinstance(out_thread, PullRequest):                                                                                                                                                                                               
             pr_comments = list(pull_request.get_issue_comments())                                                                                                                                                                               
             if 'Failed to push changes' not in pr_comments[-1].body:                                                                                                                                                                            
                 pull_request.create_issue_comment(error_msg)                                                                                                                                                                                    
 =======                                                                                                                                                                                                                                         
         elif isinstance(out_thread, PullRequest):                                                                                                                                                                                               
             pr_comments = list(out_thread.get_issue_comments())                                                                                                                                                                                 
             if 'Failed to push changes' not in pr_comments[-1].body:                                                                                                                                                                            
                 out_thread.create_issue_comment(error_msg)                                                                                                                                                                                      
 >>>>>>> REPLACE                                                                                                                                                                                                                                 
                                                                                                                                                                                                                                                 

This change replaces the undefined pull_request variable with the correctly passed out_thread parameter, which is already being checked with isinstance(out_thread, PullRequest).                                                                

Tokens: 12k sent, 193 received. Cost: $0.04 message, $0.09 session.
Applied edit to src/git_utils.py
Commit c480b04 fix: Replace undefined pull_request with out_thread in error handling

python src/check_issues.py

This response was automatically generated by blech_bot

@abuzarmahmood
Copy link
Owner Author

Skipped PR #81: PR #81 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.

Instead of checking comments and tags independently on every run, compare issue timeline to cached version to detect changes

1 participant