Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use copilot and cursor instructions as a extra_instructions #1424

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

dotneet
Copy link

@dotneet dotneet commented Dec 30, 2024

PR Type

Enhancement


Description

  • Added support for loading extra instructions from editor-specific configuration files:
    • .github/copilot-instructions.md for GitHub Copilot
    • .cursorrules for Cursor editor
  • Maintains backwards compatibility by falling back to settings value if no instruction files are found
  • Improves flexibility by allowing project-specific coding guidelines to be defined in standard locations

Changes walkthrough 📝

Relevant files
Enhancement
pr_code_suggestions.py
Add support for loading editor-specific instruction files

pr_agent/tools/pr_code_suggestions.py

  • Added new method _load_extra_instructions() to load instructions from
    either copilot or cursor configuration files
  • Modified initialization to use the new method instead of directly
    accessing settings
  • Falls back to settings value if no instruction files are found
  • +16/-1   

    💡 PR-Agent usage: Comment /help "your question" on any pull request to receive relevant information

    Copy link
    Contributor

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🏅 Score: 85
    🧪 No relevant tests
    🔒 Security concerns

    File access:
    The code reads files from the project directory without validating the file size or content type, which could potentially be exploited to read large files or non-text files that could cause memory/performance issues

    ⚡ Recommended focus areas for review

    File Handling

    The file reading code should handle potential encoding errors and file permissions issues that could occur when trying to read the instruction files

    with open(file_path, 'r', encoding='utf-8') as file:
        return file.read()
    Empty Content

    The code should validate that the loaded instruction file actually contains meaningful content before using it, rather than accepting empty files

    with open(file_path, 'r', encoding='utf-8') as file:
        return file.read()

    Copy link
    Contributor

    qodo-merge-pro-for-open-source bot commented Dec 30, 2024

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    General
    Enhance error handling to catch all potential file reading exceptions

    Add error handling for file reading operations beyond FileNotFoundError. Other
    IOErrors could occur when reading files (e.g., permission issues).

    pr_agent/tools/pr_code_suggestions.py [104-107]

     try:
         with open(file_path, 'r', encoding='utf-8') as file:
             return file.read()
    -except FileNotFoundError:
    +except (FileNotFoundError, IOError, OSError) as e:
    +    get_logger().debug(f"Could not read {file_path}: {str(e)}")
         continue
    • Apply this suggestion
    Suggestion importance[1-10]: 7

    Why: The suggestion improves error handling robustness by catching additional file-related exceptions and adds helpful debug logging, which is important for troubleshooting in production environments.

    7
    ✅ Validate file contents before processing to ensure meaningful data
    Suggestion Impact:The commit directly implemented the suggested validation by adding content.strip() and checking if content exists before returning

    code diff:

    -                    return file.read()
    +                    content = file.read().strip()
    +                    if content:
    +                        return content

    Add content validation before returning file contents to ensure we're not processing
    empty or invalid instruction files.

    pr_agent/tools/pr_code_suggestions.py [104-105]

     with open(file_path, 'r', encoding='utf-8') as file:
    -    return file.read()
    +    content = file.read().strip()
    +    if content:
    +        return content
    • Apply this suggestion
    Suggestion importance[1-10]: 6

    Why: The suggestion adds important validation to prevent processing empty files, which could lead to unexpected behavior, though the impact is moderate since empty files would currently just result in an empty string.

    6
    • Author self-review: I have reviewed the PR code suggestions, and addressed the relevant ones.

    @mrT23
    Copy link
    Collaborator

    mrT23 commented Jan 1, 2025

    This PR won't be merged.

    It's overfitted to a specific external program, and the mechanism is wrong (loading configurations in the wrong place for a specific tool with hard-coded relative paths).

    Use the existing configuration files to give extra instructions
    https://qodo-merge-docs.qodo.ai/usage-guide/configuration_options/#local-configuration-file

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

    Successfully merging this pull request may close these issues.

    2 participants