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

Improve trigger condition in github actions #828

Merged
merged 3 commits into from
Mar 27, 2024

Conversation

idubnori
Copy link
Contributor

@idubnori idubnori commented Mar 27, 2024

User description

fix: #827


Type

enhancement, documentation


Description

  • Added logging in the GitHub Action runner to provide information when an action is skipped and the reason for it.
  • Updated the GitHub Action configuration documentation to include types for pull_request events. This specifies the action to run on opened, reopened, ready_for_review, and review_requested events, improving the trigger condition.

Changes walkthrough

Relevant files
Enhancement
github_action_runner.py
Add Logging for Skipped Actions                                                   

pr_agent/servers/github_action_runner.py

  • Added logging for skipping actions with a specific reason.
+2/-0     
Documentation
github.md
Specify GitHub Action Trigger Conditions                                 

docs/docs/installation/github.md

  • Added types to pull_request event to specify when the GitHub Action
    should run.
  • This change specifies the action to run on opened, reopened,
    ready_for_review, and review_requested events.
  • +2/-0     

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

    @codiumai-pr-agent-pro codiumai-pr-agent-pro bot added documentation Improvements or additions to documentation enhancement New feature or request labels Mar 27, 2024
    Copy link
    Contributor

    PR Description updated to latest commit (493f73f)

    Copy link
    Contributor

    PR Review

    ⏱️ Estimated effort to review [1-5]

    2, because the changes are straightforward and well-documented, involving minor enhancements and documentation updates.

    🏅 Score

    90

    🧪 Relevant tests

    No

    🔍 Possible issues

    No

    🔒 Security concerns

    No

    🔀 Multiple PR themes
    Sub-PR theme: Add Logging for Skipped GitHub Actions
    Relevant files:
    • pr_agent/servers/github_action_runner.py
    Sub-PR theme: Update GitHub Action Configuration Documentation
    Relevant files:
    • docs/docs/installation/github.md

    ✨ Review tool usage guide:

    Overview:
    The review tool scans the PR code changes, and generates a PR review which includes several types of feedbacks, such as possible PR issues, security threats and relevant test in the PR. More feedbacks can be added by configuring the tool.

    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=...
    
    [pr_reviewer]
    some_config1=...
    some_config2=...
    

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

    Copy link
    Contributor

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

    PR Code Suggestions

    CategorySuggestions                                                                                                                                                       
    Enhancement
    Enhance log message for better debugging.

    Consider adding a more detailed log message that includes the action variable value. This
    will help in debugging by providing context about which action is being skipped.

    pr_agent/servers/github_action_runner.py [105]

    -get_logger().info(f"Skipping action: {action}")
    +get_logger().info(f"Skipping action: {action} due to condition not met or action not supported.")
     
    Add synchronize event to trigger types for better coverage.

    Consider adding synchronize to the list of trigger types for pull_request events. This
    ensures that the action runs on subsequent commits to a pull request that is already open,
    which is a common use case.

    docs/docs/installation/github.md [10]

    -types: [opened,reopened,ready_for_review,review_requested]
    +types: [opened,reopened,ready_for_review,review_requested,synchronize]
     
    Maintainability
    Use YAML anchors and aliases for repeated sections to improve maintainability.

    To ensure consistency and avoid duplication, consider using YAML anchors and aliases for
    defining the on section that is repeated across the documentation. This will make the
    documentation easier to maintain and update.

    docs/docs/installation/github.md [8-11]

    -on:
    +on: &default_on
       pull_request:
         types: [opened,reopened,ready_for_review,review_requested]
       issue_comment:
     
    +# Later usage
    +on: *default_on
    +

    ✨ 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=...
    
    [pr_code_suggestions]
    some_config1=...
    some_config2=...
    

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

    Comment on lines 7 to 13
    ```yaml
    on:
    pull_request:
    types: [opened,reopened,ready_for_review,review_requested]
    issue_comment:
    jobs:
    pr_agent_job:
    Copy link
    Collaborator

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    /ask can i limit the 'issue_comment' to ignore bots ? can I limit it to ignore message not starting with '/' ?

    Copy link
    Contributor

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    Yes, you can limit the issue_comment trigger to ignore bots and to only act on comments that start with a /. However, these configurations are not directly available through the on.issue_comment syntax in the GitHub Actions YAML file. Instead, you would need to implement conditional checks within the jobs of your GitHub Action workflow. Here's how you can approach it:

    1. Ignore Bots: GitHub Actions provides a github context which contains information about the event that triggered the workflow. You can use the github.actor attribute to check if the actor is a bot. Bots typically have [bot] at the end of their username.

    2. Filter Comments Starting with '/': You can use the github.event.comment.body attribute to access the content of the comment and then check if it starts with a /.

    Here is an example of how you might implement these checks in a job within your GitHub Actions workflow:

    jobs:
      pr_agent_job:
        if: >-
          !contains(github.actor, '[bot]') &&
          startsWith(github.event.comment.body, '/')
        runs-on: ubuntu-latest
        steps:
        - name: Checkout code
          uses: actions/checkout@v2
        # Add other steps as needed

    In this example:

    • The if condition for the job pr_agent_job checks two things:
      • It uses !contains(github.actor, '[bot]') to ensure the actor is not a bot.
      • It uses startsWith(github.event.comment.body, '/') to ensure the comment starts with a /.
    • If both conditions are true, the job proceeds; otherwise, it's skipped.

    This approach allows you to dynamically control the execution of your GitHub Actions based on the content and source of issue comments.

    @Codium-ai Codium-ai deleted a comment from GadiZimerman Mar 27, 2024
    @Codium-ai Codium-ai deleted a comment from codiumai-pr-agent-pro bot Mar 27, 2024
    @mrT23
    Copy link
    Collaborator

    mrT23 commented Mar 27, 2024

    @idubnori
    This PR is reasonable.
    Remove the 'review_requested' flag, as it is a bug we already fixed in github app

    Also, another optimization I want is to ignore bots. So the action should be:

    on:
      pull_request:
        types: [opened, reopened, ready_for_review]
      issue_comment:
    
    jobs:
      pr_agent_job:
        if: ${{ github.event.sender.type != 'Bot' }}
    

    there are additional optimizations that can be done (ignore comments if they don't start with '/', for example), but lets leave them to future PRs.

    Adpat the PR to the condition above, and we can merge it

    @idubnori
    Copy link
    Contributor Author

    @mrT23 Thank you for your reviewing. fixed them.

    @mrT23 mrT23 merged commit a86913a into Codium-ai:main Mar 27, 2024
    Copy link
    Contributor

    @barnett-yuxiang barnett-yuxiang left a comment

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    cool

    @idubnori idubnori deleted the work/fix-827 branch March 28, 2024 16:23
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    documentation Improvements or additions to documentation enhancement New feature or request Review effort [1-5]: 2
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    Trigger condition improvement in github actions
    3 participants