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

Added ignore_bot_pr option #800

Merged
merged 3 commits into from
Mar 21, 2024

Conversation

koid
Copy link
Contributor

@koid koid commented Mar 18, 2024

User description

Add an option to ignore pull requests opend by bots such as renovate[bot].

Discussion:
Which is preferable, ignoring bots entirely or allowing specification of users to ignore?


Type

enhancement, configuration changes


Description

  • Introduced a new feature to ignore PRs opened by bots in the GitHub App mode, enhancing automation control.
  • Added a new configuration option ignore_bot_pr in the settings to enable or disable ignoring bot-opened PRs.
  • Updated handle_new_pr_opened and get_log_context functions to support checking the sender type and applying the new ignore bots logic.

Changes walkthrough

Relevant files
Enhancement
github_app.py
Support for Ignoring Bot-Opened PRs in GitHub App               

pr_agent/servers/github_app.py

  • Added sender_type parameter to handle_new_pr_opened and
    get_log_context functions to identify the sender type.
  • Implemented a check to ignore PRs opened by bots based on the new
    ignore_bot_pr setting in the configuration.
  • Updated function calls to include the sender_type parameter.
  • +11/-3   
    Configuration changes
    configuration.toml
    Configuration Option to Ignore Bot-Opened PRs                       

    pr_agent/settings/configuration.toml

  • Introduced a new configuration option ignore_bot_pr to enable ignoring
    PRs opened by bots.
  • +1/-0     

    PR-Agent usage:
    Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    @koid
    Copy link
    Contributor Author

    koid commented Mar 18, 2024

    /describe

    Copy link

    PR-Agent was enabled for this repository. To use it, please link your git user with your CodiumAI identity here.

    PR Description updated to latest commit (781bc9f)

    1 similar comment
    Copy link

    PR-Agent was enabled for this repository. To use it, please link your git user with your CodiumAI identity here.

    PR Description updated to latest commit (781bc9f)

    Copy link

    PR-Agent was enabled for this repository. To use it, please link your git user with your CodiumAI identity here.

    PR Review

    ⏱️ Estimated effort to review [1-5]

    2, because the changes are straightforward and localized to specific sections in the codebase. The logic added is simple and does not seem to introduce complex dependencies or require deep understanding of the existing system. Reviewing the configuration change is also straightforward.

    🏅 Score

    85

    🧪 Relevant tests

    No

    🔍 Possible issues

    Regex Specificity: The regex used to match bot usernames ('.+[bot]$') is quite broad. It might be beneficial to ensure that this does not unintentionally match non-bot users who might have '[bot]' in their username for other reasons.

    Hardcoded Logic: The decision to ignore PRs based on the sender's name ending with '[bot]' is hardcoded. This might limit flexibility if there are bots that do not follow this naming convention or if there are non-bot users with names ending in '[bot]'.

    🔒 Security concerns

    No

    🔀 Multiple PR themes

    No


    ✨ Review tool usage guide:

    Overview:
    The review tool scans the PR code changes, and generates a PR review. The tool can be triggered automatically every time a new PR is opened, or can be invoked manually by commenting on any PR.
    When commenting, to edit configurations related to the review tool (pr_reviewer section), use the following template:

    /review --pr_reviewer.some_config1=... --pr_reviewer.some_config2=...
    

    With a configuration file, use the following template:

    [pr_reviewer]
    some_config1=...
    some_config2=...
    
    Utilizing extra instructions

    The review tool can be configured with extra instructions, which can be used to guide the model to a feedback tailored to the needs of your project.

    Be specific, clear, and concise in the instructions. With extra instructions, you are the prompter. Specify the relevant sub-tool, and the relevant aspects of the PR that you want to emphasize.

    Examples for extra instructions:

    [pr_reviewer] # /review #
    extra_instructions="""
    In the 'possible issues' section, emphasize the following:
    - Does the code logic cover relevant edge cases?
    - Is the code logic clear and easy to understand?
    - Is the code logic efficient?
    ...
    """
    

    Use triple quotes to write multi-line instructions. Use bullet points to make the instructions more readable.

    How to enable\disable automation
    • When you first install PR-Agent app, the default mode for the review tool is:
    pr_commands = ["/review", ...]
    

    meaning the review tool will run automatically on every PR, with the default configuration.
    Edit this field to enable/disable the tool, or to change the used configurations

    Auto-labels

    The review tool can auto-generate two specific types of labels for a PR:

    • a possible security issue label, that detects possible security issues (enable_review_labels_security flag)
    • a Review effort [1-5]: x label, where x is the estimated effort to review the PR (enable_review_labels_effort flag)
    Extra sub-tools

    The review tool provides a collection of possible feedbacks about a PR.
    It is recommended to review the possible options, and choose the ones relevant for your use case.
    Some of the feature that are disabled by default are quite useful, and should be considered for enabling. For example:
    require_score_review, require_soc2_ticket, require_can_be_split_review, and more.

    Auto-approve PRs

    By invoking:

    /review auto_approve
    

    The tool will automatically approve the PR, and add a comment with the approval.

    To ensure safety, the auto-approval feature is disabled by default. To enable auto-approval, you need to actively set in a pre-defined configuration file the following:

    [pr_reviewer]
    enable_auto_approval = true
    

    (this specific flag cannot be set with a command line argument, only in the configuration file, committed to the repository)

    You can also enable auto-approval only if the PR meets certain requirements, such as that the estimated_review_effort is equal or below a certain threshold, by adjusting the flag:

    [pr_reviewer]
    maximal_review_effort = 5
    
    More PR-Agent commands

    To invoke the PR-Agent, add a comment using one of the following commands:

    • /review: Request a review of your Pull Request.
    • /describe: Update the PR title and description based on the contents of the PR.
    • /improve [--extended]: Suggest code improvements. Extended mode provides a higher quality feedback.
    • /ask <QUESTION>: Ask a question about the PR.
    • /update_changelog: Update the changelog based on the PR's contents.
    • /add_docs 💎: Generate docstring for new components introduced in the PR.
    • /generate_labels 💎: Generate labels for the PR based on the PR's contents.
    • /analyze 💎: Automatically analyzes the PR, and presents changes walkthrough for each component.

    See the tools guide for more details.
    To list the possible configuration parameters, add a /config comment.

    See the review usage page for a comprehensive guide on using this tool.

    Copy link

    codiumai-pr-agent-pro bot commented Mar 18, 2024

    PR Code Suggestions

    CategorySuggestions                                                                                                                                                       
    Performance
    Replace regular expression match with str.endswith() for bot name check.

    Consider using a more efficient way to check if the sender is a bot. The current
    implementation uses a regular expression match, which might be less efficient and harder
    to maintain. Instead, you can directly check if the sender's name ends with '[bot]' using
    the str.endswith() method. This approach is more readable and performs better.

    pr_agent/servers/github_app.py [128]

    -if re.match('.+\[bot]$', sender) is not None:
    +if sender.endswith('[bot]'):
     
    Maintainability
    Extract bot checking logic into a separate function for better maintainability.

    To improve the maintainability of the code, consider extracting the logic for checking if
    a PR is opened by a bot into a separate function. This will make the handle_new_pr_opened
    function cleaner and the bot-checking logic reusable. Additionally, it encapsulates the
    bot detection logic in one place, making it easier to update or extend in the future.

    pr_agent/servers/github_app.py [127-130]

    -if get_settings().get("GITHUB_APP.IGNORE_BOT_PR", False):
    -   if re.match('.+\[bot]$', sender) is not None:
    -       get_logger().info(f"Ignoring PR by sender '{sender}' due to github_app.ignore_bot_pr setting")
    -       return {}
    +if should_ignore_bot_pr(sender):
    +    get_logger().info(f"Ignoring PR by sender '{sender}' due to github_app.ignore_bot_pr setting")
    +    return {}
     
    +def should_ignore_bot_pr(sender: str) -> bool:
    +    return get_settings().get("GITHUB_APP.IGNORE_BOT_PR", False) and sender.endswith('[bot]')
    +
    Best practice
    Add a comment explaining the ignore_bot_pr setting in the configuration file.

    Since the ignore_bot_pr setting is a boolean, it's a good practice to add a comment
    explaining what true and false values mean for this setting. This helps in maintaining
    clear documentation within the configuration file itself, making it easier for future
    maintainers or users to understand the purpose and effect of this setting without having
    to look into the codebase.

    pr_agent/settings/configuration.toml [158]

    +# If set to true, PRs opened by bots will be ignored. If false, bot PRs will be processed.
     ignore_bot_pr = false
     
    Enhancement
    Use a more expressive return value or exception for bot PR detection.

    When returning an empty dictionary to indicate that no further action should be taken for
    bot PRs, it might be more expressive to return a specific value or raise a custom
    exception. This approach makes the control flow clearer and helps distinguish between
    different reasons for early returns. For instance, returning None or raising a
    BotPRDetected exception could explicitly signal the intent to stop processing due to bot
    detection.

    pr_agent/servers/github_app.py [130]

    -return {}
    +raise BotPRDetected(f"PR by '{sender}' ignored due to bot detection.")
     
    +# Where BotPRDetected is a custom exception defined elsewhere in the codebase.
    +

    ✨ Improve tool usage guide:

    Overview:
    The improve tool scans the PR code changes, and automatically generates suggestions for improving the PR code. The tool can be triggered automatically every time a new PR is opened, or can be invoked manually by commenting on a PR.
    When commenting, to edit configurations related to the improve tool (pr_code_suggestions section), use the following template:

    /improve --pr_code_suggestions.some_config1=... --pr_code_suggestions.some_config2=...
    

    With a configuration file, use the following template:

    [pr_code_suggestions]
    some_config1=...
    some_config2=...
    
    Enabling\disabling automation

    When you first install the app, the default mode for the improve tool is:

    pr_commands = ["/improve --pr_code_suggestions.summarize=true", ...]
    

    meaning the improve tool will run automatically on every PR, with summarization enabled. Delete this line to disable the tool from running automatically.

    Utilizing extra instructions

    Extra instructions are very important for the improve tool, since they enable to guide the model to suggestions that are more relevant to the specific needs of the project.

    Be specific, clear, and concise in the instructions. With extra instructions, you are the prompter. Specify relevant aspects that you want the model to focus on.

    Examples for extra instructions:

    [pr_code_suggestions] # /improve #
    extra_instructions="""
    Emphasize the following aspects:
    - Does the code logic cover relevant edge cases?
    - Is the code logic clear and easy to understand?
    - Is the code logic efficient?
    ...
    """
    

    Use triple quotes to write multi-line instructions. Use bullet points to make the instructions more readable.

    A note on code suggestions quality
    • While the current AI for code is getting better and better (GPT-4), it's not flawless. Not all the suggestions will be perfect, and a user should not accept all of them automatically.
    • Suggestions are not meant to be simplistic. Instead, they aim to give deep feedback and raise questions, ideas and thoughts to the user, who can then use his judgment, experience, and understanding of the code base.
    • Recommended to use the 'extra_instructions' field to guide the model to suggestions that are more relevant to the specific needs of the project, or use the custom suggestions 💎 tool
    • With large PRs, best quality will be obtained by using 'improve --extended' mode.
    More PR-Agent commands

    To invoke the PR-Agent, add a comment using one of the following commands:

    • /review: Request a review of your Pull Request.
    • /describe: Update the PR title and description based on the contents of the PR.
    • /improve [--extended]: Suggest code improvements. Extended mode provides a higher quality feedback.
    • /ask <QUESTION>: Ask a question about the PR.
    • /update_changelog: Update the changelog based on the PR's contents.
    • /add_docs 💎: Generate docstring for new components introduced in the PR.
    • /generate_labels 💎: Generate labels for the PR based on the PR's contents.
    • /analyze 💎: Automatically analyzes the PR, and presents changes walkthrough for each component.

    See the tools guide for more details.
    To list the possible configuration parameters, add a /config comment.

    See the improve usage page for a more comprehensive guide on using this tool.

    @koid koid force-pushed the feature/ignore-bot-pr-on-github-app branch from 1347f7b to b71523f Compare March 18, 2024 07:15
    Copy link

    codiumai-pr-agent-pro bot commented Mar 18, 2024

    PR Review

    (Review updated until commit cae0b96)

    ⏱️ Estimated effort to review [1-5]

    2, because the changes are straightforward and involve adding a new feature with a clear implementation strategy. The logic is simple and does not seem to introduce complex dependencies or require deep understanding of the existing codebase.

    🏅 Score

    85

    🧪 Relevant tests

    No

    🔍 Possible issues

    Hardcoded Bot Detection: The current implementation relies on the sender's name ending with [bot] to identify bot accounts. This might not cover all bot accounts or future naming conventions.

    🔒 Security concerns

    No

    🔀 Multiple PR themes

    No

    Code feedback:
    relevant filepr_agent/servers/github_app.py
    suggestion      

    Consider using a more robust method to identify bot accounts, possibly by checking additional metadata or using GitHub's API to fetch user details. This would make the feature more reliable and future-proof. [important]

    relevant lineif get_settings().get("GITHUB_APP.IGNORE_BOT_PR", False) and sender_type == "Bot":

    relevant filepr_agent/servers/github_app.py
    suggestion      

    It's good practice to lower-case the sender_type before comparison to ensure case-insensitive matching. This prevents potential issues if the case convention changes or is inconsistent. [medium]

    relevant lineif get_settings().get("GITHUB_APP.IGNORE_BOT_PR", False) and sender_type == "Bot":

    relevant filepr_agent/servers/github_app.py
    suggestion      

    Add a debug or info log in the else case when the PR is not ignored because it's not from a bot. This can help with troubleshooting and understanding the flow of PR handling. [medium]

    relevant linereturn {}


    ✨ Review tool usage guide:

    Overview:
    The review tool scans the PR code changes, and generates a PR review. The tool can be triggered automatically every time a new PR is opened, or can be invoked manually by commenting on any PR.
    When commenting, to edit configurations related to the review tool (pr_reviewer section), use the following template:

    /review --pr_reviewer.some_config1=... --pr_reviewer.some_config2=...
    

    With a configuration file, use the following template:

    [pr_reviewer]
    some_config1=...
    some_config2=...
    
    Utilizing extra instructions

    The review tool can be configured with extra instructions, which can be used to guide the model to a feedback tailored to the needs of your project.

    Be specific, clear, and concise in the instructions. With extra instructions, you are the prompter. Specify the relevant sub-tool, and the relevant aspects of the PR that you want to emphasize.

    Examples for extra instructions:

    [pr_reviewer] # /review #
    extra_instructions="""
    In the 'possible issues' section, emphasize the following:
    - Does the code logic cover relevant edge cases?
    - Is the code logic clear and easy to understand?
    - Is the code logic efficient?
    ...
    """
    

    Use triple quotes to write multi-line instructions. Use bullet points to make the instructions more readable.

    How to enable\disable automation
    • When you first install PR-Agent app, the default mode for the review tool is:
    pr_commands = ["/review", ...]
    

    meaning the review tool will run automatically on every PR, with the default configuration.
    Edit this field to enable/disable the tool, or to change the used configurations

    Auto-labels

    The review tool can auto-generate two specific types of labels for a PR:

    • a possible security issue label, that detects possible security issues (enable_review_labels_security flag)
    • a Review effort [1-5]: x label, where x is the estimated effort to review the PR (enable_review_labels_effort flag)
    Extra sub-tools

    The review tool provides a collection of possible feedbacks about a PR.
    It is recommended to review the possible options, and choose the ones relevant for your use case.
    Some of the feature that are disabled by default are quite useful, and should be considered for enabling. For example:
    require_score_review, require_soc2_ticket, require_can_be_split_review, and more.

    Auto-approve PRs

    By invoking:

    /review auto_approve
    

    The tool will automatically approve the PR, and add a comment with the approval.

    To ensure safety, the auto-approval feature is disabled by default. To enable auto-approval, you need to actively set in a pre-defined configuration file the following:

    [pr_reviewer]
    enable_auto_approval = true
    

    (this specific flag cannot be set with a command line argument, only in the configuration file, committed to the repository)

    You can also enable auto-approval only if the PR meets certain requirements, such as that the estimated_review_effort is equal or below a certain threshold, by adjusting the flag:

    [pr_reviewer]
    maximal_review_effort = 5
    
    More PR-Agent commands

    To invoke the PR-Agent, add a comment using one of the following commands:

    • /review: Request a review of your Pull Request.
    • /describe: Update the PR title and description based on the contents of the PR.
    • /improve [--extended]: Suggest code improvements. Extended mode provides a higher quality feedback.
    • /ask <QUESTION>: Ask a question about the PR.
    • /update_changelog: Update the changelog based on the PR's contents.
    • /add_docs 💎: Generate docstring for new components introduced in the PR.
    • /generate_labels 💎: Generate labels for the PR based on the PR's contents.
    • /analyze 💎: Automatically analyzes the PR, and presents changes walkthrough for each component.

    See the tools guide for more details.
    To list the possible configuration parameters, add a /config comment.

    See the review usage page for a comprehensive guide on using this tool.

    @hussam789
    Copy link
    Collaborator

    /Describe

    Copy link

    PR Description updated to latest commit (b71523f)

    @hussam789
    Copy link
    Collaborator

    /Describe

    Copy link

    PR Description updated to latest commit (b71523f)

    @hussam789
    Copy link
    Collaborator

    /Describe

    @hussam789
    Copy link
    Collaborator

    /Review

    @Codium-ai Codium-ai deleted a comment from codiumai-pr-agent-pro bot Mar 18, 2024
    @Codium-ai Codium-ai deleted a comment from codiumai-pr-agent-pro bot Mar 18, 2024
    @hussam789
    Copy link
    Collaborator

    /improve

    Copy link

    codiumai-pr-agent-pro bot commented Mar 20, 2024

    PR Code Suggestions

    CategorySuggestions                                                                                                                                                       
    Enhancement
    Improve configuration access for ignoring bot PRs.

    Consider using a more direct approach to access the configuration setting for ignoring bot
    PRs. Instead of using get_settings().get("GITHUB_APP.IGNORE_BOT_PR", False), you can
    define a specific function or property in your settings management to directly return this
    value. This approach improves code readability and maintainability.

    pr_agent/servers/github_app.py [125]

    -if get_settings().get("GITHUB_APP.IGNORE_BOT_PR", False):
    +if settings.ignore_bot_pr:
     
    Maintainability
    Combine two if conditions into one to reduce nesting.

    To enhance the maintainability and readability of the code, consider combining the two if
    conditions into a single condition using the and operator. This reduces the nesting level
    and makes the code cleaner.

    pr_agent/servers/github_app.py [125-126]

    -if get_settings().get("GITHUB_APP.IGNORE_BOT_PR", False):
    -   if sender.endswith('[bot]'):
    +if get_settings().get("GITHUB_APP.IGNORE_BOT_PR", False) and sender.endswith('[bot]'):
     
    Clarify the return value when ignoring bot PRs.

    Returning an empty dictionary might be misleading in the context of handling a new PR
    opened. If the intention is to stop the execution for bot PRs without further action,
    consider explicitly returning None or raising a custom exception if it's an exceptional
    case. This makes the intent clearer to other developers.

    pr_agent/servers/github_app.py [128]

    -return {}
    +return None
     
    Best practice
    Use structured logging for better log management.

    It's recommended to use structured logging instead of formatting strings directly. This
    allows for better log management and filtering. Replace the formatted string with
    structured logging parameters.

    pr_agent/servers/github_app.py [127]

    -get_logger().info(f"Ignoring PR by sender '{sender}' due to github_app.ignore_bot_pr setting")
    +get_logger().info("Ignoring PR by sender due to github_app.ignore_bot_pr setting", extra={"sender": sender})
     
    Add a comment explaining the ignore_bot_pr setting.

    For better clarity and to avoid potential confusion, consider adding a comment above the
    ignore_bot_pr setting explaining its purpose and possible values. This helps in
    maintaining the configuration file and makes it easier for new developers to understand
    the impact of this setting.

    pr_agent/settings/configuration.toml [158]

    +# Set to true to ignore PRs opened by bots, false otherwise
     ignore_bot_pr = false
     

    ✨ Improve tool usage guide:

    Overview:
    The improve tool scans the PR code changes, and automatically generates suggestions for improving the PR code. The tool can be triggered automatically every time a new PR is opened, or can be invoked manually by commenting on a PR.
    When commenting, to edit configurations related to the improve tool (pr_code_suggestions section), use the following template:

    /improve --pr_code_suggestions.some_config1=... --pr_code_suggestions.some_config2=...
    

    With a configuration file, use the following template:

    [pr_code_suggestions]
    some_config1=...
    some_config2=...
    
    Enabling\disabling automation

    When you first install the app, the default mode for the improve tool is:

    pr_commands = ["/improve --pr_code_suggestions.summarize=true", ...]
    

    meaning the improve tool will run automatically on every PR, with summarization enabled. Delete this line to disable the tool from running automatically.

    Utilizing extra instructions

    Extra instructions are very important for the improve tool, since they enable to guide the model to suggestions that are more relevant to the specific needs of the project.

    Be specific, clear, and concise in the instructions. With extra instructions, you are the prompter. Specify relevant aspects that you want the model to focus on.

    Examples for extra instructions:

    [pr_code_suggestions] # /improve #
    extra_instructions="""
    Emphasize the following aspects:
    - Does the code logic cover relevant edge cases?
    - Is the code logic clear and easy to understand?
    - Is the code logic efficient?
    ...
    """
    

    Use triple quotes to write multi-line instructions. Use bullet points to make the instructions more readable.

    A note on code suggestions quality
    • While the current AI for code is getting better and better (GPT-4), it's not flawless. Not all the suggestions will be perfect, and a user should not accept all of them automatically.
    • Suggestions are not meant to be simplistic. Instead, they aim to give deep feedback and raise questions, ideas and thoughts to the user, who can then use his judgment, experience, and understanding of the code base.
    • Recommended to use the 'extra_instructions' field to guide the model to suggestions that are more relevant to the specific needs of the project, or use the custom suggestions 💎 tool
    • With large PRs, best quality will be obtained by using 'improve --extended' mode.
    More PR-Agent commands

    To invoke the PR-Agent, add a comment using one of the following commands:

    • /review: Request a review of your Pull Request.
    • /describe: Update the PR title and description based on the contents of the PR.
    • /improve [--extended]: Suggest code improvements. Extended mode provides a higher quality feedback.
    • /ask <QUESTION>: Ask a question about the PR.
    • /update_changelog: Update the changelog based on the PR's contents.
    • /add_docs 💎: Generate docstring for new components introduced in the PR.
    • /generate_labels 💎: Generate labels for the PR based on the PR's contents.
    • /analyze 💎: Automatically analyzes the PR, and presents changes walkthrough for each component.

    See the tools guide for more details.
    To list the possible configuration parameters, add a /config comment.

    See the improve usage page for a more comprehensive guide on using this tool.

    @hussam789
    Copy link
    Collaborator

    hussam789 commented Mar 20, 2024

    interactive chat

    <.....>

    backend answers:

    < ...>

    @koid
    Copy link
    Contributor Author

    koid commented Mar 21, 2024

    Consider using a more flexible bot detection mechanism. For example, GitHub API provides a type field in the user object, which can be Bot. This approach would be more reliable than checking the username suffix. [important]

    I will correct this.

    @koid
    Copy link
    Contributor Author

    koid commented Mar 21, 2024

    /describe

    @koid
    Copy link
    Contributor Author

    koid commented Mar 21, 2024

    /review

    @koid
    Copy link
    Contributor Author

    koid commented Mar 21, 2024

    /improve

    Copy link

    PR-Agent was enabled for this repository. To use it, please link your git user with your CodiumAI identity here.

    PR Description updated to latest commit (cae0b96)

    Copy link

    codiumai-pr-agent-pro bot commented Mar 21, 2024

    PR Code Suggestions

    CategorySuggestions                                                                                                                                                       
    Best practice
    Use a constant for the string literal "Bot".

    Consider using a constant for the string literal "Bot" to avoid potential typos and
    facilitate changes in the future. Define this constant at the module level and use it
    throughout your code.

    pr_agent/servers/github_app.py [126]

    -if get_settings().get("GITHUB_APP.IGNORE_BOT_PR", False) and sender_type == "Bot":
    +BOT_SENDER_TYPE = "Bot"
    +if get_settings().get("GITHUB_APP.IGNORE_BOT_PR", False) and sender_type == BOT_SENDER_TYPE:
     
    Use specific exceptions for better error handling.

    For better error handling in get_log_context, instead of catching a generic Exception,
    catch more specific exceptions related to accessing dictionary keys or type conversions.
    This can help in identifying the exact cause of failure.

    pr_agent/servers/github_app.py [244]

    -except Exception as e:
    +except (KeyError, TypeError) as e:
     
    Enhancement
    Ensure the setting value is explicitly checked to be a boolean.

    It's recommended to handle the case where get_settings().get("GITHUB_APP.IGNORE_BOT_PR",
    False) might not return a boolean as expected. Ensure the returned value is explicitly
    checked to be a boolean to avoid unexpected behavior.

    pr_agent/servers/github_app.py [126]

    -if get_settings().get("GITHUB_APP.IGNORE_BOT_PR", False) and sender_type == "Bot":
    +ignore_bot_pr_setting = get_settings().get("GITHUB_APP.IGNORE_BOT_PR", False)
    +if isinstance(ignore_bot_pr_setting, bool) and ignore_bot_pr_setting and sender_type == "Bot":
     
    Return a descriptive response when ignoring a bot PR.

    Instead of returning an empty dictionary directly in the handle_new_pr_opened function
    when ignoring a bot PR, consider logging the action and returning a more descriptive
    response. This can improve debugging and logging capabilities.

    pr_agent/servers/github_app.py [128]

    -return {}
    +return {"status": "ignored", "reason": "PR opened by bot"}
     
    Maintainability
    Split sender information extraction into a separate function.

    To improve the readability and maintainability of the get_log_context function, consider
    splitting the extraction of sender information into a separate function. This can help
    isolate changes and make the code more modular.

    pr_agent/servers/github_app.py [235-237]

    -sender = body.get("sender", {}).get("login")
    -sender_id = body.get("sender", {}).get("id")
    -sender_type = body.get("sender", {}).get("type")
    +def extract_sender_info(sender_data):
    +    return sender_data.get("login"), sender_data.get("id"), sender_data.get("type")
     
    +sender, sender_id, sender_type = extract_sender_info(body.get("sender", {}))
    +

    ✨ Improve tool usage guide:

    Overview:
    The improve tool scans the PR code changes, and automatically generates suggestions for improving the PR code. The tool can be triggered automatically every time a new PR is opened, or can be invoked manually by commenting on a PR.
    When commenting, to edit configurations related to the improve tool (pr_code_suggestions section), use the following template:

    /improve --pr_code_suggestions.some_config1=... --pr_code_suggestions.some_config2=...
    

    With a configuration file, use the following template:

    [pr_code_suggestions]
    some_config1=...
    some_config2=...
    
    Enabling\disabling automation

    When you first install the app, the default mode for the improve tool is:

    pr_commands = ["/improve --pr_code_suggestions.summarize=true", ...]
    

    meaning the improve tool will run automatically on every PR, with summarization enabled. Delete this line to disable the tool from running automatically.

    Utilizing extra instructions

    Extra instructions are very important for the improve tool, since they enable to guide the model to suggestions that are more relevant to the specific needs of the project.

    Be specific, clear, and concise in the instructions. With extra instructions, you are the prompter. Specify relevant aspects that you want the model to focus on.

    Examples for extra instructions:

    [pr_code_suggestions] # /improve #
    extra_instructions="""
    Emphasize the following aspects:
    - Does the code logic cover relevant edge cases?
    - Is the code logic clear and easy to understand?
    - Is the code logic efficient?
    ...
    """
    

    Use triple quotes to write multi-line instructions. Use bullet points to make the instructions more readable.

    A note on code suggestions quality
    • While the current AI for code is getting better and better (GPT-4), it's not flawless. Not all the suggestions will be perfect, and a user should not accept all of them automatically.
    • Suggestions are not meant to be simplistic. Instead, they aim to give deep feedback and raise questions, ideas and thoughts to the user, who can then use his judgment, experience, and understanding of the code base.
    • Recommended to use the 'extra_instructions' field to guide the model to suggestions that are more relevant to the specific needs of the project, or use the custom suggestions 💎 tool
    • With large PRs, best quality will be obtained by using 'improve --extended' mode.
    More PR-Agent commands

    To invoke the PR-Agent, add a comment using one of the following commands:

    • /review: Request a review of your Pull Request.
    • /describe: Update the PR title and description based on the contents of the PR.
    • /improve [--extended]: Suggest code improvements. Extended mode provides a higher quality feedback.
    • /ask <QUESTION>: Ask a question about the PR.
    • /update_changelog: Update the changelog based on the PR's contents.
    • /add_docs 💎: Generate docstring for new components introduced in the PR.
    • /generate_labels 💎: Generate labels for the PR based on the PR's contents.
    • /analyze 💎: Automatically analyzes the PR, and presents changes walkthrough for each component.

    See the tools guide for more details.
    To list the possible configuration parameters, add a /config comment.

    See the improve usage page for a more comprehensive guide on using this tool.

    Copy link

    PR-Agent was enabled for this repository. To use it, please link your git user with your CodiumAI identity here.

    Persistent review updated to latest commit cae0b96

    @mrT23
    Copy link
    Collaborator

    mrT23 commented Mar 21, 2024

    @koid
    i am not sure i understand the PR
    the line:
    sender_type = body.get("sender", {}).get("type")

    are you sure that such a field will always be updated ? what is the definition of 'bot' in github ?


    I think that a different more robust logic can be something similar to ignore_pr_title:

    define in the configuration file a list of forbidden keywords (for example [bot] )
    if the sender's name contains one of the keywords, ignore the PR

    this is the implementation of ignore_pr_title:

    image

    @mrT23
    Copy link
    Collaborator

    mrT23 commented Mar 21, 2024

    ok, its rather intresting:

    how github know if something is a bot ?
    ChatGPT
    GitHub uses several methods to determine if an account or activity is bot-like. These methods aim to maintain the platform's integrity, prevent abuse, and ensure compliance with its terms of service. Here are some of the primary ways GitHub might identify bot activities:

    User-Agent Analysis: When software interacts with GitHub, it often sends a User-Agent string that identifies the software making the request. GitHub can analyze these strings to identify known bot software or unusual patterns indicative of automated tools.

    API Usage Patterns: GitHub provides an API for automating interactions with the platform. This API has rate limits and usage patterns that differ between human users and bots. Excessive or patterned API requests that fall outside typical human behavior can signal bot activity.

    Account Activity Patterns: Bots often exhibit behavior patterns that are different from those of human users, such as making many actions in a short period or performing repetitive tasks that are unlikely for a human user. GitHub can analyze these patterns to detect bots.

    Machine Learning Models: GitHub can employ machine learning models trained to distinguish between bot and human activities based on various signals, including the timing of actions, the diversity of actions, and interactions with other users.

    Community Reporting and Analysis: GitHub's community and security teams can also identify bots based on reports from users or through their own investigations into suspicious activities.

    Compliance with the GitHub API Terms of Service: Developers are required to follow GitHub's API usage policies, which include identifying their bots in a way that makes it clear the account is a bot (for example, through the account name or profile information). Non-compliance with these policies can lead to identification and restriction of bot accounts.

    Content and Contribution Analysis: Automated contributions, such as commits, pull requests, or issues that follow a detectable pattern or contain spammy content, can also indicate bot activity.

    It's important to note that not all bots are bad. GitHub allows the use of bots to automate workflows, manage projects, and integrate with other tools, provided they adhere to GitHub's terms of service and guidelines for responsible bot operation. Bots that violate these terms or are used for abusive purposes are subject to being flagged and potentially banned from the platform.

    @mrT23
    Copy link
    Collaborator

    mrT23 commented Mar 21, 2024

    @koid
    after thinking about this a bit, I like it.
    GitHub spends a lot of time and effort identifying bots, and utilizing their mechanism is a good idea.

    I will test it a bit, and if i see good consistent results (and I think it will), i will turn this option on by default.

    Good job :-)

    @mrT23 mrT23 merged commit b4b2c7c into Codium-ai:main Mar 21, 2024
    @koid
    Copy link
    Contributor Author

    koid commented Mar 22, 2024

    thanks review!

    @koid koid deleted the feature/ignore-bot-pr-on-github-app branch March 22, 2024 01:12
    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.

    None yet

    3 participants