From 1e2d4e98303f864a325b71c61b7dfb21182a54b1 Mon Sep 17 00:00:00 2001 From: Ikko Eltociear Ashimine Date: Thu, 25 Jan 2024 15:03:58 +0900 Subject: [PATCH 01/50] docs: fix file name --- README.md | 2 +- docs/{Full_enviroments.md => Full_environments.md} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename docs/{Full_enviroments.md => Full_environments.md} (100%) diff --git a/README.md b/README.md index 89d9566f..b0e36c2f 100644 --- a/README.md +++ b/README.md @@ -190,7 +190,7 @@ See the [Tools Guide](./docs/TOOLS_GUIDE.md) for a detailed description of the d - 💎 means this feature is available only in [PR-Agent Pro](https://www.codium.ai/pricing/) -- Support for additional git providers is described in [here](./docs/Full_enviroments.md) +- Support for additional git providers is described in [here](./docs/Full_environments.md) ## Try it now diff --git a/docs/Full_enviroments.md b/docs/Full_environments.md similarity index 100% rename from docs/Full_enviroments.md rename to docs/Full_environments.md From 07eaa59e782ef433f3be6ca292060a8f7c38fb93 Mon Sep 17 00:00:00 2001 From: "Hussam.lawen" Date: Thu, 25 Jan 2024 11:07:43 +0200 Subject: [PATCH 02/50] small fixes --- pr_agent/tools/pr_code_suggestions.py | 3 ++- pr_agent/tools/pr_description.py | 13 +++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/pr_agent/tools/pr_code_suggestions.py b/pr_agent/tools/pr_code_suggestions.py index 97c183f2..1456f9a6 100644 --- a/pr_agent/tools/pr_code_suggestions.py +++ b/pr_agent/tools/pr_code_suggestions.py @@ -190,7 +190,8 @@ class PRCodeSuggestions: original_initial_line = None for file in self.diff_files: if file.filename.strip() == relevant_file: - original_initial_line = file.head_file.splitlines()[relevant_lines_start - 1] + if file.head_file: # in bitbucket, head_file is empty. toDo: fix this + original_initial_line = file.head_file.splitlines()[relevant_lines_start - 1] break if original_initial_line: suggested_initial_line = new_code_snippet.splitlines()[0] diff --git a/pr_agent/tools/pr_description.py b/pr_agent/tools/pr_description.py index 0cc32b7f..5eb78549 100644 --- a/pr_agent/tools/pr_description.py +++ b/pr_agent/tools/pr_description.py @@ -113,16 +113,21 @@ class PRDescription: if get_settings().config.publish_output: get_logger().info(f"Pushing answer {self.pr_id}") + + # publish labels + if get_settings().pr_description.publish_labels and self.git_provider.is_supported("get_labels"): + current_labels = self.git_provider.get_pr_labels() + user_labels = get_user_labels(current_labels) + self.git_provider.publish_labels(pr_labels + user_labels) + + # publish description if get_settings().pr_description.publish_description_as_comment: get_logger().info(f"Publishing answer as comment") self.git_provider.publish_comment(full_markdown_description) else: self.git_provider.publish_description(pr_title, pr_body) - if get_settings().pr_description.publish_labels and self.git_provider.is_supported("get_labels"): - current_labels = self.git_provider.get_pr_labels() - user_labels = get_user_labels(current_labels) - self.git_provider.publish_labels(pr_labels + user_labels) + # publish final update message if (get_settings().pr_description.final_update_message and hasattr(self.git_provider, 'pr_url') and self.git_provider.pr_url): latest_commit_url = self.git_provider.get_latest_commit_url() From 06dede29f27b6270488bac0defc37533d59c165a Mon Sep 17 00:00:00 2001 From: mrT23 Date: Sat, 27 Jan 2024 21:15:23 +0200 Subject: [PATCH 03/50] 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 From 76f44b13f8d23ba2edc1b5008113f5a810fd0511 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Sat, 27 Jan 2024 21:20:10 +0200 Subject: [PATCH 04/50] docs: Update GitHub app configurations section in Usage.md --- Usage.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Usage.md b/Usage.md index efb4dcb6..4593c925 100644 --- a/Usage.md +++ b/Usage.md @@ -142,8 +142,7 @@ num_code_suggestions=1 Then you will overwrite the default number of code suggestions to 1. #### GitHub app automatic tools -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**. +The [github_app](pr_agent/settings/configuration.toml#L108) section defines GitHub app specific configurations. ##### 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. @@ -222,7 +221,7 @@ Specifically, start by setting the following environment variables: github_action_config.auto_improve: "false" # enable\disable auto improve ``` `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. +If not set, the default option is that all three tools 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. From 98ce0a70361475fa5567e1a657e44123a8e8de43 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Sat, 27 Jan 2024 21:25:43 +0200 Subject: [PATCH 05/50] s --- pr_agent/servers/help.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/pr_agent/servers/help.py b/pr_agent/servers/help.py index 376475fe..1d48be59 100644 --- a/pr_agent/servers/help.py +++ b/pr_agent/servers/help.py @@ -48,7 +48,7 @@ Examples for extra instructions: ``` [pr_reviewer] # /review # extra_instructions=""" -In the code feedback section, emphasize the following: +In the 'general suggestions' 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? @@ -71,14 +71,14 @@ Edit this field to enable/disable the tool, or to change the used configurations """ output += "\n\n\n\n" - # code feedback - output += "
About the 'Code feedback' section
\n\n" - output+="""\ -The `review` tool provides several type of feedbacks, one of them is code suggestions. -If you are interested **only** in the code suggestions, it is recommended to use the [`improve`](https://github.com/Codium-ai/pr-agent/blob/main/docs/IMPROVE.md) feature instead, since it dedicated only to code suggestions, and usually gives better results. -Use the `review` tool if you want to get a more comprehensive feedback, which includes code suggestions as well. -""" - output += "\n\n
\n\n" +# # code feedback +# output += "
About the 'Code feedback' section
\n\n" +# output+="""\ +# The `review` tool provides several type of feedbacks, one of them is code suggestions. +# If you are interested **only** in the code suggestions, it is recommended to use the [`improve`](https://github.com/Codium-ai/pr-agent/blob/main/docs/IMPROVE.md) feature instead, since it dedicated only to code suggestions, and usually gives better results. +# Use the `review` tool if you want to get a more comprehensive feedback, which includes code suggestions as well. +# """ +# output += "\n\n
\n\n" # auto-labels output += "
Auto-labels
\n\n" @@ -309,8 +309,9 @@ Use triple quotes to write multi-line instructions. Use bullet points to make th output += """\ - 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. -- Best quality will be obtained by using 'improve --extended' mode. +- 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 :gem:](https://github.com/Codium-ai/pr-agent/blob/main/docs/CUSTOM_SUGGESTIONS.md) tool +- With large PRs, best quality will be obtained by using 'improve --extended' mode. + """ output += "\n\n
\n\n"\ From ecb46435b3487a897d96462992f5fc88afb78c9a Mon Sep 17 00:00:00 2001 From: mrT23 Date: Sat, 27 Jan 2024 21:29:19 +0200 Subject: [PATCH 06/50] s --- Usage.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Usage.md b/Usage.md index 4593c925..08ab0119 100644 --- a/Usage.md +++ b/Usage.md @@ -221,7 +221,7 @@ Specifically, start by setting the following environment variables: github_action_config.auto_improve: "false" # enable\disable auto improve ``` `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 all three tools will run automatically when a new PR is opened. +If not set, the default configuration is for all three tools to 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. From 335654b02a5f7d9780fb73acde329c2c583dcd5a Mon Sep 17 00:00:00 2001 From: Tal Date: Sat, 27 Jan 2024 21:38:25 +0200 Subject: [PATCH 07/50] Update Usage.md --- Usage.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Usage.md b/Usage.md index 08ab0119..cf88f207 100644 --- a/Usage.md +++ b/Usage.md @@ -218,7 +218,7 @@ Specifically, start by setting the following environment variables: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Make sure to add your GitHub token to your repo secrets 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_config.auto_improve: "true" # enable\disable auto improve ``` `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 configuration is for all three tools to run automatically when a new PR is opened. From 47af04d15819d9486d5c7da5569f969c43db1972 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Sun, 28 Jan 2024 20:26:58 +0200 Subject: [PATCH 08/50] s --- README.md | 4 ++++ docs/TEST.md | 25 +++++++++++++++++++++++++ pr_agent/settings/configuration.toml | 6 ++++++ 3 files changed, 35 insertions(+) create mode 100644 docs/TEST.md diff --git a/README.md b/README.md index b0e36c2f..85a4067f 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,9 @@ Making pull requests less painful with an AI agent - [Why use PR-Agent?](#why-use-pr-agent) ## News and Updates +### Jan 28, 2024 +- 💎 Test - A new tool, [`/test component_name`](https://github.com/Codium-ai/pr-agent/blob/main/docs/TEST.md), was added to PR-Agent Pro. The tool will generate tests for a selected component, based on the PR code changes. +- 💎 Analyze - The [`/analyze`](https://github.com/Codium-ai/pr-agent/blob/main/docs/Analyze.md) tool was updated and simplified. It now presents a summary of the code components that were changed in the PR. ### Jan 21, 2024 - 💎 Custom suggestions - A new tool, `/custom_suggestions`, was added to PR-Agent Pro. The tool will propose only suggestions that follow specific guidelines defined by the user. See [here](https://github.com/Codium-ai/pr-agent/blob/main/docs/CUSTOM_SUGGESTIONS.md) for more details. @@ -168,6 +171,7 @@ See the [Tools Guide](./docs/TOOLS_GUIDE.md) for a detailed description of the d | | Improve | :white_check_mark: | :white_check_mark: | :white_check_mark: | | | ⮑ Extended | :white_check_mark: | :white_check_mark: | :white_check_mark: | | | [Custom Suggestions](https://github.com/Codium-ai/pr-agent/blob/main/docs/CUSTOM_SUGGESTIONS.md) 💎 | :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | [Test](https://github.com/Codium-ai/pr-agent/blob/main/docs/Test.md) 💎 | :white_check_mark: | :white_check_mark: | :white_check_mark: | | | Reflect and Review | :white_check_mark: | :white_check_mark: | :white_check_mark: | | | Update CHANGELOG.md | :white_check_mark: | :white_check_mark: | :white_check_mark: | | | Find Similar Issue | :white_check_mark: | | | diff --git a/docs/TEST.md b/docs/TEST.md new file mode 100644 index 00000000..0d619d72 --- /dev/null +++ b/docs/TEST.md @@ -0,0 +1,25 @@ +# Test Tool 💎 +By combining LLM abilities with static code analysis, the `test` tool generate tests for a selected component, based on the PR code changes. +Language that are currently supported by the tool: Python, Java, C++, JavaScript, TypeScript. +It can be invoked manually by commenting on any PR: +``` +/test component_name +``` +where component_name is the name of a specific component in the PR. +To get a list of the components that changed in the PR, use the [`analyze`](https://github.com/Codium-ai/pr-agent/blob/main/docs/Analyze.md) tool. + + +An example [result](https://github.com/Codium-ai/pr-agent/pull/598#issuecomment-1913679429): + + +___ + +___ + + + +### Configuration options +- `num_tests`: number of tests to generate. Default is 3. +- `testing_framework`: the testing framework to use. If not set, for Python it will use `pytest`, for Java it will use `JUnit`, for C++ it will use `Catch2`, and for JavaScript and TypeScript it will use `jest`. +- `avoid_mocks`: if set to true, the tool will try to avoid using mocks in the generated tests. Default is true. Note that even if this option is set to true, the tool might still use mocks if it cannot generate a test without them. +- `extra_instructions`: Optional extra instructions to the tool. For example: "use the following mock injection scheme: ...". \ No newline at end of file diff --git a/pr_agent/settings/configuration.toml b/pr_agent/settings/configuration.toml index 2c680e8f..3a97fbb5 100644 --- a/pr_agent/settings/configuration.toml +++ b/pr_agent/settings/configuration.toml @@ -90,6 +90,12 @@ extra_instructions = "" [pr_analyze] # /analyze # +[pr_test] # /test # +testing_framework = "" # specify the testing framework you want to use +num_tests=3 # number of tests to generate. max 5. +avoid_mocks=true # if true, the generated tests will prefer to use real objects instead of mocks +extra_instructions = "" + [pr_config] # /config # [github] From 5f1722ed4a6cfdef118e6f4917df9ce2db5b2e0d Mon Sep 17 00:00:00 2001 From: mrT23 Date: Sun, 28 Jan 2024 20:30:40 +0200 Subject: [PATCH 09/50] s --- docs/TEST.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/docs/TEST.md b/docs/TEST.md index 0d619d72..f25ae60d 100644 --- a/docs/TEST.md +++ b/docs/TEST.md @@ -1,11 +1,10 @@ # Test Tool 💎 By combining LLM abilities with static code analysis, the `test` tool generate tests for a selected component, based on the PR code changes. -Language that are currently supported by the tool: Python, Java, C++, JavaScript, TypeScript. It can be invoked manually by commenting on any PR: ``` /test component_name ``` -where component_name is the name of a specific component in the PR. +where 'component_name' is the name of a specific component in the PR. To get a list of the components that changed in the PR, use the [`analyze`](https://github.com/Codium-ai/pr-agent/blob/main/docs/Analyze.md) tool. @@ -17,9 +16,12 @@ ___ ___ +Language that are currently supported by the tool: Python, Java, C++, JavaScript, TypeScript. + + ### Configuration options - `num_tests`: number of tests to generate. Default is 3. - `testing_framework`: the testing framework to use. If not set, for Python it will use `pytest`, for Java it will use `JUnit`, for C++ it will use `Catch2`, and for JavaScript and TypeScript it will use `jest`. -- `avoid_mocks`: if set to true, the tool will try to avoid using mocks in the generated tests. Default is true. Note that even if this option is set to true, the tool might still use mocks if it cannot generate a test without them. +- `avoid_mocks`: if set to true, the tool will try to avoid using mocks in the generated tests. Note that even if this option is set to true, the tool might still use mocks if it cannot generate a test without them. Default is true. - `extra_instructions`: Optional extra instructions to the tool. For example: "use the following mock injection scheme: ...". \ No newline at end of file From 2bebfba4b68566819cbd31054106fa8047c5f769 Mon Sep 17 00:00:00 2001 From: Tal Date: Sun, 28 Jan 2024 20:39:45 +0200 Subject: [PATCH 10/50] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 85a4067f..4bd2c06d 100644 --- a/README.md +++ b/README.md @@ -81,6 +81,8 @@ CodiumAI PR-Agent is an open-source tool to help efficiently review and handle p ‣ **Analyze 💎 ([`/analyze`](./docs/Analyze.md))**: Automatically analyzes the PR, and presents changes walkthrough for each component. \ ‣ **Custom Suggestions 💎 ([`/custom_suggestions`](./docs/CUSTOM_SUGGESTIONS.md))**: Automatically generates custom suggestions for improving the PR code, based on specific guidelines defined by the user. +\ +‣ **Generate Tests 💎 ([`/test component_name`](./docs/TEST.md))**: Automatically generates unit tests for a selected component, based on the PR code changes. See the [Installation Guide](./INSTALL.md) for instructions on installing and running the tool on different git platforms. From 78bb54bd8fa026fb4997c074b976fd67708be2e0 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Mon, 29 Jan 2024 11:11:30 +0200 Subject: [PATCH 11/50] s --- README.md | 71 ++++++++++++++++++++++++++----------------------------- 1 file changed, 34 insertions(+), 37 deletions(-) diff --git a/README.md b/README.md index 85a4067f..4b8fe02f 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,40 @@ You can of course overwrite these defaults by adding a `.pr_agent.toml` file to CodiumAI PR-Agent is an open-source tool to help efficiently review and handle pull requests. It automatically analyzes the pull request and can provide several types of commands: +| | | GitHub | Gitlab | Bitbucket | +|-------|---------------------------------------------|:------:|:------:|:---------:| +| TOOLS | Review | :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | ⮑ Incremental | :white_check_mark: | | | +| | ⮑ [SOC2 Compliance](https://github.com/Codium-ai/pr-agent/blob/main/docs/REVIEW.md#soc2-ticket-compliance-) 💎 | :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | Ask | :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | Describe | :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | ⮑ [Inline file summary](https://github.com/Codium-ai/pr-agent/blob/main/docs/DESCRIBE.md#inline-file-summary-) 💎 | :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | Improve | :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | ⮑ Extended | :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | [Custom Suggestions](https://github.com/Codium-ai/pr-agent/blob/main/docs/CUSTOM_SUGGESTIONS.md) 💎 | :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | [Test](https://github.com/Codium-ai/pr-agent/blob/main/docs/Test.md) 💎 | :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | Reflect and Review | :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | Update CHANGELOG.md | :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | Find Similar Issue | :white_check_mark: | | | +| | [Add PR Documentation](https://github.com/Codium-ai/pr-agent/blob/main/docs/ADD_DOCUMENTATION.md) 💎 | :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | [Generate Custom Labels](https://github.com/Codium-ai/pr-agent/blob/main/docs/DESCRIBE.md#handle-custom-labels-from-the-repos-labels-page-gem) 💎 | :white_check_mark: | :white_check_mark: | | +| | [Analyze PR Components](https://github.com/Codium-ai/pr-agent/blob/main/docs/Analyze.md) 💎 | :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | | | | | +| USAGE | CLI | :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | App / webhook | :white_check_mark: | :white_check_mark: | | +| | Tagging bot | :white_check_mark: | | | +| | Actions | :white_check_mark: | | | +| | | | | | +| CORE | PR compression | :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | Repo language prioritization | :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | Adaptive and token-aware
file patch fitting | :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | Multiple models support | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | Incremental PR review | :white_check_mark: | | | +| | [Static code analysis](https://github.com/Codium-ai/pr-agent/blob/main/docs/Analyze.md) 💎 | :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | [Global configuration](https://github.com/Codium-ai/pr-agent/blob/main/Usage.md#global-configuration-file-) 💎 | :white_check_mark: | :white_check_mark: | :white_check_mark: | +- 💎 means this feature is available only in [PR-Agent Pro](https://www.codium.ai/pricing/) +- Support for additional git providers is described in [here](./docs/Full_environments.md) + ‣ **Auto Description ([`/describe`](./docs/DESCRIBE.md))**: Automatically generating PR description - title, type, summary, code walkthrough and labels. \ ‣ **Auto Review ([`/review`](./docs/REVIEW.md))**: Adjustable feedback about the PR main theme, type, relevant tests, security issues, score, and various suggestions for the PR content. @@ -158,43 +192,6 @@ See the [Tools Guide](./docs/TOOLS_GUIDE.md) for a detailed description of the d
-## Features overview -`PR-Agent` offers extensive pull request functionalities across various git providers: -| | | GitHub | Gitlab | Bitbucket | -|-------|---------------------------------------------|:------:|:------:|:---------:| -| TOOLS | Review | :white_check_mark: | :white_check_mark: | :white_check_mark: | -| | ⮑ Incremental | :white_check_mark: | | | -| | ⮑ [SOC2 Compliance](https://github.com/Codium-ai/pr-agent/blob/main/docs/REVIEW.md#soc2-ticket-compliance-) 💎 | :white_check_mark: | :white_check_mark: | :white_check_mark: | -| | Ask | :white_check_mark: | :white_check_mark: | :white_check_mark: | -| | Describe | :white_check_mark: | :white_check_mark: | :white_check_mark: | -| | ⮑ [Inline file summary](https://github.com/Codium-ai/pr-agent/blob/main/docs/DESCRIBE.md#inline-file-summary-) 💎 | :white_check_mark: | :white_check_mark: | :white_check_mark: | -| | Improve | :white_check_mark: | :white_check_mark: | :white_check_mark: | -| | ⮑ Extended | :white_check_mark: | :white_check_mark: | :white_check_mark: | -| | [Custom Suggestions](https://github.com/Codium-ai/pr-agent/blob/main/docs/CUSTOM_SUGGESTIONS.md) 💎 | :white_check_mark: | :white_check_mark: | :white_check_mark: | -| | [Test](https://github.com/Codium-ai/pr-agent/blob/main/docs/Test.md) 💎 | :white_check_mark: | :white_check_mark: | :white_check_mark: | -| | Reflect and Review | :white_check_mark: | :white_check_mark: | :white_check_mark: | -| | Update CHANGELOG.md | :white_check_mark: | :white_check_mark: | :white_check_mark: | -| | Find Similar Issue | :white_check_mark: | | | -| | [Add PR Documentation](https://github.com/Codium-ai/pr-agent/blob/main/docs/ADD_DOCUMENTATION.md) 💎 | :white_check_mark: | :white_check_mark: | :white_check_mark: | -| | [Generate Custom Labels](https://github.com/Codium-ai/pr-agent/blob/main/docs/DESCRIBE.md#handle-custom-labels-from-the-repos-labels-page-gem) 💎 | :white_check_mark: | :white_check_mark: | | -| | [Analyze PR Components](https://github.com/Codium-ai/pr-agent/blob/main/docs/Analyze.md) 💎 | :white_check_mark: | :white_check_mark: | :white_check_mark: | -| | | | | | -| USAGE | CLI | :white_check_mark: | :white_check_mark: | :white_check_mark: | -| | App / webhook | :white_check_mark: | :white_check_mark: | | -| | Tagging bot | :white_check_mark: | | | -| | Actions | :white_check_mark: | | | -| | | | | | -| CORE | PR compression | :white_check_mark: | :white_check_mark: | :white_check_mark: | -| | Repo language prioritization | :white_check_mark: | :white_check_mark: | :white_check_mark: | -| | Adaptive and token-aware
file patch fitting | :white_check_mark: | :white_check_mark: | :white_check_mark: | -| | Multiple models support | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | -| | Incremental PR review | :white_check_mark: | | | -| | [Static code analysis](https://github.com/Codium-ai/pr-agent/blob/main/docs/Analyze.md) 💎 | :white_check_mark: | :white_check_mark: | :white_check_mark: | -| | [Global configuration](https://github.com/Codium-ai/pr-agent/blob/main/Usage.md#global-configuration-file-) 💎 | :white_check_mark: | :white_check_mark: | :white_check_mark: | - - -- 💎 means this feature is available only in [PR-Agent Pro](https://www.codium.ai/pricing/) -- Support for additional git providers is described in [here](./docs/Full_environments.md) ## Try it now From 467e2ae68ed3662611b7ec5252f059c3b813afd4 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Mon, 29 Jan 2024 11:19:37 +0200 Subject: [PATCH 12/50] s --- README.md | 64 +++++++++++++++++++++++++++---------------------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index 4b8fe02f..29043fe5 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,6 @@ Making pull requests less painful with an AI agent - [News and Updates](#news-and-updates) - [Overview](#overview) - [Example results](#example-results) -- [Features overview](#features-overview) - [Try it now](#try-it-now) - [Installation](#installation) - [PR-Agent Pro 💎](#pr-agent-pro-) @@ -62,39 +61,40 @@ You can of course overwrite these defaults by adding a `.pr_agent.toml` file to CodiumAI PR-Agent is an open-source tool to help efficiently review and handle pull requests. It automatically analyzes the pull request and can provide several types of commands: -| | | GitHub | Gitlab | Bitbucket | -|-------|---------------------------------------------|:------:|:------:|:---------:| -| TOOLS | Review | :white_check_mark: | :white_check_mark: | :white_check_mark: | -| | ⮑ Incremental | :white_check_mark: | | | -| | ⮑ [SOC2 Compliance](https://github.com/Codium-ai/pr-agent/blob/main/docs/REVIEW.md#soc2-ticket-compliance-) 💎 | :white_check_mark: | :white_check_mark: | :white_check_mark: | -| | Ask | :white_check_mark: | :white_check_mark: | :white_check_mark: | -| | Describe | :white_check_mark: | :white_check_mark: | :white_check_mark: | -| | ⮑ [Inline file summary](https://github.com/Codium-ai/pr-agent/blob/main/docs/DESCRIBE.md#inline-file-summary-) 💎 | :white_check_mark: | :white_check_mark: | :white_check_mark: | -| | Improve | :white_check_mark: | :white_check_mark: | :white_check_mark: | -| | ⮑ Extended | :white_check_mark: | :white_check_mark: | :white_check_mark: | -| | [Custom Suggestions](https://github.com/Codium-ai/pr-agent/blob/main/docs/CUSTOM_SUGGESTIONS.md) 💎 | :white_check_mark: | :white_check_mark: | :white_check_mark: | -| | [Test](https://github.com/Codium-ai/pr-agent/blob/main/docs/Test.md) 💎 | :white_check_mark: | :white_check_mark: | :white_check_mark: | -| | Reflect and Review | :white_check_mark: | :white_check_mark: | :white_check_mark: | -| | Update CHANGELOG.md | :white_check_mark: | :white_check_mark: | :white_check_mark: | -| | Find Similar Issue | :white_check_mark: | | | -| | [Add PR Documentation](https://github.com/Codium-ai/pr-agent/blob/main/docs/ADD_DOCUMENTATION.md) 💎 | :white_check_mark: | :white_check_mark: | :white_check_mark: | -| | [Generate Custom Labels](https://github.com/Codium-ai/pr-agent/blob/main/docs/DESCRIBE.md#handle-custom-labels-from-the-repos-labels-page-gem) 💎 | :white_check_mark: | :white_check_mark: | | -| | [Analyze PR Components](https://github.com/Codium-ai/pr-agent/blob/main/docs/Analyze.md) 💎 | :white_check_mark: | :white_check_mark: | :white_check_mark: | -| | | | | | -| USAGE | CLI | :white_check_mark: | :white_check_mark: | :white_check_mark: | -| | App / webhook | :white_check_mark: | :white_check_mark: | | -| | Tagging bot | :white_check_mark: | | | -| | Actions | :white_check_mark: | | | -| | | | | | -| CORE | PR compression | :white_check_mark: | :white_check_mark: | :white_check_mark: | -| | Repo language prioritization | :white_check_mark: | :white_check_mark: | :white_check_mark: | -| | Adaptive and token-aware
file patch fitting | :white_check_mark: | :white_check_mark: | :white_check_mark: | -| | Multiple models support | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | -| | Incremental PR review | :white_check_mark: | | | -| | [Static code analysis](https://github.com/Codium-ai/pr-agent/blob/main/docs/Analyze.md) 💎 | :white_check_mark: | :white_check_mark: | :white_check_mark: | -| | [Global configuration](https://github.com/Codium-ai/pr-agent/blob/main/Usage.md#global-configuration-file-) 💎 | :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | | GitHub | Gitlab | Bitbucket | +|-------|------------------------------------------------------------------------------------------------------------------------------------------|:------:|:------:|:---------:| +| TOOLS | Review | :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | ⮑ Incremental | :white_check_mark: | | | +| | ⮑ [SOC2 Compliance](https://github.com/Codium-ai/pr-agent/blob/main/docs/REVIEW.md#soc2-ticket-compliance-) 💎 | :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | Describe | :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | ⮑ [Inline File Summary](https://github.com/Codium-ai/pr-agent/blob/main/docs/DESCRIBE.md#inline-file-summary-) 💎 | :white_check_mark: | | | +| | Improve | :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | ⮑ Extended | :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | Ask | :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | [Custom Suggestions](https://github.com/Codium-ai/pr-agent/blob/main/docs/CUSTOM_SUGGESTIONS.md) 💎 | :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | [Test](https://github.com/Codium-ai/pr-agent/blob/main/docs/Test.md) 💎 | :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | Reflect and Review | :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | Update CHANGELOG.md | :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | Find Similar Issue | :white_check_mark: | | | +| | [Add PR Documentation](https://github.com/Codium-ai/pr-agent/blob/main/docs/ADD_DOCUMENTATION.md) 💎 | :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | [Custom Labels](https://github.com/Codium-ai/pr-agent/blob/main/docs/DESCRIBE.md#handle-custom-labels-from-the-repos-labels-page-gem) 💎 | :white_check_mark: | :white_check_mark: | | +| | [Analyze](https://github.com/Codium-ai/pr-agent/blob/main/docs/Analyze.md) 💎 | :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | | | | | +| USAGE | CLI | :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | App / webhook | :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | Tagging bot | :white_check_mark: | | | +| | Actions | :white_check_mark: | | :white_check_mark: | +| | | | | | +| CORE | PR compression | :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | Repo language prioritization | :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | Adaptive and token-aware
file patch fitting | :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | Multiple models support | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | [Static code analysis](https://github.com/Codium-ai/pr-agent/blob/main/docs/Analyze.md) 💎 | :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | [Global configuration](https://github.com/Codium-ai/pr-agent/blob/main/Usage.md#global-configuration-file-) 💎 | :white_check_mark: | :white_check_mark: | :white_check_mark: | - 💎 means this feature is available only in [PR-Agent Pro](https://www.codium.ai/pricing/) - Support for additional git providers is described in [here](./docs/Full_environments.md) +- +___ ‣ **Auto Description ([`/describe`](./docs/DESCRIBE.md))**: Automatically generating PR description - title, type, summary, code walkthrough and labels. \ From f1fe2563f4666ac248896af14e2e92884273b57a Mon Sep 17 00:00:00 2001 From: mrT23 Date: Mon, 29 Jan 2024 11:22:46 +0200 Subject: [PATCH 13/50] s --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 29043fe5..0ba5dc27 100644 --- a/README.md +++ b/README.md @@ -93,7 +93,6 @@ CodiumAI PR-Agent is an open-source tool to help efficiently review and handle p | | [Global configuration](https://github.com/Codium-ai/pr-agent/blob/main/Usage.md#global-configuration-file-) 💎 | :white_check_mark: | :white_check_mark: | :white_check_mark: | - 💎 means this feature is available only in [PR-Agent Pro](https://www.codium.ai/pricing/) - Support for additional git providers is described in [here](./docs/Full_environments.md) -- ___ ‣ **Auto Description ([`/describe`](./docs/DESCRIBE.md))**: Automatically generating PR description - title, type, summary, code walkthrough and labels. @@ -115,7 +114,8 @@ ___ ‣ **Analyze 💎 ([`/analyze`](./docs/Analyze.md))**: Automatically analyzes the PR, and presents changes walkthrough for each component. \ ‣ **Custom Suggestions 💎 ([`/custom_suggestions`](./docs/CUSTOM_SUGGESTIONS.md))**: Automatically generates custom suggestions for improving the PR code, based on specific guidelines defined by the user. - +\ +‣ **Generate Tests 💎 ([`/test component_name`](./docs/TEST.md))**: Automatically generates unit tests for a selected component, based on the PR code changes. See the [Installation Guide](./INSTALL.md) for instructions on installing and running the tool on different git platforms. From 412159bba5608ab725e9ced6904187b2772d776c Mon Sep 17 00:00:00 2001 From: mrT23 Date: Mon, 29 Jan 2024 11:28:58 +0200 Subject: [PATCH 14/50] s1 --- README.md | 60 +++++++++++++++++++++++++++---------------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index 0ba5dc27..f02b2954 100644 --- a/README.md +++ b/README.md @@ -61,36 +61,36 @@ You can of course overwrite these defaults by adding a `.pr_agent.toml` file to CodiumAI PR-Agent is an open-source tool to help efficiently review and handle pull requests. It automatically analyzes the pull request and can provide several types of commands: -| | | GitHub | Gitlab | Bitbucket | -|-------|------------------------------------------------------------------------------------------------------------------------------------------|:------:|:------:|:---------:| -| TOOLS | Review | :white_check_mark: | :white_check_mark: | :white_check_mark: | -| | ⮑ Incremental | :white_check_mark: | | | -| | ⮑ [SOC2 Compliance](https://github.com/Codium-ai/pr-agent/blob/main/docs/REVIEW.md#soc2-ticket-compliance-) 💎 | :white_check_mark: | :white_check_mark: | :white_check_mark: | -| | Describe | :white_check_mark: | :white_check_mark: | :white_check_mark: | -| | ⮑ [Inline File Summary](https://github.com/Codium-ai/pr-agent/blob/main/docs/DESCRIBE.md#inline-file-summary-) 💎 | :white_check_mark: | | | -| | Improve | :white_check_mark: | :white_check_mark: | :white_check_mark: | -| | ⮑ Extended | :white_check_mark: | :white_check_mark: | :white_check_mark: | -| | Ask | :white_check_mark: | :white_check_mark: | :white_check_mark: | -| | [Custom Suggestions](https://github.com/Codium-ai/pr-agent/blob/main/docs/CUSTOM_SUGGESTIONS.md) 💎 | :white_check_mark: | :white_check_mark: | :white_check_mark: | -| | [Test](https://github.com/Codium-ai/pr-agent/blob/main/docs/Test.md) 💎 | :white_check_mark: | :white_check_mark: | :white_check_mark: | -| | Reflect and Review | :white_check_mark: | :white_check_mark: | :white_check_mark: | -| | Update CHANGELOG.md | :white_check_mark: | :white_check_mark: | :white_check_mark: | -| | Find Similar Issue | :white_check_mark: | | | -| | [Add PR Documentation](https://github.com/Codium-ai/pr-agent/blob/main/docs/ADD_DOCUMENTATION.md) 💎 | :white_check_mark: | :white_check_mark: | :white_check_mark: | -| | [Custom Labels](https://github.com/Codium-ai/pr-agent/blob/main/docs/DESCRIBE.md#handle-custom-labels-from-the-repos-labels-page-gem) 💎 | :white_check_mark: | :white_check_mark: | | -| | [Analyze](https://github.com/Codium-ai/pr-agent/blob/main/docs/Analyze.md) 💎 | :white_check_mark: | :white_check_mark: | :white_check_mark: | -| | | | | | -| USAGE | CLI | :white_check_mark: | :white_check_mark: | :white_check_mark: | -| | App / webhook | :white_check_mark: | :white_check_mark: | :white_check_mark: | -| | Tagging bot | :white_check_mark: | | | -| | Actions | :white_check_mark: | | :white_check_mark: | -| | | | | | -| CORE | PR compression | :white_check_mark: | :white_check_mark: | :white_check_mark: | -| | Repo language prioritization | :white_check_mark: | :white_check_mark: | :white_check_mark: | -| | Adaptive and token-aware
file patch fitting | :white_check_mark: | :white_check_mark: | :white_check_mark: | -| | Multiple models support | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | -| | [Static code analysis](https://github.com/Codium-ai/pr-agent/blob/main/docs/Analyze.md) 💎 | :white_check_mark: | :white_check_mark: | :white_check_mark: | -| | [Global configuration](https://github.com/Codium-ai/pr-agent/blob/main/Usage.md#global-configuration-file-) 💎 | :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | : || GitHub | Gitlab | Bitbucket | +|-------|-------------------------------------------------------------------------------------------------------------------------------------------|:------:|:------:|:------:|:---------:| +| TOOLS | Review || :white_check_mark: | :white_check_mark: | :white_check_mark: | +| || ⮑ Incremental | :white_check_mark: | | | +| || ⮑ [SOC2 Compliance](https://github.com/Codium-ai/pr-agent/blob/main/docs/REVIEW.md#soc2-ticket-compliance-) 💎 | :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | Describe || :white_check_mark: | :white_check_mark: | :white_check_mark: | +| || ⮑ [Inline File Summary](https://github.com/Codium-ai/pr-agent/blob/main/docs/DESCRIBE.md#inline-file-summary-) 💎 | :white_check_mark: | | | +| | Improve || :white_check_mark: | :white_check_mark: | :white_check_mark: | +| || ⮑ Extended | :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | Ask || :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | [Custom Suggestions](https://github.com/Codium-ai/pr-agent/blob/main/docs/CUSTOM_SUGGESTIONS.md) 💎 || :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | [Test](https://github.com/Codium-ai/pr-agent/blob/main/docs/Test.md) 💎 || :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | Reflect and Review || :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | Update CHANGELOG.md || :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | Find Similar Issue || :white_check_mark: | | | +| | [Add PR Documentation](https://github.com/Codium-ai/pr-agent/blob/main/docs/ADD_DOCUMENTATION.md) 💎 || :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | [Custom Labels](https://github.com/Codium-ai/pr-agent/blob/main/docs/DESCRIBE.md#handle-custom-labels-from-the-repos-labels-page-gem) 💎 || :white_check_mark: | :white_check_mark: | | +| | [Analyze](https://github.com/Codium-ai/pr-agent/blob/main/docs/Analyze.md) 💎 || :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | || | | | +| USAGE | CLI || :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | App / webhook || :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | Tagging bot || :white_check_mark: | | | +| | Actions || :white_check_mark: | | :white_check_mark: | +| | || | | | +| CORE | PR compression || :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | Repo language prioritization || :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | Adaptive and token-aware
file patch fitting || :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | Multiple models support || :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | [Static code analysis](https://github.com/Codium-ai/pr-agent/blob/main/docs/Analyze.md) 💎 || :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | [Global configuration](https://github.com/Codium-ai/pr-agent/blob/main/Usage.md#global-configuration-file-) 💎 || :white_check_mark: | :white_check_mark: | :white_check_mark: | - 💎 means this feature is available only in [PR-Agent Pro](https://www.codium.ai/pricing/) - Support for additional git providers is described in [here](./docs/Full_environments.md) ___ From 567b400f97f65f987b54eca27a23b386cbab1ea4 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Mon, 29 Jan 2024 11:30:58 +0200 Subject: [PATCH 15/50] Revert "s1" This reverts commit 412159bba5608ab725e9ced6904187b2772d776c. --- README.md | 60 +++++++++++++++++++++++++++---------------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index f02b2954..0ba5dc27 100644 --- a/README.md +++ b/README.md @@ -61,36 +61,36 @@ You can of course overwrite these defaults by adding a `.pr_agent.toml` file to CodiumAI PR-Agent is an open-source tool to help efficiently review and handle pull requests. It automatically analyzes the pull request and can provide several types of commands: -| | : || GitHub | Gitlab | Bitbucket | -|-------|-------------------------------------------------------------------------------------------------------------------------------------------|:------:|:------:|:------:|:---------:| -| TOOLS | Review || :white_check_mark: | :white_check_mark: | :white_check_mark: | -| || ⮑ Incremental | :white_check_mark: | | | -| || ⮑ [SOC2 Compliance](https://github.com/Codium-ai/pr-agent/blob/main/docs/REVIEW.md#soc2-ticket-compliance-) 💎 | :white_check_mark: | :white_check_mark: | :white_check_mark: | -| | Describe || :white_check_mark: | :white_check_mark: | :white_check_mark: | -| || ⮑ [Inline File Summary](https://github.com/Codium-ai/pr-agent/blob/main/docs/DESCRIBE.md#inline-file-summary-) 💎 | :white_check_mark: | | | -| | Improve || :white_check_mark: | :white_check_mark: | :white_check_mark: | -| || ⮑ Extended | :white_check_mark: | :white_check_mark: | :white_check_mark: | -| | Ask || :white_check_mark: | :white_check_mark: | :white_check_mark: | -| | [Custom Suggestions](https://github.com/Codium-ai/pr-agent/blob/main/docs/CUSTOM_SUGGESTIONS.md) 💎 || :white_check_mark: | :white_check_mark: | :white_check_mark: | -| | [Test](https://github.com/Codium-ai/pr-agent/blob/main/docs/Test.md) 💎 || :white_check_mark: | :white_check_mark: | :white_check_mark: | -| | Reflect and Review || :white_check_mark: | :white_check_mark: | :white_check_mark: | -| | Update CHANGELOG.md || :white_check_mark: | :white_check_mark: | :white_check_mark: | -| | Find Similar Issue || :white_check_mark: | | | -| | [Add PR Documentation](https://github.com/Codium-ai/pr-agent/blob/main/docs/ADD_DOCUMENTATION.md) 💎 || :white_check_mark: | :white_check_mark: | :white_check_mark: | -| | [Custom Labels](https://github.com/Codium-ai/pr-agent/blob/main/docs/DESCRIBE.md#handle-custom-labels-from-the-repos-labels-page-gem) 💎 || :white_check_mark: | :white_check_mark: | | -| | [Analyze](https://github.com/Codium-ai/pr-agent/blob/main/docs/Analyze.md) 💎 || :white_check_mark: | :white_check_mark: | :white_check_mark: | -| | || | | | -| USAGE | CLI || :white_check_mark: | :white_check_mark: | :white_check_mark: | -| | App / webhook || :white_check_mark: | :white_check_mark: | :white_check_mark: | -| | Tagging bot || :white_check_mark: | | | -| | Actions || :white_check_mark: | | :white_check_mark: | -| | || | | | -| CORE | PR compression || :white_check_mark: | :white_check_mark: | :white_check_mark: | -| | Repo language prioritization || :white_check_mark: | :white_check_mark: | :white_check_mark: | -| | Adaptive and token-aware
file patch fitting || :white_check_mark: | :white_check_mark: | :white_check_mark: | -| | Multiple models support || :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | -| | [Static code analysis](https://github.com/Codium-ai/pr-agent/blob/main/docs/Analyze.md) 💎 || :white_check_mark: | :white_check_mark: | :white_check_mark: | -| | [Global configuration](https://github.com/Codium-ai/pr-agent/blob/main/Usage.md#global-configuration-file-) 💎 || :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | | GitHub | Gitlab | Bitbucket | +|-------|------------------------------------------------------------------------------------------------------------------------------------------|:------:|:------:|:---------:| +| TOOLS | Review | :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | ⮑ Incremental | :white_check_mark: | | | +| | ⮑ [SOC2 Compliance](https://github.com/Codium-ai/pr-agent/blob/main/docs/REVIEW.md#soc2-ticket-compliance-) 💎 | :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | Describe | :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | ⮑ [Inline File Summary](https://github.com/Codium-ai/pr-agent/blob/main/docs/DESCRIBE.md#inline-file-summary-) 💎 | :white_check_mark: | | | +| | Improve | :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | ⮑ Extended | :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | Ask | :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | [Custom Suggestions](https://github.com/Codium-ai/pr-agent/blob/main/docs/CUSTOM_SUGGESTIONS.md) 💎 | :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | [Test](https://github.com/Codium-ai/pr-agent/blob/main/docs/Test.md) 💎 | :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | Reflect and Review | :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | Update CHANGELOG.md | :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | Find Similar Issue | :white_check_mark: | | | +| | [Add PR Documentation](https://github.com/Codium-ai/pr-agent/blob/main/docs/ADD_DOCUMENTATION.md) 💎 | :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | [Custom Labels](https://github.com/Codium-ai/pr-agent/blob/main/docs/DESCRIBE.md#handle-custom-labels-from-the-repos-labels-page-gem) 💎 | :white_check_mark: | :white_check_mark: | | +| | [Analyze](https://github.com/Codium-ai/pr-agent/blob/main/docs/Analyze.md) 💎 | :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | | | | | +| USAGE | CLI | :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | App / webhook | :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | Tagging bot | :white_check_mark: | | | +| | Actions | :white_check_mark: | | :white_check_mark: | +| | | | | | +| CORE | PR compression | :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | Repo language prioritization | :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | Adaptive and token-aware
file patch fitting | :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | Multiple models support | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | [Static code analysis](https://github.com/Codium-ai/pr-agent/blob/main/docs/Analyze.md) 💎 | :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | [Global configuration](https://github.com/Codium-ai/pr-agent/blob/main/Usage.md#global-configuration-file-) 💎 | :white_check_mark: | :white_check_mark: | :white_check_mark: | - 💎 means this feature is available only in [PR-Agent Pro](https://www.codium.ai/pricing/) - Support for additional git providers is described in [here](./docs/Full_environments.md) ___ From 042eab1641a461d1de5e5dc32d1bd481dc1bcb55 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Mon, 29 Jan 2024 11:39:50 +0200 Subject: [PATCH 16/50] s --- pr_agent/settings/configuration.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pr_agent/settings/configuration.toml b/pr_agent/settings/configuration.toml index 3a97fbb5..0b428cce 100644 --- a/pr_agent/settings/configuration.toml +++ b/pr_agent/settings/configuration.toml @@ -1,10 +1,10 @@ [config] -model="gpt-4" # "gpt-4-1106-preview" +model="gpt-4" # "gpt-4-0125-preview" fallback_models=["gpt-3.5-turbo-16k"] git_provider="github" publish_output=true publish_output_progress=true -verbosity_level=0 # 0,1,2 +verbosity_level=2 # 0,1,2 use_extra_bad_extensions=false use_repo_settings_file=true use_global_settings_file=true From 40a7ef913244e6f87f90416c6348278a3da48482 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Mon, 29 Jan 2024 11:42:32 +0200 Subject: [PATCH 17/50] s --- pr_agent/settings/configuration.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pr_agent/settings/configuration.toml b/pr_agent/settings/configuration.toml index 0b428cce..bb5a95f7 100644 --- a/pr_agent/settings/configuration.toml +++ b/pr_agent/settings/configuration.toml @@ -4,7 +4,7 @@ fallback_models=["gpt-3.5-turbo-16k"] git_provider="github" publish_output=true publish_output_progress=true -verbosity_level=2 # 0,1,2 +verbosity_level=0 # 0,1,2 use_extra_bad_extensions=false use_repo_settings_file=true use_global_settings_file=true From 8d36e2e2f79f0e87f0c4ae17c122aaeedd808299 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Mon, 29 Jan 2024 20:17:39 +0200 Subject: [PATCH 18/50] feat: Add new configuration options in pr_test section and update TEST.md documentation --- docs/TEST.md | 5 ++++- pr_agent/settings/configuration.toml | 9 ++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/docs/TEST.md b/docs/TEST.md index f25ae60d..4f88c359 100644 --- a/docs/TEST.md +++ b/docs/TEST.md @@ -24,4 +24,7 @@ Language that are currently supported by the tool: Python, Java, C++, JavaScript - `num_tests`: number of tests to generate. Default is 3. - `testing_framework`: the testing framework to use. If not set, for Python it will use `pytest`, for Java it will use `JUnit`, for C++ it will use `Catch2`, and for JavaScript and TypeScript it will use `jest`. - `avoid_mocks`: if set to true, the tool will try to avoid using mocks in the generated tests. Note that even if this option is set to true, the tool might still use mocks if it cannot generate a test without them. Default is true. -- `extra_instructions`: Optional extra instructions to the tool. For example: "use the following mock injection scheme: ...". \ No newline at end of file +- `extra_instructions`: Optional extra instructions to the tool. For example: "use the following mock injection scheme: ...". +- `file`: in case there are several components with the same name, you can specify the relevant file. +- `class_name`: in case there are several methods with the same name in the same file, you can specify the relevant class name. +- `enable_help_text`: if set to true, the tool will add a help text to the PR comment. Default is true. \ No newline at end of file diff --git a/pr_agent/settings/configuration.toml b/pr_agent/settings/configuration.toml index bb5a95f7..3a9b8d39 100644 --- a/pr_agent/settings/configuration.toml +++ b/pr_agent/settings/configuration.toml @@ -91,10 +91,13 @@ extra_instructions = "" [pr_analyze] # /analyze # [pr_test] # /test # -testing_framework = "" # specify the testing framework you want to use -num_tests=3 # number of tests to generate. max 5. -avoid_mocks=true # if true, the generated tests will prefer to use real objects instead of mocks extra_instructions = "" +testing_framework = "" # specify the testing framework you want to use +num_tests=3 # number of tests to generate. max 5. +avoid_mocks=true # if true, the generated tests will prefer to use real objects instead of mocks +file = "" # in case there are several components with the same name, you can specify the relevant file +class_name = "" # in case there are several methods with the same name in the same file, you can specify the relevant class name +enable_help_text=true [pr_config] # /config # From 699808954956ff826cfc353b3d3b4a9d90c08fba Mon Sep 17 00:00:00 2001 From: Tal Date: Mon, 29 Jan 2024 20:21:23 +0200 Subject: [PATCH 19/50] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0ba5dc27..95ab106e 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,7 @@ CodiumAI PR-Agent is an open-source tool to help efficiently review and handle p | | ⮑ Extended | :white_check_mark: | :white_check_mark: | :white_check_mark: | | | Ask | :white_check_mark: | :white_check_mark: | :white_check_mark: | | | [Custom Suggestions](https://github.com/Codium-ai/pr-agent/blob/main/docs/CUSTOM_SUGGESTIONS.md) 💎 | :white_check_mark: | :white_check_mark: | :white_check_mark: | -| | [Test](https://github.com/Codium-ai/pr-agent/blob/main/docs/Test.md) 💎 | :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | [Test](https://github.com/Codium-ai/pr-agent/blob/main/docs/TEST.md) 💎 | :white_check_mark: | :white_check_mark: | :white_check_mark: | | | Reflect and Review | :white_check_mark: | :white_check_mark: | :white_check_mark: | | | Update CHANGELOG.md | :white_check_mark: | :white_check_mark: | :white_check_mark: | | | Find Similar Issue | :white_check_mark: | | | From 6565556e0162cb737d740338da15179ad6d34f6c Mon Sep 17 00:00:00 2001 From: mrT23 Date: Mon, 29 Jan 2024 20:51:24 +0200 Subject: [PATCH 20/50] feat: Add 'language' field to CodeSuggestion, FileDescription, and ReviewerPrompt models in settings files --- pr_agent/settings/pr_code_suggestions_prompts.toml | 8 +++----- pr_agent/settings/pr_description_prompts.toml | 6 +++--- pr_agent/settings/pr_reviewer_prompts.toml | 9 +++++---- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/pr_agent/settings/pr_code_suggestions_prompts.toml b/pr_agent/settings/pr_code_suggestions_prompts.toml index 2fb224c7..ee311054 100644 --- a/pr_agent/settings/pr_code_suggestions_prompts.toml +++ b/pr_agent/settings/pr_code_suggestions_prompts.toml @@ -51,6 +51,7 @@ The output must be a YAML object equivalent to type $PRCodeSuggestions, accordin ===== class CodeSuggestion(BaseModel): relevant_file: str = Field(description="the relevant file full path") + language: str = Field(description="the code language of the relevant file") suggestion_content: str = Field(description="an actionable suggestion for meaningfully improving the new code introduced in the PR") {%- if summarize_mode %} existing_code: str = Field(description="a short code snippet from a '__new hunk__' section to illustrate the relevant existing code. Don't show the line numbers.") @@ -74,6 +75,8 @@ Example output: code_suggestions: - relevant_file: |- src/file1.py + language: |- + python suggestion_content: |- Add a docstring to func1() {%- if summarize_mode %} @@ -105,11 +108,6 @@ user="""PR Info: Title: '{{title}}' -{%- if language %} - -Main PR language: '{{ language }}' -{%- endif %} - The PR Diff: ====== diff --git a/pr_agent/settings/pr_description_prompts.toml b/pr_agent/settings/pr_description_prompts.toml index b9c5ce39..b36b0183 100644 --- a/pr_agent/settings/pr_description_prompts.toml +++ b/pr_agent/settings/pr_description_prompts.toml @@ -39,6 +39,7 @@ class PRType(str, Enum): Class FileDescription(BaseModel): filename: str = Field(description="the relevant file full path") + language: str = Field(description="the relevant file language") changes_summary: str = Field(description="concise summary of the changes in the relevant file, in bullet points (1-4 bullet points).") changes_title: str = Field(description="an informative title for the changes in the files, describing its main theme (5-10 words).") label: str = Field(description="a single semantic label that represents a type of code changes that occurred in the File. Possible values (partial list): 'bug fix', 'tests', 'enhancement', 'documentation', 'error handling', 'configuration changes', 'dependencies', 'formatting', 'miscellaneous', ...") @@ -67,6 +68,8 @@ type: pr_files: - filename: | ... + language: | + ... changes_summary: | ... changes_title: | @@ -104,10 +107,7 @@ Previous description: {%- endif %} Branch: '{{branch}}' -{%- if language %} -Main PR language: '{{ language }}' -{%- endif %} {%- if commit_messages_str %} Commit messages: diff --git a/pr_agent/settings/pr_reviewer_prompts.toml b/pr_agent/settings/pr_reviewer_prompts.toml index 736fb247..5312832c 100644 --- a/pr_agent/settings/pr_reviewer_prompts.toml +++ b/pr_agent/settings/pr_reviewer_prompts.toml @@ -115,6 +115,9 @@ PR Feedback: relevant file: type: string description: the relevant file full path + language: + type: string + description: the language of the relevant file suggestion: type: string description: |- @@ -166,6 +169,8 @@ PR Feedback: Code feedback: - relevant file: |- directory/xxx.py + language: |- + python suggestion: |- xxx [important] relevant line: |- @@ -195,10 +200,6 @@ Description: ====== {%- endif %} -{%- if language %} - -Main PR language: '{{ language }}' -{%- endif %} {%- if commit_messages_str %} Commit messages: From 0d867797990324964251c754d4aae38115d0fddc Mon Sep 17 00:00:00 2001 From: mrT23 Date: Mon, 29 Jan 2024 21:52:54 +0200 Subject: [PATCH 21/50] feat: Improve patch formatting and handle empty data in pr_code_suggestions.py --- pr_agent/algo/git_patch_processing.py | 10 +++++----- pr_agent/algo/pr_processing.py | 4 ++-- pr_agent/settings/pr_add_docs.toml | 5 ++--- pr_agent/settings/pr_code_suggestions_prompts.toml | 5 ++--- pr_agent/settings/pr_reviewer_prompts.toml | 5 ++--- pr_agent/tools/pr_code_suggestions.py | 2 ++ 6 files changed, 15 insertions(+), 16 deletions(-) diff --git a/pr_agent/algo/git_patch_processing.py b/pr_agent/algo/git_patch_processing.py index 480387fa..10d140b0 100644 --- a/pr_agent/algo/git_patch_processing.py +++ b/pr_agent/algo/git_patch_processing.py @@ -181,7 +181,7 @@ __old hunk__ ... """ - patch_with_lines_str = f"\n\n## {file.filename}\n" + patch_with_lines_str = f"\n\n## file: '{file.filename.strip()}'\n" patch_lines = patch.splitlines() RE_HUNK_HEADER = re.compile( r"^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@[ ]?(.*)") @@ -202,11 +202,11 @@ __old hunk__ if new_content_lines: if prev_header_line: patch_with_lines_str += f'\n{prev_header_line}\n' - patch_with_lines_str += '__new hunk__\n' + patch_with_lines_str = patch_with_lines_str.rstrip()+'\n__new hunk__\n' for i, line_new in enumerate(new_content_lines): patch_with_lines_str += f"{start2 + i} {line_new}\n" if old_content_lines: - patch_with_lines_str += '__old hunk__\n' + patch_with_lines_str = patch_with_lines_str.rstrip()+'\n__old hunk__\n' for line_old in old_content_lines: patch_with_lines_str += f"{line_old}\n" new_content_lines = [] @@ -236,11 +236,11 @@ __old hunk__ if match and new_content_lines: if new_content_lines: patch_with_lines_str += f'\n{header_line}\n' - patch_with_lines_str += '\n__new hunk__\n' + patch_with_lines_str = patch_with_lines_str.rstrip()+ '\n__new hunk__\n' for i, line_new in enumerate(new_content_lines): patch_with_lines_str += f"{start2 + i} {line_new}\n" if old_content_lines: - patch_with_lines_str += '\n__old hunk__\n' + patch_with_lines_str = patch_with_lines_str.rstrip() + '\n__old hunk__\n' for line_old in old_content_lines: patch_with_lines_str += f"{line_old}\n" diff --git a/pr_agent/algo/pr_processing.py b/pr_agent/algo/pr_processing.py index ecec3015..f4ffae89 100644 --- a/pr_agent/algo/pr_processing.py +++ b/pr_agent/algo/pr_processing.py @@ -209,9 +209,9 @@ def pr_generate_compressed_diff(top_langs: list, token_handler: TokenHandler, mo if patch: if not convert_hunks_to_line_numbers: - patch_final = f"## {file.filename}\n\n{patch}\n" + patch_final = f"\n\n## file: '{file.filename.strip()}\n\n{patch.strip()}\n'" else: - patch_final = patch + patch_final = "\n\n" + patch.strip() patches.append(patch_final) total_tokens += token_handler.count_tokens(patch_final) if get_settings().config.verbosity_level >= 2: diff --git a/pr_agent/settings/pr_add_docs.toml b/pr_agent/settings/pr_add_docs.toml index 44e9f091..cc33eee5 100644 --- a/pr_agent/settings/pr_add_docs.toml +++ b/pr_agent/settings/pr_add_docs.toml @@ -5,7 +5,7 @@ Your task is to generate {{ docs_for_language }} for code components in the PR D Example for the PR Diff format: ====== -## src/file1.py +## file: 'src/file1.py' @@ -12,3 +12,4 @@ def func1(): __new hunk__ @@ -18,7 +18,6 @@ __old hunk__ -code line that was removed in the PR code line2 that remained unchanged in the PR - @@ ... @@ def func2(): __new hunk__ ... @@ -26,7 +25,7 @@ __old hunk__ ... -## src/file2.py +## file: 'src/file2.py' ... ====== diff --git a/pr_agent/settings/pr_code_suggestions_prompts.toml b/pr_agent/settings/pr_code_suggestions_prompts.toml index ee311054..71d92350 100644 --- a/pr_agent/settings/pr_code_suggestions_prompts.toml +++ b/pr_agent/settings/pr_code_suggestions_prompts.toml @@ -4,7 +4,7 @@ Your task is to provide meaningful and actionable code suggestions, to improve t Example for the PR Diff format: ====== -## src/file1.py +## file: 'src/file1.py' @@ ... @@ def func1(): __new hunk__ @@ -16,7 +16,6 @@ __old hunk__ -old code line2 that was removed in the PR code line3 that remained unchanged in the PR - @@ ... @@ def func2(): __new hunk__ ... @@ -24,7 +23,7 @@ __old hunk__ ... -## src/file2.py +## file: 'src/file2.py' ... ====== diff --git a/pr_agent/settings/pr_reviewer_prompts.toml b/pr_agent/settings/pr_reviewer_prompts.toml index 5312832c..427cd974 100644 --- a/pr_agent/settings/pr_reviewer_prompts.toml +++ b/pr_agent/settings/pr_reviewer_prompts.toml @@ -5,7 +5,7 @@ The review should focus on new code added in the PR diff (lines starting with '+ Example PR Diff: ====== -## src/file1.py +## file: 'src/file1.py' @@ -12,5 +12,5 @@ def func1(): code line 1 that remained unchanged in the PR @@ -14,12 +14,11 @@ code line 2 that remained unchanged in the PR +code line added in the PR code line 3 that remained unchanged in the PR - @@ ... @@ def func2(): ... -## src/file2.py +## file: 'src/file2.py' ... ====== diff --git a/pr_agent/tools/pr_code_suggestions.py b/pr_agent/tools/pr_code_suggestions.py index 1456f9a6..08074899 100644 --- a/pr_agent/tools/pr_code_suggestions.py +++ b/pr_agent/tools/pr_code_suggestions.py @@ -253,6 +253,8 @@ class PRCodeSuggestions: """ suggestion_list = [] + if not data: + return suggestion_list for suggestion in data: suggestion_list.append(suggestion) data_sorted = [[]] * len(suggestion_list) From 15c8fe94bb29963cf12e77c046834c0c547da810 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Mon, 29 Jan 2024 22:00:11 +0200 Subject: [PATCH 22/50] feat: Improve patch formatting and handle empty data in pr_code_suggestions.py --- pr_agent/algo/pr_processing.py | 7 +++++++ pr_agent/tools/pr_code_suggestions.py | 5 ++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/pr_agent/algo/pr_processing.py b/pr_agent/algo/pr_processing.py index f4ffae89..1e482dbf 100644 --- a/pr_agent/algo/pr_processing.py +++ b/pr_agent/algo/pr_processing.py @@ -375,6 +375,13 @@ def get_pr_multi_diffs(git_provider: GitProvider, for lang in pr_languages: sorted_files.extend(sorted(lang['files'], key=lambda x: x.tokens, reverse=True)) + + # try first a single run with standard diff string, with patch extension, and no deletions + patches_extended, total_tokens, patches_extended_tokens = pr_generate_extended_diff( + pr_languages, token_handler, add_line_numbers_to_hunks=True) + if total_tokens + OUTPUT_BUFFER_TOKENS_SOFT_THRESHOLD < get_max_tokens(model): + return ["\n".join(patches_extended)] + patches = [] final_diff_list = [] total_tokens = token_handler.prompt_tokens diff --git a/pr_agent/tools/pr_code_suggestions.py b/pr_agent/tools/pr_code_suggestions.py index 08074899..381c02a6 100644 --- a/pr_agent/tools/pr_code_suggestions.py +++ b/pr_agent/tools/pr_code_suggestions.py @@ -226,7 +226,7 @@ class PRCodeSuggestions: for i, patches_diff in enumerate(patches_diff_list): get_logger().info(f"Processing chunk {i + 1} of {len(patches_diff_list)}") self.patches_diff = patches_diff - prediction = await self._get_prediction(model) + prediction = await self._get_prediction(model) # toDo: parallelize prediction_list.append(prediction) self.prediction_list = prediction_list @@ -259,6 +259,9 @@ class PRCodeSuggestions: suggestion_list.append(suggestion) data_sorted = [[]] * len(suggestion_list) + if len(suggestion_list ) == 1: + return suggestion_list + try: suggestion_str = "" for i, suggestion in enumerate(suggestion_list): From e1ae51e7a08030e4c713b62f32924db34ce4f521 Mon Sep 17 00:00:00 2001 From: Tal Date: Tue, 30 Jan 2024 08:21:43 +0200 Subject: [PATCH 23/50] Update TOOLS_GUIDE.md --- docs/TOOLS_GUIDE.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/docs/TOOLS_GUIDE.md b/docs/TOOLS_GUIDE.md index 43960531..07dfd10f 100644 --- a/docs/TOOLS_GUIDE.md +++ b/docs/TOOLS_GUIDE.md @@ -5,8 +5,9 @@ - [ASK](./ASK.md) - [SIMILAR_ISSUE](./SIMILAR_ISSUE.md) - [UPDATE CHANGELOG](./UPDATE_CHANGELOG.md) -- [ADD DOCUMENTATION](./ADD_DOCUMENTATION.md) -- [GENERATE CUSTOM LABELS](./GENERATE_CUSTOM_LABELS.md) -- [Analyze](./Analyze.md) +- [ADD DOCUMENTATION](./ADD_DOCUMENTATION.md) 💎 +- [GENERATE CUSTOM LABELS](./GENERATE_CUSTOM_LABELS.md) 💎 +- [Analyze](./Analyze.md) 💎 +- [Test](./Test.md) 💎 -See the **[installation guide](/INSTALL.md)** for instructions on how to setup PR-Agent. \ No newline at end of file +See the **[installation guide](/INSTALL.md)** for instructions on how to setup PR-Agent. From 716832691189c27953e2127f5d24b6bca9146f8d Mon Sep 17 00:00:00 2001 From: Tal Date: Tue, 30 Jan 2024 08:22:29 +0200 Subject: [PATCH 24/50] Update TOOLS_GUIDE.md --- docs/TOOLS_GUIDE.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/TOOLS_GUIDE.md b/docs/TOOLS_GUIDE.md index 07dfd10f..037b4049 100644 --- a/docs/TOOLS_GUIDE.md +++ b/docs/TOOLS_GUIDE.md @@ -8,6 +8,6 @@ - [ADD DOCUMENTATION](./ADD_DOCUMENTATION.md) 💎 - [GENERATE CUSTOM LABELS](./GENERATE_CUSTOM_LABELS.md) 💎 - [Analyze](./Analyze.md) 💎 -- [Test](./Test.md) 💎 +- [Test](./TEST.md) 💎 -See the **[installation guide](/INSTALL.md)** for instructions on how to setup PR-Agent. +See the **[installation guide](/INSTALL.md)** for instructions on setting up PR-Agent. From 9579be028da93981845abe8c7477ed01fbcacd9e Mon Sep 17 00:00:00 2001 From: mrT23 Date: Thu, 1 Feb 2024 08:31:11 +0200 Subject: [PATCH 25/50] protections for 'get_secret_provider' --- pr_agent/secret_providers/__init__.py | 23 +++++++++++++---------- pr_agent/servers/bitbucket_app.py | 3 ++- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/pr_agent/secret_providers/__init__.py b/pr_agent/secret_providers/__init__.py index 1cc3ea7b..020ed16c 100644 --- a/pr_agent/secret_providers/__init__.py +++ b/pr_agent/secret_providers/__init__.py @@ -2,15 +2,18 @@ from pr_agent.config_loader import get_settings def get_secret_provider(): - try: - provider_id = get_settings().config.secret_provider - except AttributeError as e: - raise ValueError("secret_provider is a required attribute in the configuration file") from e - try: - if provider_id == 'google_cloud_storage': + if not get_settings().get("CONFIG.SECRET_PROVIDER"): + return None + + provider_id = get_settings().config.secret_provider + if provider_id == 'google_cloud_storage': + try: from pr_agent.secret_providers.google_cloud_storage_secret_provider import GoogleCloudStorageSecretProvider return GoogleCloudStorageSecretProvider() - else: - raise ValueError(f"Unknown secret provider: {provider_id}") - except Exception as e: - raise ValueError(f"Failed to initialize secret provider {provider_id}") from e + except Exception as e: + raise ValueError(f"Failed to initialize google_cloud_storage secret provider {provider_id}") from e + else: + raise ValueError("Unknown SECRET_PROVIDER") + + + diff --git a/pr_agent/servers/bitbucket_app.py b/pr_agent/servers/bitbucket_app.py index bdb972c7..d2cae362 100644 --- a/pr_agent/servers/bitbucket_app.py +++ b/pr_agent/servers/bitbucket_app.py @@ -26,7 +26,8 @@ from pr_agent.tools.pr_reviewer import PRReviewer setup_logger(fmt=LoggingFormat.JSON) router = APIRouter() -secret_provider = get_secret_provider() +secret_provider = get_secret_provider() if get_settings().get("CONFIG.SECRET_PROVIDER") else None + async def get_bearer_token(shared_secret: str, client_key: str): try: From 2112defa51bc671d06a49737ad782f414e548ca8 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Thu, 1 Feb 2024 08:44:23 +0200 Subject: [PATCH 26/50] lancedb bump --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 8a465c6f..b649f304 100644 --- a/requirements.txt +++ b/requirements.txt @@ -14,7 +14,7 @@ msrest==0.7.1 openai==0.27.8 pinecone-client pinecone-datasets @ git+https://github.com/mrT23/pinecone-datasets.git@main -lancedb==0.3.4 +lancedb==0.5.1 pytest==7.4.0 PyGithub==1.59.* PyYAML==6.0.1 From 2816cd2c4b9ea53f19d4814b9819ff6f5c5c6f61 Mon Sep 17 00:00:00 2001 From: Tal Date: Thu, 1 Feb 2024 09:06:01 +0200 Subject: [PATCH 27/50] Update README.md --- README.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 95ab106e..5dcc78a4 100644 --- a/README.md +++ b/README.md @@ -235,14 +235,15 @@ There are several ways to use PR-Agent: 1. **Fully managed** - We take care of everything for you - hosting, models, regular updates, and more. Installation is as simple as signing up and adding the PR-Agent app to your GitHub\BitBucket repo. 2. **Improved privacy** - No data will be stored or used to train models. PR-Agent Pro will employ zero data retention, and will use an OpenAI account with zero data retention. 3. **Improved support** - PR-Agent Pro users will receive priority support, and will be able to request new features and capabilities. -4. **Extra features** -In addition to the benefits listed above, PR-Agent Pro will emphasize more customization, and the usage of static code analysis, in addition to LLM logic, to improve results. It has the following additional features: - - [**SOC2 compliance check**](https://github.com/Codium-ai/pr-agent/blob/main/docs/REVIEW.md#soc2-ticket-compliance-) +4. **Extra features** -In addition to the benefits listed above, PR-Agent Pro will emphasize more customization, and the usage of static code analysis, in addition to LLM logic, to improve results. It has the following additional tools and features: + - [**Analyze PR components**](https://github.com/Codium-ai/pr-agent/blob/main/docs/Analyze.md) + - [**Custom Code Suggestions**](https://github.com/Codium-ai/pr-agent/blob/main/docs/CUSTOM_SUGGESTIONS.md) + - [**Tests**](https://github.com/Codium-ai/pr-agent/blob/main/docs/TEST.md) - [**PR documentation**](https://github.com/Codium-ai/pr-agent/blob/main/docs/ADD_DOCUMENTATION.md) + - [**SOC2 compliance check**](https://github.com/Codium-ai/pr-agent/blob/main/docs/REVIEW.md#soc2-ticket-compliance-) - [**Custom labels**](https://github.com/Codium-ai/pr-agent/blob/main/docs/DESCRIBE.md#handle-custom-labels-from-the-repos-labels-page-gem) - [**Global configuration**](https://github.com/Codium-ai/pr-agent/blob/main/Usage.md#global-configuration-file-) - - [**Analyze PR components**](https://github.com/Codium-ai/pr-agent/blob/main/docs/Analyze.md) - - **Custom Code Suggestions** [WIP] - - **Chat on Specific Code Lines** [WIP] + ## How it works From d04d8b616a995878a83bd9fe8dbf919022177844 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Thu, 1 Feb 2024 09:46:04 +0200 Subject: [PATCH 28/50] moving the 'improve' command to turbo mode, with auto_extended=true --- pr_agent/algo/__init__.py | 1 + pr_agent/algo/pr_processing.py | 13 ++++++++----- pr_agent/algo/utils.py | 4 ++++ pr_agent/settings/configuration.toml | 12 +++++++----- pr_agent/tools/pr_code_suggestions.py | 14 +++++++++++--- 5 files changed, 31 insertions(+), 13 deletions(-) diff --git a/pr_agent/algo/__init__.py b/pr_agent/algo/__init__.py index 63a628a5..0f647bf4 100644 --- a/pr_agent/algo/__init__.py +++ b/pr_agent/algo/__init__.py @@ -9,6 +9,7 @@ MAX_TOKENS = { 'gpt-4-0613': 8000, 'gpt-4-32k': 32000, 'gpt-4-1106-preview': 128000, # 128K, but may be limited by config.max_model_tokens + 'gpt-4-0125-preview': 128000, # 128K, but may be limited by config.max_model_tokens 'claude-instant-1': 100000, 'claude-2': 100000, 'command-nightly': 4096, diff --git a/pr_agent/algo/pr_processing.py b/pr_agent/algo/pr_processing.py index 1e482dbf..61061bbd 100644 --- a/pr_agent/algo/pr_processing.py +++ b/pr_agent/algo/pr_processing.py @@ -11,7 +11,7 @@ from pr_agent.algo.git_patch_processing import convert_to_hunks_with_lines_numbe from pr_agent.algo.language_handler import sort_files_by_main_languages from pr_agent.algo.file_filter import filter_ignored from pr_agent.algo.token_handler import TokenHandler -from pr_agent.algo.utils import get_max_tokens +from pr_agent.algo.utils import get_max_tokens, ModelType from pr_agent.config_loader import get_settings from pr_agent.git_providers.git_provider import FilePatchInfo, GitProvider, EDIT_TYPE from pr_agent.log import get_logger @@ -220,8 +220,8 @@ def pr_generate_compressed_diff(top_langs: list, token_handler: TokenHandler, mo return patches, modified_files_list, deleted_files_list, added_files_list -async def retry_with_fallback_models(f: Callable): - all_models = _get_all_models() +async def retry_with_fallback_models(f: Callable, model_type: ModelType = ModelType.REGULAR): + all_models = _get_all_models(model_type) all_deployments = _get_all_deployments(all_models) # try each (model, deployment_id) pair until one is successful, otherwise raise exception for i, (model, deployment_id) in enumerate(zip(all_models, all_deployments)): @@ -243,8 +243,11 @@ async def retry_with_fallback_models(f: Callable): raise # Re-raise the last exception -def _get_all_models() -> List[str]: - model = get_settings().config.model +def _get_all_models(model_type: ModelType = ModelType.REGULAR) -> List[str]: + if model_type == ModelType.TURBO: + model = get_settings().config.model_turbo + else: + model = get_settings().config.model fallback_models = get_settings().config.fallback_models if not isinstance(fallback_models, list): fallback_models = [m.strip() for m in fallback_models.split(",")] diff --git a/pr_agent/algo/utils.py b/pr_agent/algo/utils.py index 9a150864..e92c3219 100644 --- a/pr_agent/algo/utils.py +++ b/pr_agent/algo/utils.py @@ -5,6 +5,7 @@ import json import re import textwrap from datetime import datetime +from enum import Enum from typing import Any, List import yaml @@ -15,6 +16,9 @@ from pr_agent.algo.token_handler import get_token_encoder from pr_agent.config_loader import get_settings, global_settings from pr_agent.log import get_logger +class ModelType(str, Enum): + REGULAR = "regular" + TURBO = "turbo" def get_setting(key: str) -> Any: try: diff --git a/pr_agent/settings/configuration.toml b/pr_agent/settings/configuration.toml index 3a9b8d39..5c7a35eb 100644 --- a/pr_agent/settings/configuration.toml +++ b/pr_agent/settings/configuration.toml @@ -1,5 +1,6 @@ [config] model="gpt-4" # "gpt-4-0125-preview" +model_turbo="gpt-4-0125-preview" fallback_models=["gpt-3.5-turbo-16k"] git_provider="github" publish_output=true @@ -68,17 +69,18 @@ enable_help_text=true [pr_code_suggestions] # /improve # +max_context_tokens=8000 num_code_suggestions=4 summarize = true extra_instructions = "" rank_suggestions = false enable_help_text=true # params for '/improve --extended' mode -auto_extended_mode=false -num_code_suggestions_per_chunk=8 -rank_extended_suggestions = true -max_number_of_calls = 5 -final_clip_factor = 0.9 +auto_extended_mode=true +num_code_suggestions_per_chunk=5 +rank_extended_suggestions = false +max_number_of_calls = 3 +final_clip_factor = 0.8 [pr_add_docs] # /add_docs # extra_instructions = "" diff --git a/pr_agent/tools/pr_code_suggestions.py b/pr_agent/tools/pr_code_suggestions.py index 381c02a6..fb725848 100644 --- a/pr_agent/tools/pr_code_suggestions.py +++ b/pr_agent/tools/pr_code_suggestions.py @@ -8,7 +8,7 @@ from pr_agent.algo.ai_handlers.base_ai_handler import BaseAiHandler from pr_agent.algo.ai_handlers.litellm_ai_handler import LiteLLMAIHandler from pr_agent.algo.pr_processing import get_pr_diff, get_pr_multi_diffs, retry_with_fallback_models from pr_agent.algo.token_handler import TokenHandler -from pr_agent.algo.utils import load_yaml, replace_code_tags +from pr_agent.algo.utils import load_yaml, replace_code_tags, ModelType from pr_agent.config_loader import get_settings from pr_agent.git_providers import get_git_provider from pr_agent.git_providers.git_provider import get_main_pr_language @@ -26,6 +26,14 @@ class PRCodeSuggestions: self.git_provider.get_languages(), self.git_provider.get_files() ) + # limit context specifically for the improve command, which has hard input to parse: + if get_settings().pr_code_suggestions.max_context_tokens: + MAX_CONTEXT_TOKENS_IMPROVE = get_settings().pr_code_suggestions.max_context_tokens + if get_settings().config.max_model_tokens > MAX_CONTEXT_TOKENS_IMPROVE: + get_logger().info(f"Setting max_model_tokens to {MAX_CONTEXT_TOKENS_IMPROVE} for PR improve") + get_settings().config.max_model_tokens = MAX_CONTEXT_TOKENS_IMPROVE + + # extended mode try: self.is_extended = self._get_is_extended(args or []) @@ -64,10 +72,10 @@ class PRCodeSuggestions: get_logger().info('Preparing PR code suggestions...') if not self.is_extended: - await retry_with_fallback_models(self._prepare_prediction) + await retry_with_fallback_models(self._prepare_prediction, ModelType.TURBO) data = self._prepare_pr_code_suggestions() else: - data = await retry_with_fallback_models(self._prepare_prediction_extended) + data = await retry_with_fallback_models(self._prepare_prediction_extended, ModelType.TURBO) if (not data) or (not 'code_suggestions' in data): From 023f2eb77c01ffa2bfa18178d5ae4a9ee7032764 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Fri, 2 Feb 2024 14:07:06 +0200 Subject: [PATCH 29/50] pr-actions --- README.md | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 5dcc78a4..f64bb2f6 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,17 @@ Making pull requests less painful with an AI agent - [Why use PR-Agent?](#why-use-pr-agent) ## News and Updates +### Feb 2, 2024 +We are excited to introduce "PR Actions" 💎: + + + +[](https://www.codium.ai/images/pr_agent/pr-actions.mp4) + + + +(click on the image to see a video demonstration) + ### Jan 28, 2024 - 💎 Test - A new tool, [`/test component_name`](https://github.com/Codium-ai/pr-agent/blob/main/docs/TEST.md), was added to PR-Agent Pro. The tool will generate tests for a selected component, based on the PR code changes. - 💎 Analyze - The [`/analyze`](https://github.com/Codium-ai/pr-agent/blob/main/docs/Analyze.md) tool was updated and simplified. It now presents a summary of the code components that were changed in the PR. @@ -38,23 +49,6 @@ Making pull requests less painful with an AI agent - 💎 Custom suggestions - A new tool, `/custom_suggestions`, was added to PR-Agent Pro. The tool will propose only suggestions that follow specific guidelines defined by the user. See [here](https://github.com/Codium-ai/pr-agent/blob/main/docs/CUSTOM_SUGGESTIONS.md) for more details. -### Jan 17, 2024 -- 💎 Inline file summary - The `describe` tool has a new option `--pr_description.inline_file_summary`, which allows to add a summary of each file changes to the Diffview page. See [here](https://github.com/Codium-ai/pr-agent/blob/main/docs/DESCRIBE.md#inline-file-summary-) -- The `improve` tool can now present suggestions in a nice collapsible format, which significantly reduces the PR footprint. See [here](https://github.com/Codium-ai/pr-agent/blob/main/docs/IMPROVE.md#summarized-vs-commitable-code-suggestions) for more details. -- To accompany the improved interface of the `improve` tool, we change the [default automation settings](https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/settings/configuration.toml#L116) of our GithupApp to: -``` -pr_commands = [ - "/describe --pr_description.add_original_user_description=true --pr_description.keep_original_user_title=true", - "/review --pr_reviewer.num_code_suggestions=0", - "/improve --pr_code_suggestions.summarize=true", -] -``` -Meaning that by default, for each PR the `describe`, `review`, and `improve` tools will be triggered automatically, and the `improve` tool will present the suggestions in a single comment. -You can of course overwrite these defaults by adding a `.pr_agent.toml` file to your repo. See [here](https://github.com/Codium-ai/pr-agent/blob/main/Usage.md#working-with-github-app). - -### Jan 10, 2024 -[LanceDB](https://lancedb.com/) is now supported as a locally hosted VectorDB for the `similar_issue` tool. See [here](./docs/SIMILAR_ISSUE.md) for more details. - ## Overview
@@ -78,7 +72,7 @@ CodiumAI PR-Agent is an open-source tool to help efficiently review and handle p | | Find Similar Issue | :white_check_mark: | | | | | [Add PR Documentation](https://github.com/Codium-ai/pr-agent/blob/main/docs/ADD_DOCUMENTATION.md) 💎 | :white_check_mark: | :white_check_mark: | :white_check_mark: | | | [Custom Labels](https://github.com/Codium-ai/pr-agent/blob/main/docs/DESCRIBE.md#handle-custom-labels-from-the-repos-labels-page-gem) 💎 | :white_check_mark: | :white_check_mark: | | -| | [Analyze](https://github.com/Codium-ai/pr-agent/blob/main/docs/Analyze.md) 💎 | :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | [Analyze](https://github.com/Codium-ai/pr-agent/blob/main/docs/Analyze.md) 💎 | :white_check_mark: | :white_check_mark: | | | | | | | | | USAGE | CLI | :white_check_mark: | :white_check_mark: | :white_check_mark: | | | App / webhook | :white_check_mark: | :white_check_mark: | :white_check_mark: | @@ -91,6 +85,8 @@ CodiumAI PR-Agent is an open-source tool to help efficiently review and handle p | | Multiple models support | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | | | [Static code analysis](https://github.com/Codium-ai/pr-agent/blob/main/docs/Analyze.md) 💎 | :white_check_mark: | :white_check_mark: | :white_check_mark: | | | [Global configuration](https://github.com/Codium-ai/pr-agent/blob/main/Usage.md#global-configuration-file-) 💎 | :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | [PR Actions](https://www.codium.ai/images/pr_agent/pr-actions.mp4) 💎 | :white_check_mark: | | | + - 💎 means this feature is available only in [PR-Agent Pro](https://www.codium.ai/pricing/) - Support for additional git providers is described in [here](./docs/Full_environments.md) ___ From e1b0e4a40a9bbf97b7cf1feb41a118d18ec10520 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Sun, 4 Feb 2024 14:24:55 +0200 Subject: [PATCH 30/50] minor prompt changes --- .../settings/pr_code_suggestions_prompts.toml | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/pr_agent/settings/pr_code_suggestions_prompts.toml b/pr_agent/settings/pr_code_suggestions_prompts.toml index 71d92350..22a699ec 100644 --- a/pr_agent/settings/pr_code_suggestions_prompts.toml +++ b/pr_agent/settings/pr_code_suggestions_prompts.toml @@ -9,11 +9,11 @@ Example for the PR Diff format: @@ ... @@ def func1(): __new hunk__ 12 code line1 that remained unchanged in the PR -13 +new code line2 added in the PR +13 +new hunk code line2 added in the PR 14 code line3 that remained unchanged in the PR __old hunk__ code line1 that remained unchanged in the PR --old code line2 that was removed in the PR +-old hunk code line2 that was removed in the PR code line3 that remained unchanged in the PR @@ ... @@ def func2(): @@ -33,7 +33,7 @@ Specific instructions: - The suggestions should refer only to code from the '__new hunk__' sections, and focus on new lines of code (lines starting with '+'). - Prioritize suggestions that address major problems, issues and bugs in the PR code. As a second priority, suggestions should focus on enhancement, best practice, performance, maintainability, and other aspects. - Don't suggest to add docstring, type hints, or comments, or to remove unused imports. -- Avoid making suggestions that have already been implemented in the PR code. For example, if you want to add logs, or change a variable to const, or anything else, make sure it isn't already in the '__new hunk__' code. +- Suggestions should not repeat code already present in the '__new hunk__' sections. - Provide the exact line numbers range (inclusive) for each suggestion. - When quoting variables or names from the code, use backticks (`) instead of single quote ('). @@ -72,35 +72,35 @@ class PRCodeSuggestions(BaseModel): Example output: ```yaml code_suggestions: -- relevant_file: |- +- relevant_file: | src/file1.py - language: |- + language: | python - suggestion_content: |- + suggestion_content: | Add a docstring to func1() {%- if summarize_mode %} - existing_code: |- + existing_code: | def func1(): - improved_code: |- + improved_code: | ... - one_sentence_summary: |- + one_sentence_summary: | ... relevant_lines_start: 12 relevant_lines_end: 12 {%- else %} - existing_code: |- + existing_code: | def func1(): relevant_lines_start: 12 relevant_lines_end: 12 - improved_code: |- + improved_code: | ... {%- endif %} - label: |- + label: | ... ``` -Each YAML output MUST be after a newline, indented, with block scalar indicator ('|-'). +Each YAML output MUST be after a newline, indented, with block scalar indicator ('|'). """ user="""PR Info: From 3e128869dc5f619cde5b79fe47b9964d78a09c8c Mon Sep 17 00:00:00 2001 From: mrT23 Date: Sun, 4 Feb 2024 16:10:53 +0200 Subject: [PATCH 31/50] large patch protection --- pr_agent/algo/pr_processing.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pr_agent/algo/pr_processing.py b/pr_agent/algo/pr_processing.py index 61061bbd..e44a63a8 100644 --- a/pr_agent/algo/pr_processing.py +++ b/pr_agent/algo/pr_processing.py @@ -408,6 +408,11 @@ def get_pr_multi_diffs(git_provider: GitProvider, patch = convert_to_hunks_with_lines_numbers(patch, file) new_patch_tokens = token_handler.count_tokens(patch) + + if patch and new_patch_tokens > get_max_tokens(model) - OUTPUT_BUFFER_TOKENS_SOFT_THRESHOLD: + get_logger().warning(f"Patch too large, skipping: {file.filename}") + continue + if patch and (total_tokens + new_patch_tokens > get_max_tokens(model) - OUTPUT_BUFFER_TOKENS_SOFT_THRESHOLD): final_diff = "\n".join(patches) final_diff_list.append(final_diff) From e104bd7a3f0da18dd65ab3d38d5d5fea5c7b3119 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Sun, 4 Feb 2024 16:27:57 +0200 Subject: [PATCH 32/50] large patch protection --- pr_agent/algo/pr_processing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pr_agent/algo/pr_processing.py b/pr_agent/algo/pr_processing.py index e44a63a8..19e16a8e 100644 --- a/pr_agent/algo/pr_processing.py +++ b/pr_agent/algo/pr_processing.py @@ -409,7 +409,7 @@ def get_pr_multi_diffs(git_provider: GitProvider, patch = convert_to_hunks_with_lines_numbers(patch, file) new_patch_tokens = token_handler.count_tokens(patch) - if patch and new_patch_tokens > get_max_tokens(model) - OUTPUT_BUFFER_TOKENS_SOFT_THRESHOLD: + if patch and (token_handler.prompt_tokens + new_patch_tokens) > get_max_tokens(model) - OUTPUT_BUFFER_TOKENS_SOFT_THRESHOLD: get_logger().warning(f"Patch too large, skipping: {file.filename}") continue From 2ee329674f6adc26f3f99a71b890667d768149ea Mon Sep 17 00:00:00 2001 From: mrT23 Date: Mon, 5 Feb 2024 09:20:36 +0200 Subject: [PATCH 33/50] insert_br_after_x_chars --- pr_agent/algo/git_patch_processing.py | 2 +- pr_agent/algo/pr_processing.py | 79 +------------------ pr_agent/algo/types.py | 23 ++++++ pr_agent/algo/utils.py | 77 +++++++++++++++++- .../git_providers/azuredevops_provider.py | 3 +- pr_agent/git_providers/bitbucket_provider.py | 5 +- .../bitbucket_server_provider.py | 6 +- pr_agent/git_providers/codecommit_provider.py | 4 +- pr_agent/git_providers/gerrit_provider.py | 3 +- pr_agent/git_providers/git_provider.py | 24 +----- pr_agent/git_providers/github_provider.py | 6 +- pr_agent/git_providers/gitlab_provider.py | 6 +- pr_agent/git_providers/local_git_provider.py | 3 +- pr_agent/tools/pr_description.py | 78 +++++++++++------- tests/unittest/test_codecommit_provider.py | 2 +- tests/unittest/test_convert_to_markdown.py | 26 ++++++ ...nd_line_number_of_relevant_line_in_file.py | 5 +- 17 files changed, 200 insertions(+), 152 deletions(-) create mode 100644 pr_agent/algo/types.py diff --git a/pr_agent/algo/git_patch_processing.py b/pr_agent/algo/git_patch_processing.py index 10d140b0..72c9aebf 100644 --- a/pr_agent/algo/git_patch_processing.py +++ b/pr_agent/algo/git_patch_processing.py @@ -3,7 +3,7 @@ from __future__ import annotations import re from pr_agent.config_loader import get_settings -from pr_agent.git_providers.git_provider import EDIT_TYPE +from pr_agent.algo.types import EDIT_TYPE, FilePatchInfo from pr_agent.log import get_logger diff --git a/pr_agent/algo/pr_processing.py b/pr_agent/algo/pr_processing.py index 19e16a8e..30738236 100644 --- a/pr_agent/algo/pr_processing.py +++ b/pr_agent/algo/pr_processing.py @@ -1,9 +1,7 @@ from __future__ import annotations -import difflib -import re import traceback -from typing import Any, Callable, List, Tuple +from typing import Callable, List, Tuple from github import RateLimitExceededException @@ -13,7 +11,8 @@ from pr_agent.algo.file_filter import filter_ignored from pr_agent.algo.token_handler import TokenHandler from pr_agent.algo.utils import get_max_tokens, ModelType from pr_agent.config_loader import get_settings -from pr_agent.git_providers.git_provider import FilePatchInfo, GitProvider, EDIT_TYPE +from pr_agent.git_providers.git_provider import GitProvider +from pr_agent.algo.types import EDIT_TYPE, FilePatchInfo from pr_agent.log import get_logger DELETED_FILES_ = "Deleted files:\n" @@ -270,78 +269,6 @@ def _get_all_deployments(all_models: List[str]) -> List[str]: return all_deployments -def find_line_number_of_relevant_line_in_file(diff_files: List[FilePatchInfo], - relevant_file: str, - relevant_line_in_file: str, - absolute_position: int = None) -> Tuple[int, int]: - position = -1 - if absolute_position is None: - absolute_position = -1 - re_hunk_header = re.compile( - r"^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@[ ]?(.*)") - - for file in diff_files: - if file.filename and (file.filename.strip() == relevant_file): - patch = file.patch - patch_lines = patch.splitlines() - delta = 0 - start1, size1, start2, size2 = 0, 0, 0, 0 - if absolute_position != -1: # matching absolute to relative - for i, line in enumerate(patch_lines): - # new hunk - if line.startswith('@@'): - delta = 0 - match = re_hunk_header.match(line) - start1, size1, start2, size2 = map(int, match.groups()[:4]) - elif not line.startswith('-'): - delta += 1 - - # - absolute_position_curr = start2 + delta - 1 - - if absolute_position_curr == absolute_position: - position = i - break - else: - # try to find the line in the patch using difflib, with some margin of error - matches_difflib: list[str | Any] = difflib.get_close_matches(relevant_line_in_file, - patch_lines, n=3, cutoff=0.93) - if len(matches_difflib) == 1 and matches_difflib[0].startswith('+'): - relevant_line_in_file = matches_difflib[0] - - - for i, line in enumerate(patch_lines): - if line.startswith('@@'): - delta = 0 - match = re_hunk_header.match(line) - start1, size1, start2, size2 = map(int, match.groups()[:4]) - elif not line.startswith('-'): - delta += 1 - - if relevant_line_in_file in line and line[0] != '-': - position = i - absolute_position = start2 + delta - 1 - break - - if position == -1 and relevant_line_in_file[0] == '+': - no_plus_line = relevant_line_in_file[1:].lstrip() - for i, line in enumerate(patch_lines): - if line.startswith('@@'): - delta = 0 - match = re_hunk_header.match(line) - start1, size1, start2, size2 = map(int, match.groups()[:4]) - elif not line.startswith('-'): - delta += 1 - - if no_plus_line in line and line[0] != '-': - # The model might add a '+' to the beginning of the relevant_line_in_file even if originally - # it's a context line - position = i - absolute_position = start2 + delta - 1 - break - return position, absolute_position - - def get_pr_multi_diffs(git_provider: GitProvider, token_handler: TokenHandler, model: str, diff --git a/pr_agent/algo/types.py b/pr_agent/algo/types.py new file mode 100644 index 00000000..045115b4 --- /dev/null +++ b/pr_agent/algo/types.py @@ -0,0 +1,23 @@ +from dataclasses import dataclass +from enum import Enum + + +class EDIT_TYPE(Enum): + ADDED = 1 + DELETED = 2 + MODIFIED = 3 + RENAMED = 4 + UNKNOWN = 5 + + +@dataclass +class FilePatchInfo: + base_file: str + head_file: str + patch: str + filename: str + tokens: int = -1 + edit_type: EDIT_TYPE = EDIT_TYPE.UNKNOWN + old_filename: str = None + num_plus_lines: int = -1 + num_minus_lines: int = -1 diff --git a/pr_agent/algo/utils.py b/pr_agent/algo/utils.py index e92c3219..f7b1f7cd 100644 --- a/pr_agent/algo/utils.py +++ b/pr_agent/algo/utils.py @@ -6,7 +6,7 @@ import re import textwrap from datetime import datetime from enum import Enum -from typing import Any, List +from typing import Any, List, Tuple import yaml from starlette_context import context @@ -14,6 +14,7 @@ from starlette_context import context from pr_agent.algo import MAX_TOKENS from pr_agent.algo.token_handler import get_token_encoder from pr_agent.config_loader import get_settings, global_settings +from pr_agent.algo.types import FilePatchInfo from pr_agent.log import get_logger class ModelType(str, Enum): @@ -487,4 +488,76 @@ def replace_code_tags(text): parts = text.split('`') for i in range(1, len(parts), 2): parts[i] = '' + parts[i] + '' - return ''.join(parts) \ No newline at end of file + return ''.join(parts) + + +def find_line_number_of_relevant_line_in_file(diff_files: List[FilePatchInfo], + relevant_file: str, + relevant_line_in_file: str, + absolute_position: int = None) -> Tuple[int, int]: + position = -1 + if absolute_position is None: + absolute_position = -1 + re_hunk_header = re.compile( + r"^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@[ ]?(.*)") + + for file in diff_files: + if file.filename and (file.filename.strip() == relevant_file): + patch = file.patch + patch_lines = patch.splitlines() + delta = 0 + start1, size1, start2, size2 = 0, 0, 0, 0 + if absolute_position != -1: # matching absolute to relative + for i, line in enumerate(patch_lines): + # new hunk + if line.startswith('@@'): + delta = 0 + match = re_hunk_header.match(line) + start1, size1, start2, size2 = map(int, match.groups()[:4]) + elif not line.startswith('-'): + delta += 1 + + # + absolute_position_curr = start2 + delta - 1 + + if absolute_position_curr == absolute_position: + position = i + break + else: + # try to find the line in the patch using difflib, with some margin of error + matches_difflib: list[str | Any] = difflib.get_close_matches(relevant_line_in_file, + patch_lines, n=3, cutoff=0.93) + if len(matches_difflib) == 1 and matches_difflib[0].startswith('+'): + relevant_line_in_file = matches_difflib[0] + + + for i, line in enumerate(patch_lines): + if line.startswith('@@'): + delta = 0 + match = re_hunk_header.match(line) + start1, size1, start2, size2 = map(int, match.groups()[:4]) + elif not line.startswith('-'): + delta += 1 + + if relevant_line_in_file in line and line[0] != '-': + position = i + absolute_position = start2 + delta - 1 + break + + if position == -1 and relevant_line_in_file[0] == '+': + no_plus_line = relevant_line_in_file[1:].lstrip() + for i, line in enumerate(patch_lines): + if line.startswith('@@'): + delta = 0 + match = re_hunk_header.match(line) + start1, size1, start2, size2 = map(int, match.groups()[:4]) + elif not line.startswith('-'): + delta += 1 + + if no_plus_line in line and line[0] != '-': + # The model might add a '+' to the beginning of the relevant_line_in_file even if originally + # it's a context line + position = i + absolute_position = start2 + delta - 1 + break + return position, absolute_position diff --git a/pr_agent/git_providers/azuredevops_provider.py b/pr_agent/git_providers/azuredevops_provider.py index 17d87488..a46c0ab2 100644 --- a/pr_agent/git_providers/azuredevops_provider.py +++ b/pr_agent/git_providers/azuredevops_provider.py @@ -6,7 +6,8 @@ from ..log import get_logger from ..algo.language_handler import is_valid_file from ..algo.utils import clip_tokens, load_large_diff from ..config_loader import get_settings -from .git_provider import EDIT_TYPE, FilePatchInfo, GitProvider +from .git_provider import GitProvider +from pr_agent.algo.types import EDIT_TYPE, FilePatchInfo AZURE_DEVOPS_AVAILABLE = True diff --git a/pr_agent/git_providers/bitbucket_provider.py b/pr_agent/git_providers/bitbucket_provider.py index c98ebc05..c761d10b 100644 --- a/pr_agent/git_providers/bitbucket_provider.py +++ b/pr_agent/git_providers/bitbucket_provider.py @@ -6,10 +6,11 @@ import requests from atlassian.bitbucket import Cloud from starlette_context import context -from ..algo.pr_processing import find_line_number_of_relevant_line_in_file +from pr_agent.algo.types import FilePatchInfo, EDIT_TYPE +from ..algo.utils import find_line_number_of_relevant_line_in_file from ..config_loader import get_settings from ..log import get_logger -from .git_provider import FilePatchInfo, GitProvider, EDIT_TYPE +from .git_provider import GitProvider class BitbucketProvider(GitProvider): diff --git a/pr_agent/git_providers/bitbucket_server_provider.py b/pr_agent/git_providers/bitbucket_server_provider.py index 2d96120b..9798cd5e 100644 --- a/pr_agent/git_providers/bitbucket_server_provider.py +++ b/pr_agent/git_providers/bitbucket_server_provider.py @@ -6,9 +6,9 @@ import requests from atlassian.bitbucket import Bitbucket from starlette_context import context -from .git_provider import FilePatchInfo, GitProvider, EDIT_TYPE -from ..algo.pr_processing import find_line_number_of_relevant_line_in_file -from ..algo.utils import load_large_diff +from .git_provider import GitProvider +from pr_agent.algo.types import FilePatchInfo +from ..algo.utils import load_large_diff, find_line_number_of_relevant_line_in_file from ..config_loader import get_settings from ..log import get_logger diff --git a/pr_agent/git_providers/codecommit_provider.py b/pr_agent/git_providers/codecommit_provider.py index 3c7b7697..50398c17 100644 --- a/pr_agent/git_providers/codecommit_provider.py +++ b/pr_agent/git_providers/codecommit_provider.py @@ -5,9 +5,9 @@ from typing import List, Optional, Tuple from urllib.parse import urlparse from pr_agent.git_providers.codecommit_client import CodeCommitClient - +from pr_agent.algo.types import EDIT_TYPE, FilePatchInfo from ..algo.utils import load_large_diff -from .git_provider import EDIT_TYPE, FilePatchInfo, GitProvider +from .git_provider import GitProvider from ..config_loader import get_settings from ..log import get_logger diff --git a/pr_agent/git_providers/gerrit_provider.py b/pr_agent/git_providers/gerrit_provider.py index f7dd05ac..a1491c78 100644 --- a/pr_agent/git_providers/gerrit_provider.py +++ b/pr_agent/git_providers/gerrit_provider.py @@ -13,7 +13,8 @@ import urllib3.util from git import Repo from pr_agent.config_loader import get_settings -from pr_agent.git_providers.git_provider import EDIT_TYPE, FilePatchInfo, GitProvider +from pr_agent.git_providers.git_provider import GitProvider +from pr_agent.algo.types import EDIT_TYPE, FilePatchInfo from pr_agent.git_providers.local_git_provider import PullRequestMimic from pr_agent.log import get_logger diff --git a/pr_agent/git_providers/git_provider.py b/pr_agent/git_providers/git_provider.py index f981d863..ae2109b5 100644 --- a/pr_agent/git_providers/git_provider.py +++ b/pr_agent/git_providers/git_provider.py @@ -1,35 +1,13 @@ from abc import ABC, abstractmethod -from dataclasses import dataclass # enum EDIT_TYPE (ADDED, DELETED, MODIFIED, RENAMED) -from enum import Enum from typing import Optional from pr_agent.config_loader import get_settings +from pr_agent.algo.types import FilePatchInfo from pr_agent.log import get_logger -class EDIT_TYPE(Enum): - ADDED = 1 - DELETED = 2 - MODIFIED = 3 - RENAMED = 4 - UNKNOWN = 5 - - -@dataclass -class FilePatchInfo: - base_file: str - head_file: str - patch: str - filename: str - tokens: int = -1 - edit_type: EDIT_TYPE = EDIT_TYPE.UNKNOWN - old_filename: str = None - num_plus_lines: int = -1 - num_minus_lines: int = -1 - - class GitProvider(ABC): @abstractmethod def is_supported(self, capability: str) -> bool: diff --git a/pr_agent/git_providers/github_provider.py b/pr_agent/git_providers/github_provider.py index aaf1f386..9b89973d 100644 --- a/pr_agent/git_providers/github_provider.py +++ b/pr_agent/git_providers/github_provider.py @@ -9,12 +9,12 @@ from retry import retry from starlette_context import context from ..algo.language_handler import is_valid_file -from ..algo.pr_processing import find_line_number_of_relevant_line_in_file -from ..algo.utils import load_large_diff, clip_tokens +from ..algo.utils import load_large_diff, clip_tokens, find_line_number_of_relevant_line_in_file from ..config_loader import get_settings from ..log import get_logger from ..servers.utils import RateLimitExceeded -from .git_provider import FilePatchInfo, GitProvider, IncrementalPR, EDIT_TYPE +from .git_provider import GitProvider, IncrementalPR +from pr_agent.algo.types import EDIT_TYPE, FilePatchInfo class GithubProvider(GitProvider): diff --git a/pr_agent/git_providers/gitlab_provider.py b/pr_agent/git_providers/gitlab_provider.py index 4db37305..85525e6c 100644 --- a/pr_agent/git_providers/gitlab_provider.py +++ b/pr_agent/git_providers/gitlab_provider.py @@ -7,10 +7,10 @@ import gitlab from gitlab import GitlabGetError from ..algo.language_handler import is_valid_file -from ..algo.pr_processing import find_line_number_of_relevant_line_in_file -from ..algo.utils import load_large_diff, clip_tokens +from ..algo.utils import load_large_diff, clip_tokens, find_line_number_of_relevant_line_in_file from ..config_loader import get_settings -from .git_provider import EDIT_TYPE, FilePatchInfo, GitProvider +from .git_provider import GitProvider +from pr_agent.algo.types import EDIT_TYPE, FilePatchInfo from ..log import get_logger diff --git a/pr_agent/git_providers/local_git_provider.py b/pr_agent/git_providers/local_git_provider.py index 3d45d35c..83c50791 100644 --- a/pr_agent/git_providers/local_git_provider.py +++ b/pr_agent/git_providers/local_git_provider.py @@ -5,7 +5,8 @@ from typing import List from git import Repo from pr_agent.config_loader import _find_repository_root, get_settings -from pr_agent.git_providers.git_provider import EDIT_TYPE, FilePatchInfo, GitProvider +from pr_agent.git_providers.git_provider import GitProvider +from pr_agent.algo.types import EDIT_TYPE, FilePatchInfo from pr_agent.log import get_logger diff --git a/pr_agent/tools/pr_description.py b/pr_agent/tools/pr_description.py index 5eb78549..ef64f515 100644 --- a/pr_agent/tools/pr_description.py +++ b/pr_agent/tools/pr_description.py @@ -379,8 +379,7 @@ class PRDescription: for filename, file_changes_title, file_change_description in list_tuples: filename = filename.replace("'", "`") filename_publish = filename.split("/")[-1] - file_changes_title_br = insert_br_after_x_chars(file_changes_title, x=(delta - 5), - new_line_char="\n\n") + file_changes_title_br = insert_br_after_x_chars(file_changes_title, x=(delta - 5)) file_changes_title_extended = file_changes_title_br.strip() + "" if len(file_changes_title_extended) < (delta - 5): file_changes_title_extended += "  " * ((delta - 5) - len(file_changes_title_extended)) @@ -428,48 +427,67 @@ class PRDescription: pass return pr_body -def insert_br_after_x_chars(text, x=70, new_line_char="
"): +def insert_br_after_x_chars(text, x=70): """ Insert
into a string after a word that increases its length above x characters. + Use proper HTML tags for code and new lines. """ if len(text) < x: return text - lines = text.splitlines() + # replace odd instances of ` with and even instances of ` with + text = replace_code_tags(text) + + # convert list items to
  • + if text.startswith("- "): + text = "
  • " + text[2:] + text = text.replace("\n- ", '
  • ').replace("\n - ", '
  • ') + + # convert new lines to
    + text = text.replace("\n", '
    ') + + # split text into lines + lines = text.split('
    ') words = [] - for i,line in enumerate(lines): + for i, line in enumerate(lines): words += line.split(' ') - if i x: - if not is_inside_code: - new_text += f"{new_line_char} " # Insert line break - current_length = 0 # Reset counter - else: - new_text += f"`{new_line_char} `" - # check if inside tag - if word.startswith("`") and not is_inside_code and not word.endswith("`"): + is_saved_word = False + if word == "" or word == "" or word == "
  • " or word == "
    ": + is_saved_word = True + if word == "": is_inside_code = True - if word.endswith("`"): + elif word == "": is_inside_code = False - # Add the word to the new text - if word.endswith("\n"): - new_text += word - else: - new_text += word + " " - current_length += len(word) + 1 # Add 1 for the space + if not is_saved_word and (current_length + len(word) > x): + if is_inside_code: + new_text.append("

    ") + else: + new_text.append("
    ") + current_length = 0 # Reset counter + new_text.append(word + " ") + if not is_saved_word: + current_length += len(word) + 1 # Add 1 for the space - if word.endswith("\n"): + if word == "
  • " or word == "
    ": current_length = 0 - return new_text.strip() # Remove trailing space + + return ''.join(new_text).strip() + +def replace_code_tags(text): + """ + Replace odd instances of ` with and even instances of ` with + """ + parts = text.split('`') + for i in range(1, len(parts), 2): + parts[i] = '' + parts[i] + '' + return ''.join(parts) + diff --git a/tests/unittest/test_codecommit_provider.py b/tests/unittest/test_codecommit_provider.py index 6f187de7..56312d73 100644 --- a/tests/unittest/test_codecommit_provider.py +++ b/tests/unittest/test_codecommit_provider.py @@ -3,7 +3,7 @@ from unittest.mock import patch from pr_agent.git_providers.codecommit_provider import CodeCommitFile from pr_agent.git_providers.codecommit_provider import CodeCommitProvider from pr_agent.git_providers.codecommit_provider import PullRequestCCMimic -from pr_agent.git_providers.git_provider import EDIT_TYPE +from pr_agent.algo.types import EDIT_TYPE, FilePatchInfo class TestCodeCommitFile: diff --git a/tests/unittest/test_convert_to_markdown.py b/tests/unittest/test_convert_to_markdown.py index 87f8f983..9e662a76 100644 --- a/tests/unittest/test_convert_to_markdown.py +++ b/tests/unittest/test_convert_to_markdown.py @@ -1,5 +1,6 @@ # Generated by CodiumAI from pr_agent.algo.utils import convert_to_markdown +from pr_agent.tools.pr_description import insert_br_after_x_chars """ Code Analysis @@ -93,3 +94,28 @@ class TestConvertToMarkdown: } expected_output = '' assert convert_to_markdown(input_data).strip() == expected_output.strip() + + +class TestBR: + def test_br1(self): + file_change_description = '- Created a new class `ColorPaletteResourcesCollection` in the namespace `Avalonia.Themes.Fluent`.\n- The class extends `AvaloniaDictionary` and implements `IResourceProvider`.\n- The class includes methods for handling theme variants, resource retrieval, owner management, and property change events.' + file_change_description_br = insert_br_after_x_chars(file_change_description) + expected_output=('
  • Created a new class ColorPaletteResourcesCollection
    in the namespace ' + 'Avalonia.Themes.Fluent.
  • The class extends AvaloniaDictionary' + 'ColorPaletteResources> and implements
    IResourceProvider' + '.
  • The class includes methods for handling theme variants, resource
    ' + 'retrieval, owner management, and property change events.') + assert file_change_description_br == expected_output + # print("-----") + # print(file_change_description_br) + + def test_br2(self): + file_change_description = ('- Created a - new -class `ColorPaletteResourcesCollection ColorPaletteResourcesCollection ' + 'ColorPaletteResourcesCollection ColorPaletteResourcesCollection`') + file_change_description_br = insert_br_after_x_chars(file_change_description) + expected_output = ('
  • Created a - new -class ColorPaletteResourcesCollection ' + '
    ColorPaletteResourcesCollection ColorPaletteResourcesCollection ' + '
    ColorPaletteResourcesCollection
    ') + assert file_change_description_br == expected_output + # print("-----") + # print(file_change_description_br) \ No newline at end of file diff --git a/tests/unittest/test_find_line_number_of_relevant_line_in_file.py b/tests/unittest/test_find_line_number_of_relevant_line_in_file.py index 7488c6df..f9d143c6 100644 --- a/tests/unittest/test_find_line_number_of_relevant_line_in_file.py +++ b/tests/unittest/test_find_line_number_of_relevant_line_in_file.py @@ -1,8 +1,7 @@ # Generated by CodiumAI -from pr_agent.git_providers.git_provider import FilePatchInfo -from pr_agent.algo.pr_processing import find_line_number_of_relevant_line_in_file - +from pr_agent.git_providers.types import FilePatchInfo +from pr_agent.algo.utils import find_line_number_of_relevant_line_in_file import pytest From 3f2a7869dde9445695b5a1b2120745fe91ed19c2 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Mon, 5 Feb 2024 09:22:26 +0200 Subject: [PATCH 34/50] insert_br_after_x_chars --- .../unittest/test_find_line_number_of_relevant_line_in_file.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unittest/test_find_line_number_of_relevant_line_in_file.py b/tests/unittest/test_find_line_number_of_relevant_line_in_file.py index f9d143c6..fcb028ca 100644 --- a/tests/unittest/test_find_line_number_of_relevant_line_in_file.py +++ b/tests/unittest/test_find_line_number_of_relevant_line_in_file.py @@ -1,6 +1,6 @@ # Generated by CodiumAI -from pr_agent.git_providers.types import FilePatchInfo +from pr_agent.algo.types import FilePatchInfo from pr_agent.algo.utils import find_line_number_of_relevant_line_in_file import pytest From 32e8ba331a3c2ed8c4bdf77a3c4a32c7cb95f4b3 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Mon, 5 Feb 2024 10:12:47 +0200 Subject: [PATCH 35/50] insert_br_after_x_chars --- pr_agent/tools/pr_code_suggestions.py | 2 +- pr_agent/tools/pr_description.py | 15 ++++++++++----- tests/unittest/test_convert_to_markdown.py | 19 +++++++++---------- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/pr_agent/tools/pr_code_suggestions.py b/pr_agent/tools/pr_code_suggestions.py index fb725848..5fc45619 100644 --- a/pr_agent/tools/pr_code_suggestions.py +++ b/pr_agent/tools/pr_code_suggestions.py @@ -325,7 +325,7 @@ class PRCodeSuggestions: pr_body += "" header = f"Suggestions" - delta = 77 + delta = 75 header += "  " * delta pr_body += f"""""" pr_body += """""" diff --git a/pr_agent/tools/pr_description.py b/pr_agent/tools/pr_description.py index ef64f515..bbe53fca 100644 --- a/pr_agent/tools/pr_description.py +++ b/pr_agent/tools/pr_description.py @@ -363,7 +363,7 @@ class PRDescription: try: pr_body += "
    {header}
    " header = f"Relevant files" - delta = 77 + delta = 75 # header += "  " * delta pr_body += f"""""" pr_body += """""" @@ -454,6 +454,10 @@ def insert_br_after_x_chars(text, x=70): if i < len(lines) - 1: words[-1] += "
    " + def count_chars_without_html(string): + no_html_string = re.sub('<[^>]+>', '', string) + return len(no_html_string) + new_text = [] is_inside_code = False current_length = 0 @@ -461,12 +465,13 @@ def insert_br_after_x_chars(text, x=70): is_saved_word = False if word == "" or word == "" or word == "
  • " or word == "
    ": is_saved_word = True - if word == "": + if "" in word: is_inside_code = True - elif word == "": + if "" in word: is_inside_code = False - if not is_saved_word and (current_length + len(word) > x): + len_word = count_chars_without_html(word) + if not is_saved_word and (current_length + len_word > x): if is_inside_code: new_text.append("
    ") else: @@ -475,7 +480,7 @@ def insert_br_after_x_chars(text, x=70): new_text.append(word + " ") if not is_saved_word: - current_length += len(word) + 1 # Add 1 for the space + current_length += len_word + 1 # Add 1 for the space if word == "
  • " or word == "
    ": current_length = 0 diff --git a/tests/unittest/test_convert_to_markdown.py b/tests/unittest/test_convert_to_markdown.py index 9e662a76..72d34656 100644 --- a/tests/unittest/test_convert_to_markdown.py +++ b/tests/unittest/test_convert_to_markdown.py @@ -98,13 +98,11 @@ class TestConvertToMarkdown: class TestBR: def test_br1(self): - file_change_description = '- Created a new class `ColorPaletteResourcesCollection` in the namespace `Avalonia.Themes.Fluent`.\n- The class extends `AvaloniaDictionary` and implements `IResourceProvider`.\n- The class includes methods for handling theme variants, resource retrieval, owner management, and property change events.' + file_change_description = '- Imported `FilePatchInfo` and `EDIT_TYPE` from `pr_agent.algo.types` instead of `pr_agent.git_providers.git_provider`.' file_change_description_br = insert_br_after_x_chars(file_change_description) - expected_output=('
  • Created a new class ColorPaletteResourcesCollection
    in the namespace ' - 'Avalonia.Themes.Fluent.
  • The class extends AvaloniaDictionary' - 'ColorPaletteResources> and implements
    IResourceProvider' - '.
  • The class includes methods for handling theme variants, resource
    ' - 'retrieval, owner management, and property change events.') + expected_output = ('
  • Imported FilePatchInfo and EDIT_TYPE from ' + 'pr_agent.algo.types instead
    of ' + 'pr_agent.git_providers.git_provider.') assert file_change_description_br == expected_output # print("-----") # print(file_change_description_br) @@ -113,9 +111,10 @@ class TestBR: file_change_description = ('- Created a - new -class `ColorPaletteResourcesCollection ColorPaletteResourcesCollection ' 'ColorPaletteResourcesCollection ColorPaletteResourcesCollection`') file_change_description_br = insert_br_after_x_chars(file_change_description) - expected_output = ('
  • Created a - new -class ColorPaletteResourcesCollection ' - '
    ColorPaletteResourcesCollection ColorPaletteResourcesCollection ' - '
    ColorPaletteResourcesCollection
    ') + expected_output = ('
  • Created a - new -class ColorPaletteResourcesCollection
    ' + 'ColorPaletteResourcesCollection ColorPaletteResourcesCollection
    ' + 'ColorPaletteResourcesCollection
    ') assert file_change_description_br == expected_output # print("-----") - # print(file_change_description_br) \ No newline at end of file + # print(file_change_description_br) + From cce3c70369c186529859d89af45dcb48802499c7 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Mon, 5 Feb 2024 12:03:30 +0200 Subject: [PATCH 36/50] - patch_extra_lines = 1 - describe is with turbo model (for larger context) --- pr_agent/settings/configuration.toml | 4 ++-- pr_agent/tools/pr_description.py | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/pr_agent/settings/configuration.toml b/pr_agent/settings/configuration.toml index 5c7a35eb..7ab2f8cb 100644 --- a/pr_agent/settings/configuration.toml +++ b/pr_agent/settings/configuration.toml @@ -9,11 +9,11 @@ verbosity_level=0 # 0,1,2 use_extra_bad_extensions=false use_repo_settings_file=true use_global_settings_file=true -ai_timeout=180 +ai_timeout=90 max_description_tokens = 500 max_commits_tokens = 500 max_model_tokens = 32000 # Limits the maximum number of tokens that can be used by any model, regardless of the model's default capabilities. -patch_extra_lines = 3 +patch_extra_lines = 1 secret_provider="google_cloud_storage" cli_mode=false diff --git a/pr_agent/tools/pr_description.py b/pr_agent/tools/pr_description.py index bbe53fca..4916de48 100644 --- a/pr_agent/tools/pr_description.py +++ b/pr_agent/tools/pr_description.py @@ -9,7 +9,7 @@ from pr_agent.algo.ai_handlers.base_ai_handler import BaseAiHandler from pr_agent.algo.ai_handlers.litellm_ai_handler import LiteLLMAIHandler from pr_agent.algo.pr_processing import get_pr_diff, retry_with_fallback_models from pr_agent.algo.token_handler import TokenHandler -from pr_agent.algo.utils import load_yaml, set_custom_labels, get_user_labels +from pr_agent.algo.utils import load_yaml, set_custom_labels, get_user_labels, ModelType from pr_agent.config_loader import get_settings from pr_agent.git_providers import get_git_provider from pr_agent.git_providers.git_provider import get_main_pr_language @@ -80,7 +80,7 @@ class PRDescription: if get_settings().config.publish_output: self.git_provider.publish_comment("Preparing PR description...", is_temporary=True) - await retry_with_fallback_models(self._prepare_prediction) + await retry_with_fallback_models(self._prepare_prediction, ModelType.TURBO) # turbo model because larger context get_logger().info(f"Preparing answer {self.pr_id}") if self.prediction: @@ -455,6 +455,8 @@ def insert_br_after_x_chars(text, x=70): words[-1] += "
    " def count_chars_without_html(string): + if '<' not in string: + return len(string) no_html_string = re.sub('<[^>]+>', '', string) return len(no_html_string) From 2b6e8c3f09378216a173710d4b33d39ad963c737 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Mon, 5 Feb 2024 12:39:03 +0200 Subject: [PATCH 37/50] minor change --- pr_agent/tools/pr_description.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pr_agent/tools/pr_description.py b/pr_agent/tools/pr_description.py index 4916de48..00ec358d 100644 --- a/pr_agent/tools/pr_description.py +++ b/pr_agent/tools/pr_description.py @@ -411,7 +411,10 @@ class PRDescription: {filename} {file_change_description_br} - + + + +
  • From c1c7b3b6da37ee1bd04f1cd2faeeb0f04eb15649 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Mon, 5 Feb 2024 13:00:57 +0200 Subject: [PATCH 38/50] fixed code --- pr_agent/tools/pr_description.py | 9 +++++---- tests/unittest/test_convert_to_markdown.py | 12 ++++++++++-- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/pr_agent/tools/pr_description.py b/pr_agent/tools/pr_description.py index 00ec358d..46fdc1b2 100644 --- a/pr_agent/tools/pr_description.py +++ b/pr_agent/tools/pr_description.py @@ -415,6 +415,7 @@ class PRDescription: + @@ -470,10 +471,6 @@ def insert_br_after_x_chars(text, x=70): is_saved_word = False if word == "" or word == "" or word == "
  • " or word == "
    ": is_saved_word = True - if "" in word: - is_inside_code = True - if "" in word: - is_inside_code = False len_word = count_chars_without_html(word) if not is_saved_word and (current_length + len_word > x): @@ -490,6 +487,10 @@ def insert_br_after_x_chars(text, x=70): if word == "
  • " or word == "
    ": current_length = 0 + if "" in word: + is_inside_code = True + if "" in word: + is_inside_code = False return ''.join(new_text).strip() def replace_code_tags(text): diff --git a/tests/unittest/test_convert_to_markdown.py b/tests/unittest/test_convert_to_markdown.py index 72d34656..36b0371d 100644 --- a/tests/unittest/test_convert_to_markdown.py +++ b/tests/unittest/test_convert_to_markdown.py @@ -112,9 +112,17 @@ class TestBR: 'ColorPaletteResourcesCollection ColorPaletteResourcesCollection`') file_change_description_br = insert_br_after_x_chars(file_change_description) expected_output = ('
  • Created a - new -class ColorPaletteResourcesCollection
    ' - 'ColorPaletteResourcesCollection ColorPaletteResourcesCollection
    ' - 'ColorPaletteResourcesCollection
    ') + 'ColorPaletteResourcesCollection ColorPaletteResourcesCollection ' + '

    ColorPaletteResourcesCollection') assert file_change_description_br == expected_output # print("-----") # print(file_change_description_br) + def test_br3(self): + file_change_description = 'Created a new class `ColorPaletteResourcesCollection` which extends `AvaloniaDictionary` and implements aaa' + file_change_description_br = insert_br_after_x_chars(file_change_description) + assert file_change_description_br == ('Created a new class ColorPaletteResourcesCollection which ' + 'extends
    AvaloniaDictionary' + ' and implements
    aaa') + # print("-----") + # print(file_change_description_br) From 3773303bfd43f410ce184eadfdc1b5a33bb625e4 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Tue, 6 Feb 2024 07:44:20 +0200 Subject: [PATCH 39/50] publish_output fix --- Usage.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Usage.md b/Usage.md index cf88f207..75504b13 100644 --- a/Usage.md +++ b/Usage.md @@ -100,7 +100,7 @@ python -m pr_agent.cli --pr_url= /review --pr_reviewer.extra_instructio (2) You can print results locally, without publishing them, by setting in `configuration.toml`: ``` [config] -publish_output=true +publish_output=false verbosity_level=2 ``` This is useful for debugging or experimenting with different tools. From b190b1879eaf51529599d8080ee0b3b517abe1ad Mon Sep 17 00:00:00 2001 From: mrT23 Date: Tue, 6 Feb 2024 08:31:36 +0200 Subject: [PATCH 40/50] auto approval --- README.md | 3 +++ docs/REVIEW.md | 29 ++++++++++++++++++++ pr_agent/agent/pr_agent.py | 8 ++++++ pr_agent/git_providers/git_provider.py | 6 ++++- pr_agent/git_providers/github_provider.py | 10 +++++++ pr_agent/servers/help.py | 26 ++++++++++++++++++ pr_agent/settings/configuration.toml | 4 +++ pr_agent/tools/pr_reviewer.py | 33 +++++++++++++++++++++++ 8 files changed, 118 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f64bb2f6..f01bcc3d 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,9 @@ Making pull requests less painful with an AI agent - [Why use PR-Agent?](#why-use-pr-agent) ## News and Updates +### Feb 6, 2024 +A new feature was added to the `review` tool - [Auto-approved PRs](./docs/REVIEW.md#auto-approved-prs). If enabled, this feature enables to automatically approve PRs that meet specific criteria, by commenting on a PR: `/review auto_approve`. + ### Feb 2, 2024 We are excited to introduce "PR Actions" 💎: diff --git a/docs/REVIEW.md b/docs/REVIEW.md index 5a35d8b9..e37b9c24 100644 --- a/docs/REVIEW.md +++ b/docs/REVIEW.md @@ -11,6 +11,7 @@ - [Automation](#automation) - [Auto-labels](#auto-labels) - [Extra instructions](#extra-instructions) + - [Auto-approval](#auto-approval) ## Overview The `review` tool scans the PR code changes, and automatically generates a PR review. @@ -50,6 +51,9 @@ This sub-tool checks if the PR description properly contains a ticket to a proje #### Adding PR labels - `enable_review_labels_security`: if set to true, the tool will publish a 'possible security issue' label if it detects a security issue. Default is true. - `enable_review_labels_effort`: if set to true, the tool will publish a 'Review effort [1-5]: x' label. Default is true. +#### Auto-approval +- `enable_auto_approval`: if set to true, the tool will approve the PR when invoked with the 'auto_approve' command. Default is false. This flag can be changed only from configuration file. +- `maximal_review_effort`: maximal effort level for auto-approval. If the PR's estimated review effort is above this threshold, the auto-approval will not run. Default is 5. ### Incremental Mode Incremental review only considers changes since the last PR-Agent review. This can be useful when working on the PR in an iterative manner, and you want to focus on the changes since the last review instead of reviewing the entire PR again. @@ -97,6 +101,7 @@ ___ 3) [Automation](#automation) 4) [Auto-labels](#auto-labels) 5) [Extra instructions](#extra-instructions) +6) [Auto-approval](#auto-approval) ### General guidelines The `review` tool provides a collection of possible feedbacks about a PR. @@ -146,3 +151,27 @@ In the code feedback section, emphasize the following: ``` Use triple quotes to write multi-line instructions. Use bullet points to make the instructions more readable. + +### Auto-approval +PR-Agent can approve a PR when a specific comment is invoked, given that this ability was enabled in the configuration file. + +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) + + +After enabling, by invoking: +``` +/review auto_approve +``` +The tool will automatically approve the PR, and add a comment with the approval. + + +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 +``` diff --git a/pr_agent/agent/pr_agent.py b/pr_agent/agent/pr_agent.py index 3eb26841..770317fb 100644 --- a/pr_agent/agent/pr_agent.py +++ b/pr_agent/agent/pr_agent.py @@ -45,6 +45,7 @@ commands = list(command2class.keys()) class PRAgent: def __init__(self, ai_handler: partial[BaseAiHandler,] = LiteLLMAIHandler): self.ai_handler = ai_handler # will be initialized in run_action + self.forbidden_cli_args = ['enable_auto_approval'] async def handle_request(self, pr_url, request, notify=None) -> bool: # First, apply repo specific settings if exists @@ -58,6 +59,13 @@ class PRAgent: action, *args = list(lexer) else: action, *args = request + + if args: + for forbidden_arg in self.forbidden_cli_args: + for arg in args: + if forbidden_arg in arg: + get_logger().error(f"CLI argument '{forbidden_arg}' is forbidden") + return False args = update_settings_from_args(args) action = action.lstrip("/").lower() diff --git a/pr_agent/git_providers/git_provider.py b/pr_agent/git_providers/git_provider.py index ae2109b5..a3237dac 100644 --- a/pr_agent/git_providers/git_provider.py +++ b/pr_agent/git_providers/git_provider.py @@ -171,6 +171,11 @@ class GitProvider(ABC): def get_latest_commit_url(self) -> str: return "" + def auto_approve(self) -> bool: + return False + + + def get_main_pr_language(languages, files) -> str: """ Get the main language of the commit. Return an empty string if cannot determine. @@ -239,7 +244,6 @@ def get_main_pr_language(languages, files) -> str: return main_language_str - class IncrementalPR: def __init__(self, is_incremental: bool = False): self.is_incremental = is_incremental diff --git a/pr_agent/git_providers/github_provider.py b/pr_agent/git_providers/github_provider.py index 9b89973d..8dd8a87f 100644 --- a/pr_agent/git_providers/github_provider.py +++ b/pr_agent/git_providers/github_provider.py @@ -643,3 +643,13 @@ class GithubProvider(GitProvider): return pr_id except: return "" + + def auto_approve(self) -> bool: + try: + res = self.pr.create_review(event="APPROVE") + if res.state == "APPROVED": + return True + return False + except Exception as e: + get_logger().exception(f"Failed to auto-approve, error: {e}") + return False \ No newline at end of file diff --git a/pr_agent/servers/help.py b/pr_agent/servers/help.py index 1d48be59..36bd0db5 100644 --- a/pr_agent/servers/help.py +++ b/pr_agent/servers/help.py @@ -99,6 +99,31 @@ Some of the feature that are disabled by default are quite useful, and should be """ output += "\n\n\n\n" + output += "
  • \n\n" + # general output += "\n\n
    {header}
    {diff_plus_minus}{delta_nbsp}
    {diff_plus_minus}{delta_nbsp}
    Auto-approve PRs
    \n\n" + output += '''\ +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 +``` +''' + output += "\n\n
    More PR-Agent commands
    \n\n" output += HelpMessage.get_general_bot_help_text() @@ -186,6 +211,7 @@ To enable inline file summary, set `pr_description.inline_file_summary` in the c - `true`: A collapsable file comment with changes title and a changes summary for each file in the PR. - `false` (default): File changes walkthrough will be added only to the "Conversation" tab. """ + # extra instructions output += "
    Utilizing extra instructions
    \n\n" output += '''\ diff --git a/pr_agent/settings/configuration.toml b/pr_agent/settings/configuration.toml index 7ab2f8cb..eea41a7f 100644 --- a/pr_agent/settings/configuration.toml +++ b/pr_agent/settings/configuration.toml @@ -43,6 +43,10 @@ require_all_thresholds_for_incremental_review=false minimal_commits_for_incremental_review=0 minimal_minutes_for_incremental_review=0 enable_help_text=true # Determines whether to include help text in the PR review. Enabled by default. +# auto approval +enable_auto_approval=false +maximal_review_effort=5 + [pr_description] # /describe # publish_labels=true diff --git a/pr_agent/tools/pr_reviewer.py b/pr_agent/tools/pr_reviewer.py index 31cc1c43..e714b194 100644 --- a/pr_agent/tools/pr_reviewer.py +++ b/pr_agent/tools/pr_reviewer.py @@ -36,6 +36,7 @@ class PRReviewer: ai_handler (BaseAiHandler): The AI handler to be used for the review. Defaults to None. args (list, optional): List of arguments passed to the PRReviewer class. Defaults to None. """ + self.args = args self.parse_args(args) # -i command self.git_provider = get_git_provider()(pr_url, incremental=self.incremental) @@ -102,6 +103,11 @@ class PRReviewer: if self.incremental.is_incremental and not self._can_run_incremental_review(): return None + if isinstance(self.args, list) and self.args and self.args[0] == 'auto_approve': + get_logger().info(f'Auto approve flow PR: {self.pr_url} ...') + self.auto_approve_logic() + return None + get_logger().info(f'Reviewing PR: {self.pr_url} ...') if get_settings().config.publish_output: @@ -392,3 +398,30 @@ class PRReviewer: self.git_provider.publish_labels(review_labels + current_labels_filtered) except Exception as e: get_logger().error(f"Failed to set review labels, error: {e}") + + def auto_approve_logic(self): + """ + Auto-approve a pull request if it meets the conditions for auto-approval. + """ + if get_settings().pr_reviewer.enable_auto_approval: + maximal_review_effort = get_settings().pr_reviewer.maximal_review_effort + if maximal_review_effort < 5: + current_labels = self.git_provider.get_pr_labels() + for label in current_labels: + if label.lower().startswith('review effort [1-5]:'): + effort = int(label.split(':')[1].strip()) + if effort > maximal_review_effort: + get_logger().info( + f"Auto-approve error: PR review effort ({effort}) is higher than the maximal review effort " + f"({maximal_review_effort}) allowed") + self.git_provider.publish_comment( + f"Auto-approve error: PR review effort ({effort}) is higher than the maximal review effort " + f"({maximal_review_effort}) allowed") + return + is_auto_approved = self.git_provider.auto_approve() + if is_auto_approved: + get_logger().info("Auto-approved PR") + self.git_provider.publish_comment("Auto-approved PR") + else: + get_logger().info("Auto-approval option is disabled") + self.git_provider.publish_comment("Auto-approval option for PR-Agent is disabled") \ No newline at end of file From 8a04a4f481f2f87a52240ed4ed2ad23019027cd0 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Tue, 6 Feb 2024 09:12:52 +0200 Subject: [PATCH 41/50] auto approval --- README.md | 2 +- docs/REVIEW.md | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index f01bcc3d..3c592dd1 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ Making pull requests less painful with an AI agent ## News and Updates ### Feb 6, 2024 -A new feature was added to the `review` tool - [Auto-approved PRs](./docs/REVIEW.md#auto-approved-prs). If enabled, this feature enables to automatically approve PRs that meet specific criteria, by commenting on a PR: `/review auto_approve`. +A new feature was added to the `review` tool - [Auto-approve PRs](./docs/REVIEW.md#auto-approval-1). If enabled, this feature enables to automatically approve PRs that meet specific criteria, by commenting on a PR: `/review auto_approve`. ### Feb 2, 2024 We are excited to introduce "PR Actions" 💎: diff --git a/docs/REVIEW.md b/docs/REVIEW.md index e37b9c24..0c22f280 100644 --- a/docs/REVIEW.md +++ b/docs/REVIEW.md @@ -11,7 +11,7 @@ - [Automation](#automation) - [Auto-labels](#auto-labels) - [Extra instructions](#extra-instructions) - - [Auto-approval](#auto-approval) + - [Auto-approval](#auto-approval-1) ## Overview The `review` tool scans the PR code changes, and automatically generates a PR review. @@ -153,7 +153,7 @@ Use triple quotes to write multi-line instructions. Use bullet points to make th ### Auto-approval -PR-Agent can approve a PR when a specific comment is invoked, given that this ability was enabled in the configuration file. +PR-Agent can approve a PR when a specific comment is invoked. 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: ``` @@ -170,7 +170,7 @@ After enabling, by invoking: The tool will automatically approve the PR, and add a comment with the approval. -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: +You can also enable auto-approval only if the PR meets certain requirements, such as that the `estimated_review_effort` label is equal or below a certain threshold, by adjusting the flag: ``` [pr_reviewer] maximal_review_effort = 5 From 1c9bd3e9a85700b10b8b9c1e3c910c465f4b1292 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Tue, 6 Feb 2024 09:26:00 +0200 Subject: [PATCH 42/50] get_pr_url --- pr_agent/tools/pr_description.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pr_agent/tools/pr_description.py b/pr_agent/tools/pr_description.py index 46fdc1b2..135b850b 100644 --- a/pr_agent/tools/pr_description.py +++ b/pr_agent/tools/pr_description.py @@ -133,7 +133,7 @@ class PRDescription: latest_commit_url = self.git_provider.get_latest_commit_url() if latest_commit_url: self.git_provider.publish_comment( - f"**[PR Description]({self.git_provider.pr_url})** updated to latest commit ({latest_commit_url})") + f"**[PR Description]({self.git_provider.get_pr_url()})** updated to latest commit ({latest_commit_url})") self.git_provider.remove_initial_comment() except Exception as e: get_logger().error(f"Error generating PR description {self.pr_id}: {e}") From 2bc398f74e1f8eea080461b72c4ae853b6cba148 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Tue, 6 Feb 2024 16:48:29 +0200 Subject: [PATCH 43/50] readme --- docs/REVIEW.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/REVIEW.md b/docs/REVIEW.md index 0c22f280..19c4880b 100644 --- a/docs/REVIEW.md +++ b/docs/REVIEW.md @@ -163,11 +163,11 @@ enable_auto_approval = true (this specific flag cannot be set with a command line argument, only in the configuration file, committed to the repository) -After enabling, by invoking: +After enabling, by commenting on a PR: ``` /review auto_approve ``` -The tool will automatically approve the PR, and add a comment with the approval. +PR-Agent will automatically approve the PR, and add a comment with the approval. You can also enable auto-approval only if the PR meets certain requirements, such as that the `estimated_review_effort` label is equal or below a certain threshold, by adjusting the flag: From 034c654bacda4367c3fd458771476d01ee9ddacf Mon Sep 17 00:00:00 2001 From: Tal Date: Tue, 6 Feb 2024 17:47:14 +0200 Subject: [PATCH 44/50] Update .pr_agent.toml --- .pr_agent.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/.pr_agent.toml b/.pr_agent.toml index 7fc8ea8a..29c5489a 100644 --- a/.pr_agent.toml +++ b/.pr_agent.toml @@ -1,5 +1,6 @@ [pr_reviewer] enable_review_labels_effort = true +enable_auto_approval = true [pr_code_suggestions] From 91e77787c0716a55a0b4590d3b89ddcd5f6f8054 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Tue, 6 Feb 2024 17:46:04 +0200 Subject: [PATCH 45/50] readme cleaning --- INSTALL.md | 14 -------------- README.md | 24 +++++++++++++----------- 2 files changed, 13 insertions(+), 25 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index d06b744d..2deed774 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -14,7 +14,6 @@ There are several ways to use PR-Agent: **GitHub specific methods** - [Run as a GitHub Action](INSTALL.md#run-as-a-github-action) -- [Run as a polling server](INSTALL.md#run-as-a-polling-server) - [Run as a GitHub App](INSTALL.md#run-as-a-github-app) - [Deploy as a Lambda Function](INSTALL.md#deploy-as-a-lambda-function) - [AWS CodeCommit](INSTALL.md#aws-codecommit-setup) @@ -186,19 +185,6 @@ When you open your next PR, you should see a comment from `github-actions` bot w --- -### Run as a polling server -Request reviews by tagging your GitHub user on a PR - -Follow [steps 1-3](#run-as-a-github-action) of the GitHub Action setup. - -Run the following command to start the server: - -``` -python pr_agent/servers/github_polling.py -``` - ---- - ### Run as a GitHub App Allowing you to automate the review process on your private or public repositories. diff --git a/README.md b/README.md index 3c592dd1..642006e1 100644 --- a/README.md +++ b/README.md @@ -217,17 +217,19 @@ To use your own version of PR-Agent, you first need to acquire two tokens: There are several ways to use PR-Agent: -- [Method 1: Use Docker image (no installation required)](INSTALL.md#method-1-use-docker-image-no-installation-required) -- [Method 2: Run from source](INSTALL.md#method-2-run-from-source) -- [Method 3: Run as a GitHub Action](INSTALL.md#method-3-run-as-a-github-action) -- [Method 4: Run as a polling server](INSTALL.md#method-4-run-as-a-polling-server) - - Request reviews by tagging your GitHub user on a PR -- [Method 5: Run as a GitHub App](INSTALL.md#method-5-run-as-a-github-app) - - Allowing you to automate the review process on your private or public repositories -- [Method 6: Deploy as a Lambda Function](INSTALL.md#method-6---deploy-as-a-lambda-function) -- [Method 7: AWS CodeCommit](INSTALL.md#method-7---aws-codecommit-setup) -- [Method 8: Run a GitLab webhook server](INSTALL.md#method-8---run-a-gitlab-webhook-server) -- [Method 9: Run as a Bitbucket Pipeline](INSTALL.md#method-9-run-as-a-bitbucket-pipeline) +**Locally** +- [Use Docker image (no installation required)](./INSTALL.md#use-docker-image-no-installation-required) +- [Run from source](./INSTALL.md#run-from-source) + +**GitHub specific methods** +- [Run as a GitHub Action](./INSTALL.md#run-as-a-github-action) +- [Run as a GitHub App](./INSTALL.md#run-as-a-github-app) + +**GitLab specific methods** +- [Run a GitLab webhook server](./INSTALL.md#run-a-gitlab-webhook-server) + +**BitBucket specific methods** +- [Run as a Bitbucket Pipeline](./INSTALL.md#run-as-a-bitbucket-pipeline) ## PR-Agent Pro 💎 [PR-Agent Pro](https://www.codium.ai/pricing/) is a hosted version of PR-Agent, provided by CodiumAI. It is available for a monthly fee, and provides the following benefits: From 5d81f31ccc407f8a6bd6a56956833b612a63cf91 Mon Sep 17 00:00:00 2001 From: Hussam Lawen Date: Tue, 6 Feb 2024 21:18:56 +0200 Subject: [PATCH 46/50] Update DESCRIBE.md --- docs/DESCRIBE.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/docs/DESCRIBE.md b/docs/DESCRIBE.md index 00526a87..526b31a3 100644 --- a/docs/DESCRIBE.md +++ b/docs/DESCRIBE.md @@ -52,8 +52,12 @@ To edit [configurations](./../pr_agent/settings/configuration.toml#L46) related ### Inline file summary 💎 > This feature is available only in PR-Agent Pro -This will enable you to quickly understand the changes in each file, while reviewing the code changes (diff view). -To enable inline file summary, set `pr_description.inline_file_summary` in the configuration file, possible values are: +This will enable you to quickly understand the changes in each file while reviewing the code changes (diff view). + +To add the walkthrough table to the "Files changed" tab, you can click on the checkbox that appears PR Description status message below the main PR Description: + + +If you prefer to have the file summaries appear in the "Files changed" tab on every PR, change the `pr_description.inline_file_summary` parameter in the configuration file, possible values are: - `'table'`: File changes walkthrough table will be displayed on the top of the "Files changed" tab, in addition to the "Conversation" tab. - `true`: A collapsable file comment with changes title and a changes summary for each file in the PR. From 9a26ed7c43a8308a7c6bc9fccdc0f61c8a36e831 Mon Sep 17 00:00:00 2001 From: Hussam Lawen Date: Tue, 6 Feb 2024 21:19:47 +0200 Subject: [PATCH 47/50] Update DESCRIBE.md --- docs/DESCRIBE.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/DESCRIBE.md b/docs/DESCRIBE.md index 526b31a3..e321df18 100644 --- a/docs/DESCRIBE.md +++ b/docs/DESCRIBE.md @@ -55,6 +55,7 @@ To edit [configurations](./../pr_agent/settings/configuration.toml#L46) related This will enable you to quickly understand the changes in each file while reviewing the code changes (diff view). To add the walkthrough table to the "Files changed" tab, you can click on the checkbox that appears PR Description status message below the main PR Description: + If you prefer to have the file summaries appear in the "Files changed" tab on every PR, change the `pr_description.inline_file_summary` parameter in the configuration file, possible values are: From ea3a34be0808ada29892ab11d6275357033c2bad Mon Sep 17 00:00:00 2001 From: Tal Date: Wed, 7 Feb 2024 07:31:21 +0200 Subject: [PATCH 48/50] Update DESCRIBE.md --- docs/DESCRIBE.md | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/docs/DESCRIBE.md b/docs/DESCRIBE.md index e321df18..a17d371b 100644 --- a/docs/DESCRIBE.md +++ b/docs/DESCRIBE.md @@ -52,20 +52,23 @@ To edit [configurations](./../pr_agent/settings/configuration.toml#L46) related ### Inline file summary 💎 > This feature is available only in PR-Agent Pro -This will enable you to quickly understand the changes in each file while reviewing the code changes (diff view). +This feature will enable you to quickly understand the changes in each file while reviewing the code changes (diff view). To add the walkthrough table to the "Files changed" tab, you can click on the checkbox that appears PR Description status message below the main PR Description: If you prefer to have the file summaries appear in the "Files changed" tab on every PR, change the `pr_description.inline_file_summary` parameter in the configuration file, possible values are: + - `'table'`: File changes walkthrough table will be displayed on the top of the "Files changed" tab, in addition to the "Conversation" tab. - + + - `true`: A collapsable file comment with changes title and a changes summary for each file in the PR. - + + - `false` (`default`): File changes walkthrough will be added only to the "Conversation" tab. -*Note that this feature is currently available only for GitHub. +Note that this feature is currently available only for GitHub. ### Handle custom labels from the Repo's labels page :gem: @@ -86,7 +89,7 @@ The description should be comprehensive and detailed, indicating when to add the ### Markers template To enable markers, set `pr_description.use_description_markers=true`. -markers enable to easily integrate user's content and auto-generated content, with a template-like mechanism. +Markers enable to easily integrate user's content and auto-generated content, with a template-like mechanism. For example, if the PR original description was: ``` From a7ce2b11b42a34ca96f8851ccdbe27a34b012b75 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Wed, 7 Feb 2024 08:00:01 +0200 Subject: [PATCH 49/50] parallel_calls --- pr_agent/settings/configuration.toml | 3 ++- pr_agent/tools/pr_code_suggestions.py | 29 ++++++++++++++++----------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/pr_agent/settings/configuration.toml b/pr_agent/settings/configuration.toml index eea41a7f..7555c292 100644 --- a/pr_agent/settings/configuration.toml +++ b/pr_agent/settings/configuration.toml @@ -82,8 +82,9 @@ enable_help_text=true # params for '/improve --extended' mode auto_extended_mode=true num_code_suggestions_per_chunk=5 -rank_extended_suggestions = false max_number_of_calls = 3 +parallel_calls = true +rank_extended_suggestions = false final_clip_factor = 0.8 [pr_add_docs] # /add_docs # diff --git a/pr_agent/tools/pr_code_suggestions.py b/pr_agent/tools/pr_code_suggestions.py index 5fc45619..de922730 100644 --- a/pr_agent/tools/pr_code_suggestions.py +++ b/pr_agent/tools/pr_code_suggestions.py @@ -1,3 +1,4 @@ +import asyncio import copy import textwrap from functools import partial @@ -111,18 +112,18 @@ class PRCodeSuggestions: async def _prepare_prediction(self, model: str): get_logger().info('Getting PR diff...') - self.patches_diff = get_pr_diff(self.git_provider, + patches_diff = get_pr_diff(self.git_provider, self.token_handler, model, add_line_numbers_to_hunks=True, disable_extra_lines=True) get_logger().info('Getting AI prediction...') - self.prediction = await self._get_prediction(model) + self.prediction = await self._get_prediction(model, patches_diff) - async def _get_prediction(self, model: str): + async def _get_prediction(self, model: str, patches_diff: str): variables = copy.deepcopy(self.vars) - variables["diff"] = self.patches_diff # update diff + variables["diff"] = patches_diff # update diff environment = Environment(undefined=StrictUndefined) system_prompt = environment.from_string(get_settings().pr_code_suggestions_prompt.system).render(variables) user_prompt = environment.from_string(get_settings().pr_code_suggestions_prompt.user).render(variables) @@ -229,14 +230,18 @@ class PRCodeSuggestions: patches_diff_list = get_pr_multi_diffs(self.git_provider, self.token_handler, model, max_calls=get_settings().pr_code_suggestions.max_number_of_calls) - get_logger().info('Getting multi AI predictions...') - prediction_list = [] - for i, patches_diff in enumerate(patches_diff_list): - get_logger().info(f"Processing chunk {i + 1} of {len(patches_diff_list)}") - self.patches_diff = patches_diff - prediction = await self._get_prediction(model) # toDo: parallelize - prediction_list.append(prediction) - self.prediction_list = prediction_list + # parallelize calls to AI: + if get_settings().pr_code_suggestions.parallel_calls: + get_logger().info('Getting multi AI predictions in parallel...') + prediction_list = await asyncio.gather(*[self._get_prediction(model, patches_diff) for patches_diff in patches_diff_list]) + self.prediction_list = prediction_list + else: + get_logger().info('Getting multi AI predictions...') + prediction_list = [] + for i, patches_diff in enumerate(patches_diff_list): + get_logger().info(f"Processing chunk {i + 1} of {len(patches_diff_list)}") + prediction = await self._get_prediction(model, patches_diff) # toDo: parallelize + prediction_list.append(prediction) data = {} for prediction in prediction_list: From b077873c3d7e54d68c6686c7e8399db9266a6f22 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Wed, 7 Feb 2024 08:00:16 +0200 Subject: [PATCH 50/50] parallel_calls --- pr_agent/tools/pr_code_suggestions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pr_agent/tools/pr_code_suggestions.py b/pr_agent/tools/pr_code_suggestions.py index de922730..b944047e 100644 --- a/pr_agent/tools/pr_code_suggestions.py +++ b/pr_agent/tools/pr_code_suggestions.py @@ -240,7 +240,7 @@ class PRCodeSuggestions: prediction_list = [] for i, patches_diff in enumerate(patches_diff_list): get_logger().info(f"Processing chunk {i + 1} of {len(patches_diff_list)}") - prediction = await self._get_prediction(model, patches_diff) # toDo: parallelize + prediction = await self._get_prediction(model, patches_diff) prediction_list.append(prediction) data = {}