From 06dede29f27b6270488bac0defc37533d59c165a Mon Sep 17 00:00:00 2001 From: mrT23 Date: Sat, 27 Jan 2024 21:15:23 +0200 Subject: [PATCH] feat: Update configuration and handling of GitHub Action settings --- .github/workflows/pr-agent-review.yaml | 6 +++-- Usage.md | 32 ++++++++++-------------- pr_agent/servers/github_action_runner.py | 19 ++++++++++---- pr_agent/settings/configuration.toml | 4 +-- 4 files changed, 33 insertions(+), 28 deletions(-) diff --git a/.github/workflows/pr-agent-review.yaml b/.github/workflows/pr-agent-review.yaml index 1fe03133..aa7a8fe0 100644 --- a/.github/workflows/pr-agent-review.yaml +++ b/.github/workflows/pr-agent-review.yaml @@ -27,7 +27,9 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} PINECONE.API_KEY: ${{ secrets.PINECONE_API_KEY }} PINECONE.ENVIRONMENT: ${{ secrets.PINECONE_ENVIRONMENT }} - GITHUB_ACTION.AUTO_REVIEW: true - GITHUB_ACTION.AUTO_IMPROVE: true + GITHUB_ACTION_CONFIG.AUTO_DESCRIBE: true + GITHUB_ACTION_CONFIG.AUTO_REVIEW: true + GITHUB_ACTION_CONFIG.AUTO_IMPROVE: true + diff --git a/Usage.md b/Usage.md index 76bef1d7..efb4dcb6 100644 --- a/Usage.md +++ b/Usage.md @@ -145,25 +145,18 @@ Then you will overwrite the default number of code suggestions to 1. The [github_app](pr_agent/settings/configuration.toml#L76) section defines GitHub app-specific configurations. In this section, you can define configurations to control the conditions for which tools will **run automatically**. -##### GitHub app automatic tools for PR actions -The GitHub app can respond to the following actions on a PR: -1. `opened` - Opening a new PR -2. `reopened` - Reopening a closed PR -3. `ready_for_review` - Moving a PR from Draft to Open -4. `review_requested` - Specifically requesting review (in the PR reviewers list) from the `github-actions[bot]` user - -The configuration parameter `handle_pr_actions` defines the list of actions for which the GitHub app will trigger the PR-Agent. -The configuration parameter `pr_commands` defines the list of tools that will be **run automatically** when one of the above actions happens (e.g., a new PR is opened): +##### GitHub app automatic tools for PR actions +The configuration parameter `pr_commands` defines the list of tools that will be **run automatically** when a new PR is opened. ``` [github_app] -handle_pr_actions = ['opened', 'reopened', 'ready_for_review', 'review_requested'] pr_commands = [ "/describe --pr_description.add_original_user_description=true --pr_description.keep_original_user_title=true", - "/review", + "/review --pr_reviewer.num_code_suggestions=0", + "/improve", ] ``` -This means that when a new PR is opened/reopened or marked as ready for review, PR-Agent will run the `describe` and `review` tools. -For the `describe` tool, the `add_original_user_description` and `keep_original_user_title` parameters will be set to true. +This means that when a new PR is opened/reopened or marked as ready for review, PR-Agent will run the `describe`, `review` and `improve` tools. +For the `describe` tool, for example, the `add_original_user_description` and `keep_original_user_title` parameters will be set to true. You can override the default tool parameters by uploading a local configuration file called `.pr_agent.toml` to the root of your repo. For example, if your local `.pr_agent.toml` file contains: @@ -180,7 +173,7 @@ To cancel the automatic run of all the tools, set: handle_pr_actions = [] ``` -##### GitHub app automatic tools for new code (PR push) +##### GitHub app automatic tools for push actions (commits to an open PR) In addition to running automatic tools when a PR is opened, the GitHub app can also respond to new code that is pushed to an open PR. The configuration toggle `handle_push_trigger` can be used to enable this feature. @@ -217,17 +210,18 @@ user=""" Note that the new prompt will need to generate an output compatible with the relevant [post-process function](./pr_agent/tools/pr_description.py#L137). ### Working with GitHub Action -You can configure settings in GitHub action by adding environment variables under the env section in `.github/workflows/pr_agent.yml` file. +`GitHub Action` is a different way to trigger PR-Agent tools, and uses a different configuration mechanism than `GitHub App`. +You can configure settings for `GitHub Action` by adding environment variables under the env section in `.github/workflows/pr_agent.yml` file. Specifically, start by setting the following environment variables: ```yaml env: OPENAI_KEY: ${{ secrets.OPENAI_KEY }} # Make sure to add your OpenAI key to your repo secrets GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Make sure to add your GitHub token to your repo secrets - github_action.auto_review: "true" # enable\disable auto review - github_action.auto_describe: "true" # enable\disable auto describe - github_action.auto_improve: "false" # enable\disable auto improve + github_action_config.auto_review: "true" # enable\disable auto review + github_action_config.auto_describe: "true" # enable\disable auto describe + github_action_config.auto_improve: "false" # enable\disable auto improve ``` -`github_action.auto_review`, `github_action.auto_describe` and `github_action.auto_improve` are used to enable/disable automatic tools that run when a new PR is opened. +`github_action_config.auto_review`, `github_action_config.auto_describe` and `github_action_config.auto_improve` are used to enable/disable automatic tools that run when a new PR is opened. If not set, the default option is that only the `review` tool will run automatically when a new PR is opened. Note that you can give additional config parameters by adding environment variables to `.github/workflows/pr_agent.yml`, or by using a `.pr_agent.toml` file in the root of your repo, similar to the GitHub App usage. diff --git a/pr_agent/servers/github_action_runner.py b/pr_agent/servers/github_action_runner.py index 45f9c712..b56eeb07 100644 --- a/pr_agent/servers/github_action_runner.py +++ b/pr_agent/servers/github_action_runner.py @@ -82,14 +82,23 @@ async def run_action(): if action in ["opened", "reopened"]: pr_url = event_payload.get("pull_request", {}).get("url") if pr_url: + # legacy - supporting both GITHUB_ACTION and GITHUB_ACTION_CONFIG auto_review = get_setting_or_env("GITHUB_ACTION.AUTO_REVIEW", None) + if auto_review is None: + auto_review = get_setting_or_env("GITHUB_ACTION_CONFIG.AUTO_REVIEW", None) + auto_describe = get_setting_or_env("GITHUB_ACTION.AUTO_DESCRIBE", None) + if auto_describe is None: + auto_describe = get_setting_or_env("GITHUB_ACTION_CONFIG.AUTO_DESCRIBE", None) + auto_improve = get_setting_or_env("GITHUB_ACTION.AUTO_IMPROVE", None) + if auto_improve is None: + auto_improve = get_setting_or_env("GITHUB_ACTION_CONFIG.AUTO_IMPROVE", None) + + # invoke by default all three tools + if auto_describe is None or is_true(auto_describe): + await PRDescription(pr_url).run() if auto_review is None or is_true(auto_review): await PRReviewer(pr_url).run() - auto_describe = get_setting_or_env("GITHUB_ACTION.AUTO_DESCRIBE", None) - if is_true(auto_describe): - await PRDescription(pr_url).run() - auto_improve = get_setting_or_env("GITHUB_ACTION.AUTO_IMPROVE", None) - if is_true(auto_improve): + if auto_improve is None or is_true(auto_improve): await PRCodeSuggestions(pr_url).run() # Handle issue comment event diff --git a/pr_agent/settings/configuration.toml b/pr_agent/settings/configuration.toml index 5d9a84ab..2c680e8f 100644 --- a/pr_agent/settings/configuration.toml +++ b/pr_agent/settings/configuration.toml @@ -47,7 +47,7 @@ enable_help_text=true # Determines whether to include help text in the PR review publish_labels=true publish_description_as_comment=false add_original_user_description=true -keep_original_user_title=false +keep_original_user_title=true use_bullet_points=true extra_instructions = "" enable_pr_type=true @@ -100,7 +100,7 @@ base_url = "https://api.github.com" publish_inline_comments_fallback_with_verification = true try_fix_invalid_inline_comments = true -[github_action] +[github_action_config] # auto_review = true # set as env var in .github/workflows/pr-agent.yaml # auto_describe = true # set as env var in .github/workflows/pr-agent.yaml # auto_improve = true # set as env var in .github/workflows/pr-agent.yaml