diff --git a/INSTALL.md b/INSTALL.md index ec6090b0..4e588b92 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -368,7 +368,7 @@ PYTHONPATH="/PATH/TO/PROJECTS/pr-agent" python pr_agent/cli.py \ ``` WEBHOOK_SECRET=$(python -c "import secrets; print(secrets.token_hex(10))") ``` -3. Follow the instructions to build the Docker image, setup a secrets file and deploy on your own server from [Method 5](#method-5-run-as-a-github-app) steps 4-7. +3. Follow the instructions to build the Docker image, setup a secrets file and deploy on your own server from [Method 5](#run-as-a-github-app) steps 4-7. 4. In the secrets file, fill in the following: - Your OpenAI key. - In the [gitlab] section, fill in personal_access_token and shared_secret. The access token can be a personal access token, or a group or project access token. diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 082c0583..bfef1240 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -9,9 +9,10 @@ ### Added::Algo - New tool - [generate_labels](https://github.com/Codium-ai/pr-agent/blob/main/docs/GENERATE_CUSTOM_LABELS.md) - New ability to use [customize labels](https://github.com/Codium-ai/pr-agent/blob/main/docs/GENERATE_CUSTOM_LABELS.md#how-to-enable-custom-labels) on the `review` and `describe` tools. +- New tool - [add_docs](https://github.com/Codium-ai/pr-agent/blob/main/docs/ADD_DOCUMENTATION.md) - GitHub Action: Can now use a `.pr_agent.toml` file to control configuration parameters (see [Usage Guide](./Usage.md#working-with-github-action)). -- GitHub App: Added ability to trigger tools on push events (see [link](https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/settings/configuration.toml#L91)) -- Support custom domain URLs for azure devops integration (see [link](https://github.com/Codium-ai/pr-agent/pull/381)). +- GitHub App: Added ability to trigger tools on [push events](https://github.com/Codium-ai/pr-agent/blob/main/Usage.md#github-app-automatic-tools-for-new-code-pr-push) +- Support custom domain URLs for Azure devops integration (see [link](https://github.com/Codium-ai/pr-agent/pull/381)). - PR Description default mode is now in [bullet points](https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/settings/configuration.toml#L35). ### Added::Documentation diff --git a/Usage.md b/Usage.md index 95b52b57..2548431f 100644 --- a/Usage.md +++ b/Usage.md @@ -111,16 +111,28 @@ Any configuration value in [configuration file](pr_agent/settings/configuration. When running PR-Agent from [GitHub App](INSTALL.md#method-5-run-as-a-github-app), the default configurations from a pre-built docker will be initially loaded. #### GitHub app automatic tools -The [github_app](pr_agent/settings/configuration.toml#L56) section defines GitHub app specific configurations. -An important parameter is `pr_commands`, which is a list of tools that will be **run automatically** when a new PR is opened: +The [github_app](pr_agent/settings/configuration.toml#L56) section defines GitHub app specific configurations. +In this section you can define configurations to control the conditions for which tools will **run automatically**. +Note that a local `.pr_agent.toml` file enables you to edit and customize the default parameters of any tool, not just the ones that are 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 action happens (e.g. 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", "/auto_review", ] ``` -This means that when a new PR is opened, PR-Agent will run the `describe` and `auto_review` tools. +This means that when a new PR is opened/reopened or marked as ready for review, PR-Agent will run the `describe` and `auto_review` tools. For the describe tool, 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. @@ -135,11 +147,27 @@ When a new PR is opened, PR-Agent will run the `describe` tool with the above pa To cancel the automatic run of all the tools, set: ``` [github_app] -pr_commands = "" +handle_pr_actions = [] ``` +##### GitHub app automatic tools for new code (PR push) +In addition the running automatic tools when a PR is opened, the GitHub app can also respond to new code that is pushed to an open PR. -Note that a local `.pr_agent.toml` file enables you to edit and customize the default parameters of any tool, not just the ones that are run automatically. +The configuration toggle `handle_push_trigger` can be used to enable this feature. +The configuration parameter `push_commands` defines the list of tools that will be **run automatically** when new code is pushed to the PR. +``` +[github_app] +handle_push_trigger = true +push_commands = [ + "/describe --pr_description.add_original_user_description=true --pr_description.keep_original_user_title=true", + "/auto_review -i --pr_reviewer.remove_previous_review_comment=true", +] +``` +The means that when new code is pused to the PR, the PR-Agent will run the `describe` and incremental `auto_review` tools. +For the describe tool, the `add_original_user_description` and `keep_original_user_title` parameters will be set to true. +For the `auto_review` tool, it will run in incremental mode, and the `remove_previous_review_comment` parameter will be set to true. + +Much like the configurations for `pr_commands`, you can override the default tool paramteres by uploading a local configuration file to the root of your repo. #### Editing the prompts The prompts for the various PR-Agent tools are defined in the `pr_agent/settings` folder. diff --git a/docs/GENERATE_CUSTOM_LABELS.md b/docs/GENERATE_CUSTOM_LABELS.md index 2035b02c..c915a0c4 100644 --- a/docs/GENERATE_CUSTOM_LABELS.md +++ b/docs/GENERATE_CUSTOM_LABELS.md @@ -10,6 +10,7 @@ For example: If we wish to add detect changes to SQL queries in a given PR, we can add the following custom label along with its description: + When running the `generate_labels` tool on a PR that includes changes in SQL queries, it will automatically suggest the custom label: diff --git a/pr_agent/algo/utils.py b/pr_agent/algo/utils.py index 423771a3..304c2200 100644 --- a/pr_agent/algo/utils.py +++ b/pr_agent/algo/utils.py @@ -101,7 +101,8 @@ def parse_code_suggestion(code_suggestions: dict, gfm_supported: bool=True) -> s markdown_text += f" **{sub_key}:** {sub_value}\n" if not gfm_supported: if "relevant line" not in sub_key.lower(): # nicer presentation - markdown_text = markdown_text.rstrip('\n') + "\\\n" + # markdown_text = markdown_text.rstrip('\n') + "\\\n" # works for gitlab + markdown_text = markdown_text.rstrip('\n') + " \n" # works for gitlab and bitbucker markdown_text += "\n" return markdown_text diff --git a/pr_agent/tools/pr_reviewer.py b/pr_agent/tools/pr_reviewer.py index be938b4a..fdb7161e 100644 --- a/pr_agent/tools/pr_reviewer.py +++ b/pr_agent/tools/pr_reviewer.py @@ -119,7 +119,8 @@ class PRReviewer: previous_review_comment = self._get_previous_review_comment() self.git_provider.publish_comment(pr_comment) self.git_provider.remove_initial_comment() - self._remove_previous_review_comment(previous_review_comment) + if previous_review_comment: + self._remove_previous_review_comment(previous_review_comment) if get_settings().pr_reviewer.inline_code_comments: get_logger().info('Pushing inline code comments...') self._publish_inline_code_comments()