From 06d00032df3e58adbe831ae0f535587d57e3f567 Mon Sep 17 00:00:00 2001 From: szecsip Date: Thu, 31 Aug 2023 11:47:51 +0000 Subject: [PATCH 01/22] update docs for Azure DevOps --- CONFIGURATION.md | 18 ++++++++++++++++++ README.md | 44 ++++++++++++++++++++++---------------------- 2 files changed, 40 insertions(+), 22 deletions(-) diff --git a/CONFIGURATION.md b/CONFIGURATION.md index 66ec4f06..f9d3d010 100644 --- a/CONFIGURATION.md +++ b/CONFIGURATION.md @@ -73,8 +73,26 @@ key = ... Also review the [AiHandler](pr_agent/algo/ai_handler.py) file for instruction how to set keys for other models. +#### Changing a GIT provider +See [here](pr_agent/git_providers/__init__.py) for the list of GIT providers. + +To use GitHub, for example, set: +``` +[config] +git_provider="github" +``` + #### Extra instructions +##### General All PR-Agent tools have a parameter called `extra_instructions`, that enables to add free-text extra instructions. Example usage: ``` /update_changelog --pr_update_changelog.extra_instructions="Make sure to update also the version ..." +``` + +##### Azure DevOps provider +To use Azure DevOps provider set: +``` +[config] +git_provider="azure" +use_repo_settings_file=false ``` \ No newline at end of file diff --git a/README.md b/README.md index 095d2c04..85705c6c 100644 --- a/README.md +++ b/README.md @@ -75,27 +75,27 @@ CodiumAI `PR-Agent` is an open-source tool aiming to help developers review pull ## Overview `PR-Agent` offers extensive pull request functionalities across various git providers: -| | | GitHub | Gitlab | Bitbucket | CodeCommit | -|-------|---------------------------------------------|:------:|:------:|:---------:|:----------:| -| TOOLS | Review | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | -| | ⮑ Inline review | :white_check_mark: | :white_check_mark: | | | -| | Ask | :white_check_mark: | :white_check_mark: | :white_check_mark: | -| | Auto-Description | :white_check_mark: | :white_check_mark: | | :white_check_mark: | -| | Improve Code | :white_check_mark: | :white_check_mark: | | | -| | ⮑ Extended | :white_check_mark: | :white_check_mark: | | | -| | Reflect and Review | :white_check_mark: | | | | -| | Update CHANGELOG.md | :white_check_mark: | | | | -| | | | | | | -| USAGE | CLI | :white_check_mark: | :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: | | -| | Incremental PR Review | :white_check_mark: | | | | +| | | GitHub | Gitlab | Bitbucket | CodeCommit | Azure DevOps | +|-------|---------------------------------------------|:------:|:------:|:---------:|:----------:|:----------:| +| TOOLS | Review | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | ⮑ Inline review | :white_check_mark: | :white_check_mark: | | | | +| | Ask | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: +| | Auto-Description | :white_check_mark: | :white_check_mark: | | :white_check_mark: | :white_check_mark: | +| | Improve Code | :white_check_mark: | :white_check_mark: | | | | +| | ⮑ Extended | :white_check_mark: | :white_check_mark: | | | | +| | Reflect and Review | :white_check_mark: | | | | :white_check_mark: | +| | Update CHANGELOG.md | :white_check_mark: | | | | | +| | | | | | | | +| USAGE | CLI | :white_check_mark: | :white_check_mark: | :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: | | :white_check_mark: | +| | Repo language prioritization | :white_check_mark: | :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: | | :white_check_mark: | +| | Multiple models support | :white_check_mark: | :white_check_mark: | :white_check_mark: | | :white_check_mark: | +| | Incremental PR Review | :white_check_mark: | | | | | Examples for invoking the different tools via the CLI: - **Review**: python cli.py --pr_url= review @@ -184,4 +184,4 @@ Here are some advantages of PR-Agent: - [Aider - GPT powered coding in your terminal](https://github.com/paul-gauthier/aider) - [openai-pr-reviewer](https://github.com/coderabbitai/openai-pr-reviewer) - [CodeReview BOT](https://github.com/anc95/ChatGPT-CodeReview) -- [AI-Maintainer](https://github.com/merwanehamadi/AI-Maintainer) +- [AI-Maintainer](https://github.com/merwanehamadi/AI-Maintainer) \ No newline at end of file From 24900305d6f6e0042cc9ceb10964bca8cc47d779 Mon Sep 17 00:00:00 2001 From: szecsip Date: Thu, 31 Aug 2023 11:50:41 +0000 Subject: [PATCH 02/22] update docs for Azure DevOps --- CONFIGURATION.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/CONFIGURATION.md b/CONFIGURATION.md index f9d3d010..cedd8514 100644 --- a/CONFIGURATION.md +++ b/CONFIGURATION.md @@ -90,9 +90,16 @@ All PR-Agent tools have a parameter called `extra_instructions`, that enables to ``` ##### Azure DevOps provider -To use Azure DevOps provider set: +To use Azure DevOps provider use the following settings in configuration.toml: ``` [config] git_provider="azure" use_repo_settings_file=false +``` + +And use the following settings (you have to replace the values) in .secrets.toml: +``` +[azure_devops] +org = "https://dev.azure.com/YOUR_ORGANIZATION/" +pat = "YOUR_PAT_TOKEN" ``` \ No newline at end of file From be19b64542995deb7a6fbe4c0eabf07b7908aa18 Mon Sep 17 00:00:00 2001 From: szecsip Date: Thu, 31 Aug 2023 11:53:54 +0000 Subject: [PATCH 03/22] add dependencies for Azure DevOps provider --- requirements.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/requirements.txt b/requirements.txt index 2441b1c1..99efa846 100644 --- a/requirements.txt +++ b/requirements.txt @@ -17,3 +17,5 @@ litellm~=0.1.504 boto3~=1.28.25 google-cloud-storage==2.10.0 ujson==5.8.0 +azure-devops==7.1.0b3 +msrest==0.7.1 \ No newline at end of file From f7c698ff54aecafc8e639bfe051ccfa44b17f063 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Fri, 1 Sep 2023 19:40:38 +0300 Subject: [PATCH 04/22] update --- README.md | 81 ++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 51 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index 85705c6c..c236c8fa 100644 --- a/README.md +++ b/README.md @@ -35,33 +35,55 @@ CodiumAI `PR-Agent` is an open-source tool aiming to help developers review pull

-

/review:

-
-

- -

-
-

/reflect_and_review:

-
-

- -

-
-

/ask:

-
-

- -

-
-

/improve:

-
-

- -

-
+ +[//]: # (

/review:

) +[//]: # (
) + +[//]: # (

) + +[//]: # () + +[//]: # (

) + +[//]: # (
) +[//]: # (

/reflect_and_review:

) + +[//]: # (
) + +[//]: # (

) + +[//]: # () + +[//]: # (

) + +[//]: # (
) + +[//]: # (

/ask:

) + +[//]: # (
) + +[//]: # (

) + +[//]: # () + +[//]: # (

) + +[//]: # (
) + +[//]: # (

/improve:

) + +[//]: # (
) + +[//]: # (

) + +[//]: # () + +[//]: # (

) + +[//]: # (
)
- +## Table of Contents - [Overview](#overview) - [Try it now](#try-it-now) - [Installation](#installation) @@ -78,7 +100,6 @@ CodiumAI `PR-Agent` is an open-source tool aiming to help developers review pull | | | GitHub | Gitlab | Bitbucket | CodeCommit | Azure DevOps | |-------|---------------------------------------------|:------:|:------:|:---------:|:----------:|:----------:| | TOOLS | Review | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | -| | ⮑ Inline review | :white_check_mark: | :white_check_mark: | | | | | | Ask | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | | Auto-Description | :white_check_mark: | :white_check_mark: | | :white_check_mark: | :white_check_mark: | | | Improve Code | :white_check_mark: | :white_check_mark: | | | | @@ -91,10 +112,10 @@ CodiumAI `PR-Agent` is an open-source tool aiming to help developers review pull | | Tagging bot | :white_check_mark: | | | | | | | Actions | :white_check_mark: | | | | | | | | | | | | | -| CORE | PR compression | :white_check_mark: | :white_check_mark: | :white_check_mark: | | :white_check_mark: | -| | Repo language prioritization | :white_check_mark: | :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: | | :white_check_mark: | -| | Multiple models support | :white_check_mark: | :white_check_mark: | :white_check_mark: | | :white_check_mark: | +| CORE | PR compression | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | Repo language prioritization | :white_check_mark: | :white_check_mark: | :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: | :white_check_mark: | :white_check_mark: | +| | Multiple models support | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | | | Incremental PR Review | :white_check_mark: | | | | | Examples for invoking the different tools via the CLI: From 777c773a9098f9c18ac35bb9373abd727873a235 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Fri, 1 Sep 2023 19:50:10 +0300 Subject: [PATCH 05/22] update --- CONFIGURATION.md | 23 +++++++++++++++++++---- README.md | 22 +++++++--------------- 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/CONFIGURATION.md b/CONFIGURATION.md index 320ddedf..162a51d3 100644 --- a/CONFIGURATION.md +++ b/CONFIGURATION.md @@ -2,18 +2,33 @@ The different tools and sub-tools used by CodiumAI PR-Agent are adjustable via the **[configuration file](pr_agent/settings/configuration.toml)** +Options that are available in the configuration file can be specified at run time when calling actions. Two examples: +``` +- /review --pr_reviewer.extra_instructions="focus on the file: ..." +- /describe --pr_description.add_original_user_description=false -pr_description.extra_instructions="make sure to mention: ..." +``` + ### Working from CLI When running from source (CLI), your local configuration file will be initially used. -Example for invoking the 'review' tools via the CLI: +Examples for invoking the different tools via the CLI: ``` -python cli.py --pr-url= review +- **Review**: python cli.py --pr_url= review +- **Describe**: python cli.py --pr_url= describe +- **Improve**: python cli.py --pr_url= improve +- **Ask**: python cli.py --pr_url= ask "Write me a poem about this PR" +- **Reflect**: python cli.py --pr_url= reflect +- **Update Changelog**: python cli.py --pr_url= update_changelog ``` -In addition to general configurations, the 'review' tool will use parameters from the `[pr_reviewer]` section (every tool has a dedicated section in the configuration file). -Note that you can print results locally, without publishing them, by setting in `configuration.toml`: +"" is the url of the relevant PR (for example: https://github.com/Codium-ai/pr-agent/pull/50). +Notes: + +(1) In addition to general configurations, each tool has its own configurations. For example, the 'review' tool will use parameters from the `[pr_reviewer]` section. + +(2) You can print results locally, without publishing them, by setting in `configuration.toml`: ``` [config] publish_output=true diff --git a/README.md b/README.md index c236c8fa..cbf13970 100644 --- a/README.md +++ b/README.md @@ -118,29 +118,21 @@ CodiumAI `PR-Agent` is an open-source tool aiming to help developers review pull | | Multiple models support | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | | | Incremental PR Review | :white_check_mark: | | | | | -Examples for invoking the different tools via the CLI: -- **Review**: python cli.py --pr_url= review -- **Describe**: python cli.py --pr_url= describe -- **Improve**: python cli.py --pr_url= improve -- **Ask**: python cli.py --pr_url= ask "Write me a poem about this PR" -- **Reflect**: python cli.py --pr_url= reflect -- **Update Changelog**: python cli.py --pr_url= update_changelog - -"" is the url of the relevant PR (for example: https://github.com/Codium-ai/pr-agent/pull/50). - -In the [configuration](./CONFIGURATION.md) file you can select your git provider (GitHub, Gitlab, Bitbucket), and further configure the different tools. -Options that are available in the configuration file can be specified at run time when calling actions. Two examples: -- /review --pr_reviewer.extra_instructions="focus on the file: ..." -- /describe --pr_description.add_original_user_description=false -pr_description.extra_instructions="make sure to mention: ..." +Review the [configuration](./CONFIGURATION.md) section for instruction how to use the different tools, select the relevant git provider (GitHub, Gitlab, Bitbucket,...), and adjust the configuration file to your needs. ## Try it now Try GPT-4 powered PR-Agent on your public GitHub repository for free. Just mention `@CodiumAI-Agent` and add the desired command in any PR comment! The agent will generate a response based on your command. +For example, add a comment: +``` +@CodiumAI-Agent /review +``` +And the agent will respond with a review of your PR ![Review generation process](https://www.codium.ai/images/demo-2.gif) -To set up your own PR-Agent, see the [Installation](#installation) section +To set up your own PR-Agent, see the [Installation](#installation) section below. --- ## Installation From 7a6efbcb5590e21519bb76dc25697744a31791bf Mon Sep 17 00:00:00 2001 From: mrT23 Date: Fri, 1 Sep 2023 19:56:20 +0300 Subject: [PATCH 06/22] update --- CONFIGURATION.md | 11 +++++++---- README.md | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/CONFIGURATION.md b/CONFIGURATION.md index 162a51d3..82326a27 100644 --- a/CONFIGURATION.md +++ b/CONFIGURATION.md @@ -2,6 +2,11 @@ The different tools and sub-tools used by CodiumAI PR-Agent are adjustable via the **[configuration file](pr_agent/settings/configuration.toml)** +The `git_provider` field in the configuration file determines the GIT provider that will be used by PR-Agent. Currently, the following providers are supported: +` +"github", "gitlab", "azure", "codecommit","local" +` + Options that are available in the configuration file can be specified at run time when calling actions. Two examples: ``` - /review --pr_reviewer.extra_instructions="focus on the file: ..." @@ -13,20 +18,18 @@ When running from source (CLI), your local configuration file will be initially Examples for invoking the different tools via the CLI: -``` - **Review**: python cli.py --pr_url= review - **Describe**: python cli.py --pr_url= describe - **Improve**: python cli.py --pr_url= improve - **Ask**: python cli.py --pr_url= ask "Write me a poem about this PR" - **Reflect**: python cli.py --pr_url= reflect - **Update Changelog**: python cli.py --pr_url= update_changelog -``` -"" is the url of the relevant PR (for example: https://github.com/Codium-ai/pr-agent/pull/50). +`` is the url of the relevant PR (for example: https://github.com/Codium-ai/pr-agent/pull/50). Notes: -(1) In addition to general configurations, each tool has its own configurations. For example, the 'review' tool will use parameters from the `[pr_reviewer]` section. +(1) In addition to general configurations, each tool has its own configurations. For example, the 'review' tool will use parameters from the `[pr_reviewer]` section in the [configuration file](pr_agent/settings/configuration.toml) (2) You can print results locally, without publishing them, by setting in `configuration.toml`: ``` diff --git a/README.md b/README.md index cbf13970..71278a03 100644 --- a/README.md +++ b/README.md @@ -91,7 +91,6 @@ CodiumAI `PR-Agent` is an open-source tool aiming to help developers review pull - [How it works](#how-it-works) - [Why use PR-Agent](#why-use-pr-agent) - [Roadmap](#roadmap) -- [Similar projects](#similar-projects)
@@ -133,6 +132,7 @@ And the agent will respond with a review of your PR To set up your own PR-Agent, see the [Installation](#installation) section below. + --- ## Installation From 7f6493009cbc4393176da98cd61faa0c914c2f11 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Fri, 1 Sep 2023 20:05:33 +0300 Subject: [PATCH 07/22] update --- CONFIGURATION.md | 21 ++++++--------------- README.md | 6 +++--- 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/CONFIGURATION.md b/CONFIGURATION.md index 82326a27..10a18aa7 100644 --- a/CONFIGURATION.md +++ b/CONFIGURATION.md @@ -14,7 +14,7 @@ Options that are available in the configuration file can be specified at run tim ``` ### Working from CLI -When running from source (CLI), your local configuration file will be initially used. +When running from source (CLI), your local configuration file will be used. Examples for invoking the different tools via the CLI: @@ -27,9 +27,9 @@ Examples for invoking the different tools via the CLI: `` is the url of the relevant PR (for example: https://github.com/Codium-ai/pr-agent/pull/50). -Notes: +**Notes:** -(1) In addition to general configurations, each tool has its own configurations. For example, the 'review' tool will use parameters from the `[pr_reviewer]` section in the [configuration file](pr_agent/settings/configuration.toml) +(1) In addition to general configuration options, each tool has its own configurations. For example, the 'review' tool will use parameters from the `[pr_reviewer]` section in the [configuration file](/pr_agent/settings/configuration.toml#L16) (2) You can print results locally, without publishing them, by setting in `configuration.toml`: ``` @@ -40,11 +40,11 @@ verbosity_level=2 This is useful for debugging or experimenting with the different tools. ### Working from GitHub App (pre-built repo) -When running PR-Agent from GitHub App, the default configuration file (`configuration.toml`) will be loaded. +When running PR-Agent from GitHub App, the default configuration file (`configuration.toml`) will be initially loaded. #### GitHub app default tools -The `[github_app]` section of the configuration file defines GitHub app specific configurations. -The important parameter is `pr_commands`, which is a list of tools that will be run automatically when a new PR is opened: +The `[github_app]` section defines the GitHub app specific configurations. +An important parameter is `pr_commands`, which is a list of tools that will be run automatically when a new PR is opened: ``` [github_app] pr_commands = [ @@ -109,15 +109,6 @@ key = ... Also review the [AiHandler](pr_agent/algo/ai_handler.py) file for instruction how to set keys for other models. -#### Changing a GIT provider -See [here](pr_agent/git_providers/__init__.py) for the list of GIT providers. - -To use GitHub, for example, set: -``` -[config] -git_provider="github" -``` - #### Extra instructions ##### General All PR-Agent tools have a parameter called `extra_instructions`, that enables to add free-text extra instructions. Example usage: diff --git a/README.md b/README.md index 71278a03..ec0d5315 100644 --- a/README.md +++ b/README.md @@ -117,16 +117,16 @@ CodiumAI `PR-Agent` is an open-source tool aiming to help developers review pull | | Multiple models support | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | | | Incremental PR Review | :white_check_mark: | | | | | -Review the [configuration](./CONFIGURATION.md) section for instruction how to use the different tools, select the relevant git provider (GitHub, Gitlab, Bitbucket,...), and adjust the configuration file to your needs. +Review the [configuration](./CONFIGURATION.md) section for instructions how to use the different tools, select the relevant git provider (GitHub, Gitlab, Bitbucket,...), and adjust the configuration file to your needs. ## Try it now Try GPT-4 powered PR-Agent on your public GitHub repository for free. Just mention `@CodiumAI-Agent` and add the desired command in any PR comment! The agent will generate a response based on your command. -For example, add a comment: +For example, add a comment to any pull request with the following text: ``` @CodiumAI-Agent /review ``` -And the agent will respond with a review of your PR +and the agent will respond with a review of your PR ![Review generation process](https://www.codium.ai/images/demo-2.gif) From 4d6d6c48121c06f677be6dcc0e5b9ddccdaace37 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Fri, 1 Sep 2023 20:09:53 +0300 Subject: [PATCH 08/22] update --- CONFIGURATION.md | 17 ++++++++--------- README.md | 4 ++-- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/CONFIGURATION.md b/CONFIGURATION.md index 10a18aa7..5124bb63 100644 --- a/CONFIGURATION.md +++ b/CONFIGURATION.md @@ -4,7 +4,7 @@ The different tools and sub-tools used by CodiumAI PR-Agent are adjustable via t The `git_provider` field in the configuration file determines the GIT provider that will be used by PR-Agent. Currently, the following providers are supported: ` -"github", "gitlab", "azure", "codecommit","local" +"github", "gitlab", "azure", "codecommit", "local" ` Options that are available in the configuration file can be specified at run time when calling actions. Two examples: @@ -18,12 +18,12 @@ When running from source (CLI), your local configuration file will be used. Examples for invoking the different tools via the CLI: -- **Review**: python cli.py --pr_url= review -- **Describe**: python cli.py --pr_url= describe -- **Improve**: python cli.py --pr_url= improve -- **Ask**: python cli.py --pr_url= ask "Write me a poem about this PR" -- **Reflect**: python cli.py --pr_url= reflect -- **Update Changelog**: python cli.py --pr_url= update_changelog +- **Review**: `python cli.py --pr_url= review` +- **Describe**: `python cli.py --pr_url= describe` +- **Improve**: `python cli.py --pr_url= improve` +- **Ask**: `python cli.py --pr_url= ask "Write me a poem about this PR"` +- **Reflect**: `python cli.py --pr_url= reflect` +- **Update Changelog**: `python cli.py --pr_url= update_changelog` `` is the url of the relevant PR (for example: https://github.com/Codium-ai/pr-agent/pull/50). @@ -110,13 +110,12 @@ key = ... Also review the [AiHandler](pr_agent/algo/ai_handler.py) file for instruction how to set keys for other models. #### Extra instructions -##### General All PR-Agent tools have a parameter called `extra_instructions`, that enables to add free-text extra instructions. Example usage: ``` /update_changelog --pr_update_changelog.extra_instructions="Make sure to update also the version ..." ``` -##### Azure DevOps provider +#### Azure DevOps provider To use Azure DevOps provider use the following settings in configuration.toml: ``` [config] diff --git a/README.md b/README.md index ec0d5315..d0f8e9db 100644 --- a/README.md +++ b/README.md @@ -117,11 +117,11 @@ CodiumAI `PR-Agent` is an open-source tool aiming to help developers review pull | | Multiple models support | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | | | Incremental PR Review | :white_check_mark: | | | | | -Review the [configuration](./CONFIGURATION.md) section for instructions how to use the different tools, select the relevant git provider (GitHub, Gitlab, Bitbucket,...), and adjust the configuration file to your needs. +Review the **[configuration](./CONFIGURATION.md)** section for detailed instructions how to use the different tools, select the relevant git provider (GitHub, Gitlab, Bitbucket,...), and adjust the configuration file to your needs. ## Try it now -Try GPT-4 powered PR-Agent on your public GitHub repository for free. Just mention `@CodiumAI-Agent` and add the desired command in any PR comment! The agent will generate a response based on your command. +You can try GPT-4 powered PR-Agent, on your public GitHub repository, instantly. Just mention `@CodiumAI-Agent` and add the desired command in any PR comment. The agent will generate a response based on your command. For example, add a comment to any pull request with the following text: ``` @CodiumAI-Agent /review From 44b790567b03be1832989b3969bfeaed987fa478 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Fri, 1 Sep 2023 19:40:38 +0300 Subject: [PATCH 09/22] update readme --- CONFIGURATION.md | 50 ++++++++++++---------- README.md | 107 ++++++++++++++++++++++++++--------------------- 2 files changed, 89 insertions(+), 68 deletions(-) diff --git a/CONFIGURATION.md b/CONFIGURATION.md index 320ddedf..5124bb63 100644 --- a/CONFIGURATION.md +++ b/CONFIGURATION.md @@ -2,18 +2,36 @@ The different tools and sub-tools used by CodiumAI PR-Agent are adjustable via the **[configuration file](pr_agent/settings/configuration.toml)** +The `git_provider` field in the configuration file determines the GIT provider that will be used by PR-Agent. Currently, the following providers are supported: +` +"github", "gitlab", "azure", "codecommit", "local" +` + +Options that are available in the configuration file can be specified at run time when calling actions. Two examples: +``` +- /review --pr_reviewer.extra_instructions="focus on the file: ..." +- /describe --pr_description.add_original_user_description=false -pr_description.extra_instructions="make sure to mention: ..." +``` + ### Working from CLI -When running from source (CLI), your local configuration file will be initially used. +When running from source (CLI), your local configuration file will be used. -Example for invoking the 'review' tools via the CLI: +Examples for invoking the different tools via the CLI: -``` -python cli.py --pr-url= review -``` -In addition to general configurations, the 'review' tool will use parameters from the `[pr_reviewer]` section (every tool has a dedicated section in the configuration file). +- **Review**: `python cli.py --pr_url= review` +- **Describe**: `python cli.py --pr_url= describe` +- **Improve**: `python cli.py --pr_url= improve` +- **Ask**: `python cli.py --pr_url= ask "Write me a poem about this PR"` +- **Reflect**: `python cli.py --pr_url= reflect` +- **Update Changelog**: `python cli.py --pr_url= update_changelog` -Note that you can print results locally, without publishing them, by setting in `configuration.toml`: +`` is the url of the relevant PR (for example: https://github.com/Codium-ai/pr-agent/pull/50). +**Notes:** + +(1) In addition to general configuration options, each tool has its own configurations. For example, the 'review' tool will use parameters from the `[pr_reviewer]` section in the [configuration file](/pr_agent/settings/configuration.toml#L16) + +(2) You can print results locally, without publishing them, by setting in `configuration.toml`: ``` [config] publish_output=true @@ -22,11 +40,11 @@ verbosity_level=2 This is useful for debugging or experimenting with the different tools. ### Working from GitHub App (pre-built repo) -When running PR-Agent from GitHub App, the default configuration file (`configuration.toml`) will be loaded. +When running PR-Agent from GitHub App, the default configuration file (`configuration.toml`) will be initially loaded. #### GitHub app default tools -The `[github_app]` section of the configuration file defines GitHub app specific configurations. -The important parameter is `pr_commands`, which is a list of tools that will be run automatically when a new PR is opened: +The `[github_app]` section defines the GitHub app specific configurations. +An important parameter is `pr_commands`, which is a list of tools that will be run automatically when a new PR is opened: ``` [github_app] pr_commands = [ @@ -91,23 +109,13 @@ key = ... Also review the [AiHandler](pr_agent/algo/ai_handler.py) file for instruction how to set keys for other models. -#### Changing a GIT provider -See [here](pr_agent/git_providers/__init__.py) for the list of GIT providers. - -To use GitHub, for example, set: -``` -[config] -git_provider="github" -``` - #### Extra instructions -##### General All PR-Agent tools have a parameter called `extra_instructions`, that enables to add free-text extra instructions. Example usage: ``` /update_changelog --pr_update_changelog.extra_instructions="Make sure to update also the version ..." ``` -##### Azure DevOps provider +#### Azure DevOps provider To use Azure DevOps provider use the following settings in configuration.toml: ``` [config] diff --git a/README.md b/README.md index 85705c6c..d0f8e9db 100644 --- a/README.md +++ b/README.md @@ -35,33 +35,55 @@ CodiumAI `PR-Agent` is an open-source tool aiming to help developers review pull

-

/review:

-
-

- -

-
-

/reflect_and_review:

-
-

- -

-
-

/ask:

-
-

- -

-
-

/improve:

-
-

- -

-
+ +[//]: # (

/review:

) +[//]: # (
) + +[//]: # (

) + +[//]: # () + +[//]: # (

) + +[//]: # (
) +[//]: # (

/reflect_and_review:

) + +[//]: # (
) + +[//]: # (

) + +[//]: # () + +[//]: # (

) + +[//]: # (
) + +[//]: # (

/ask:

) + +[//]: # (
) + +[//]: # (

) + +[//]: # () + +[//]: # (

) + +[//]: # (
) + +[//]: # (

/improve:

) + +[//]: # (
) + +[//]: # (

) + +[//]: # () + +[//]: # (

) + +[//]: # (
)
- +## Table of Contents - [Overview](#overview) - [Try it now](#try-it-now) - [Installation](#installation) @@ -69,7 +91,6 @@ CodiumAI `PR-Agent` is an open-source tool aiming to help developers review pull - [How it works](#how-it-works) - [Why use PR-Agent](#why-use-pr-agent) - [Roadmap](#roadmap) -- [Similar projects](#similar-projects)
@@ -78,7 +99,6 @@ CodiumAI `PR-Agent` is an open-source tool aiming to help developers review pull | | | GitHub | Gitlab | Bitbucket | CodeCommit | Azure DevOps | |-------|---------------------------------------------|:------:|:------:|:---------:|:----------:|:----------:| | TOOLS | Review | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | -| | ⮑ Inline review | :white_check_mark: | :white_check_mark: | | | | | | Ask | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | | Auto-Description | :white_check_mark: | :white_check_mark: | | :white_check_mark: | :white_check_mark: | | | Improve Code | :white_check_mark: | :white_check_mark: | | | | @@ -91,34 +111,27 @@ CodiumAI `PR-Agent` is an open-source tool aiming to help developers review pull | | Tagging bot | :white_check_mark: | | | | | | | Actions | :white_check_mark: | | | | | | | | | | | | | -| CORE | PR compression | :white_check_mark: | :white_check_mark: | :white_check_mark: | | :white_check_mark: | -| | Repo language prioritization | :white_check_mark: | :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: | | :white_check_mark: | -| | Multiple models support | :white_check_mark: | :white_check_mark: | :white_check_mark: | | :white_check_mark: | +| CORE | PR compression | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | +| | Repo language prioritization | :white_check_mark: | :white_check_mark: | :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: | :white_check_mark: | :white_check_mark: | +| | Multiple models support | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | | | Incremental PR Review | :white_check_mark: | | | | | -Examples for invoking the different tools via the CLI: -- **Review**: python cli.py --pr_url= review -- **Describe**: python cli.py --pr_url= describe -- **Improve**: python cli.py --pr_url= improve -- **Ask**: python cli.py --pr_url= ask "Write me a poem about this PR" -- **Reflect**: python cli.py --pr_url= reflect -- **Update Changelog**: python cli.py --pr_url= update_changelog - -"" is the url of the relevant PR (for example: https://github.com/Codium-ai/pr-agent/pull/50). - -In the [configuration](./CONFIGURATION.md) file you can select your git provider (GitHub, Gitlab, Bitbucket), and further configure the different tools. -Options that are available in the configuration file can be specified at run time when calling actions. Two examples: -- /review --pr_reviewer.extra_instructions="focus on the file: ..." -- /describe --pr_description.add_original_user_description=false -pr_description.extra_instructions="make sure to mention: ..." +Review the **[configuration](./CONFIGURATION.md)** section for detailed instructions how to use the different tools, select the relevant git provider (GitHub, Gitlab, Bitbucket,...), and adjust the configuration file to your needs. ## Try it now -Try GPT-4 powered PR-Agent on your public GitHub repository for free. Just mention `@CodiumAI-Agent` and add the desired command in any PR comment! The agent will generate a response based on your command. +You can try GPT-4 powered PR-Agent, on your public GitHub repository, instantly. Just mention `@CodiumAI-Agent` and add the desired command in any PR comment. The agent will generate a response based on your command. +For example, add a comment to any pull request with the following text: +``` +@CodiumAI-Agent /review +``` +and the agent will respond with a review of your PR ![Review generation process](https://www.codium.ai/images/demo-2.gif) -To set up your own PR-Agent, see the [Installation](#installation) section + +To set up your own PR-Agent, see the [Installation](#installation) section below. --- From 20c32375e197d45984d2223e6ed00a573b9a0535 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Fri, 1 Sep 2023 20:14:14 +0300 Subject: [PATCH 10/22] auto --- CONFIGURATION.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CONFIGURATION.md b/CONFIGURATION.md index 5124bb63..7790f9f5 100644 --- a/CONFIGURATION.md +++ b/CONFIGURATION.md @@ -44,7 +44,7 @@ When running PR-Agent from GitHub App, the default configuration file (`configur #### GitHub app default tools The `[github_app]` section defines the GitHub app specific configurations. -An important parameter is `pr_commands`, which is a list of tools that will be run automatically when a new PR is opened: +An important parameter is `pr_commands`, which is a list of tools that will be **run automatically when a new PR is opened**: ``` [github_app] pr_commands = [ @@ -55,7 +55,7 @@ pr_commands = [ This means that when a new PR is opened, PR-Agent will run the `describe` and `auto_review` tools. For the describe tool, the `add_original_user_description` and `keep_original_user_title` parameters will be set to true. -However, you can override the default tool parameters by uploading a local configuration file called `.pr_agent.toml` to the root of your repo. +However, 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: ``` [pr_description] From 690c8194790af018ad6fd0ff74ec283160376202 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Fri, 1 Sep 2023 20:22:10 +0300 Subject: [PATCH 11/22] update CONFIGURATION.md --- CONFIGURATION.md | 46 +++++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/CONFIGURATION.md b/CONFIGURATION.md index b92d6e0b..e7ab2d65 100644 --- a/CONFIGURATION.md +++ b/CONFIGURATION.md @@ -2,18 +2,36 @@ The different tools and sub-tools used by CodiumAI PR-Agent are adjustable via the **[configuration file](pr_agent/settings/configuration.toml)** +The `git_provider` field in the configuration file determines the GIT provider that will be used by PR-Agent. Currently, the following providers are supported: +` +"github", "gitlab", "azure", "codecommit", "local" +` + +Options that are available in the configuration file can be specified at run time when calling actions. Two examples: +``` +- /review --pr_reviewer.extra_instructions="focus on the file: ..." +- /describe --pr_description.add_original_user_description=false -pr_description.extra_instructions="make sure to mention: ..." +``` + ### Working from CLI -When running from source (CLI), your local configuration file will be initially used. +When running from source (CLI), your local configuration file will be used. -Example for invoking the 'review' tools via the CLI: +Examples for invoking the different tools via the CLI: -``` -python cli.py --pr-url= review -``` -In addition to general configurations, the 'review' tool will use parameters from the `[pr_reviewer]` section (every tool has a dedicated section in the configuration file). +- **Review**: `python cli.py --pr_url= review` +- **Describe**: `python cli.py --pr_url= describe` +- **Improve**: `python cli.py --pr_url= improve` +- **Ask**: `python cli.py --pr_url= ask "Write me a poem about this PR"` +- **Reflect**: `python cli.py --pr_url= reflect` +- **Update Changelog**: `python cli.py --pr_url= update_changelog` -Note that you can print results locally, without publishing them, by setting in `configuration.toml`: +`` is the url of the relevant PR (for example: https://github.com/Codium-ai/pr-agent/pull/50). +**Notes:** + +(1) In addition to general configuration options, each tool has its own configurations. For example, the 'review' tool will use parameters from the `[pr_reviewer]` section in the [configuration file](/pr_agent/settings/configuration.toml#L16) + +(2) You can print results locally, without publishing them, by setting in `configuration.toml`: ``` [config] publish_output=true @@ -22,7 +40,7 @@ verbosity_level=2 This is useful for debugging or experimenting with the different tools. ### Working from GitHub App (pre-built repo) -When running PR-Agent from GitHub App, the default configuration file (`configuration.toml`) will be loaded. +When running PR-Agent from GitHub App, the default configuration file (`configuration.toml`) will be initially loaded. #### GitHub app default tools The `[github_app]` section defines the GitHub app specific configurations. @@ -91,23 +109,13 @@ key = ... Also review the [AiHandler](pr_agent/algo/ai_handler.py) file for instruction how to set keys for other models. -#### Changing a GIT provider -See [here](pr_agent/git_providers/__init__.py) for the list of GIT providers. - -To use GitHub, for example, set: -``` -[config] -git_provider="github" -``` - #### Extra instructions -##### General All PR-Agent tools have a parameter called `extra_instructions`, that enables to add free-text extra instructions. Example usage: ``` /update_changelog --pr_update_changelog.extra_instructions="Make sure to update also the version ..." ``` -##### Azure DevOps provider +#### Azure DevOps provider To use Azure DevOps provider use the following settings in configuration.toml: ``` [config] From e79bcbed930b62feaf51128807fab62c87a5bd8d Mon Sep 17 00:00:00 2001 From: mrT23 Date: Fri, 1 Sep 2023 20:25:07 +0300 Subject: [PATCH 12/22] update CONFIGURATION.md --- CONFIGURATION.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONFIGURATION.md b/CONFIGURATION.md index e7ab2d65..872caedc 100644 --- a/CONFIGURATION.md +++ b/CONFIGURATION.md @@ -2,7 +2,7 @@ The different tools and sub-tools used by CodiumAI PR-Agent are adjustable via the **[configuration file](pr_agent/settings/configuration.toml)** -The `git_provider` field in the configuration file determines the GIT provider that will be used by PR-Agent. Currently, the following providers are supported: +The [git_provider](pr-agent/blob/main/pr_agent/settings/configuration.toml#L4) field in the configuration file determines the GIT provider that will be used by PR-Agent. Currently, the following providers are supported: ` "github", "gitlab", "azure", "codecommit", "local" ` From d52c11b907cdb5fded834fe3047f840b34e634b6 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Fri, 1 Sep 2023 20:26:36 +0300 Subject: [PATCH 13/22] update CONFIGURATION.md --- CONFIGURATION.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONFIGURATION.md b/CONFIGURATION.md index 872caedc..f3daa1d0 100644 --- a/CONFIGURATION.md +++ b/CONFIGURATION.md @@ -2,7 +2,7 @@ The different tools and sub-tools used by CodiumAI PR-Agent are adjustable via the **[configuration file](pr_agent/settings/configuration.toml)** -The [git_provider](pr-agent/blob/main/pr_agent/settings/configuration.toml#L4) field in the configuration file determines the GIT provider that will be used by PR-Agent. Currently, the following providers are supported: +The [git_provider](pr-agent/settings/configuration.toml#L4) field in the configuration file determines the GIT provider that will be used by PR-Agent. Currently, the following providers are supported: ` "github", "gitlab", "azure", "codecommit", "local" ` From 98019fe97f11142072959add69bb6edc7ff97c55 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Fri, 1 Sep 2023 20:27:29 +0300 Subject: [PATCH 14/22] update CONFIGURATION.md --- CONFIGURATION.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONFIGURATION.md b/CONFIGURATION.md index f3daa1d0..b02c7e2b 100644 --- a/CONFIGURATION.md +++ b/CONFIGURATION.md @@ -2,7 +2,7 @@ The different tools and sub-tools used by CodiumAI PR-Agent are adjustable via the **[configuration file](pr_agent/settings/configuration.toml)** -The [git_provider](pr-agent/settings/configuration.toml#L4) field in the configuration file determines the GIT provider that will be used by PR-Agent. Currently, the following providers are supported: +The [git_provider](pr_agent/settings/configuration.toml#L4) field in the configuration file determines the GIT provider that will be used by PR-Agent. Currently, the following providers are supported: ` "github", "gitlab", "azure", "codecommit", "local" ` From 2b8a8ce824f4dfda40ac5c3aaa78bd4486169341 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Sat, 2 Sep 2023 09:19:35 +0300 Subject: [PATCH 15/22] update README.md --- INSTALL.md | 78 ++++++++++++++++++------------------ README.md | 10 ++--- CONFIGURATION.md => Usage.md | 73 ++++++++++++++++++++++++--------- 3 files changed, 99 insertions(+), 62 deletions(-) rename CONFIGURATION.md => Usage.md (62%) diff --git a/INSTALL.md b/INSTALL.md index e778e266..37bee57e 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -9,8 +9,8 @@ To get started with PR-Agent quickly, 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 as a GitHub Action](INSTALL.md#method-2-run-as-a-github-action) -- [Method 3: Run from source](INSTALL.md#method-3-run-from-source) +- [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) - [Method 5: Run as a GitHub App](INSTALL.md#method-5-run-as-a-github-app) - [Method 6: Deploy as a Lambda Function](INSTALL.md#method-6---deploy-as-a-lambda-function) @@ -55,7 +55,41 @@ Possible questions you can ask include: --- -### Method 2: Run as a GitHub Action +### Method 2: Run from source + +1. Clone this repository: + +``` +git clone https://github.com/Codium-ai/pr-agent.git +``` + +2. Install the requirements in your favorite virtual environment: + +``` +pip install -r requirements.txt +``` + +3. Copy the secrets template file and fill in your OpenAI key and your GitHub user token: + +``` +cp pr_agent/settings/.secrets_template.toml pr_agent/settings/.secrets.toml +chmod 600 pr_agent/settings/.secrets.toml +# Edit .secrets.toml file +``` + +4. Add the pr_agent folder to your PYTHONPATH, then run the cli.py script: + +``` +export PYTHONPATH=[$PYTHONPATH:] +python pr_agent/cli.py --pr_url review +python pr_agent/cli.py --pr_url ask +python pr_agent/cli.py --pr_url describe +python pr_agent/cli.py --pr_url improve +``` + +--- + +### Method 3: Run as a GitHub Action You can use our pre-built Github Action Docker image to run PR-Agent as a Github Action. @@ -114,7 +148,7 @@ The GITHUB_TOKEN secret is automatically created by GitHub. 3. Merge this change to your main branch. When you open your next PR, you should see a comment from `github-actions` bot with a review of your PR, and instructions on how to use the rest of the tools. -4. You may configure PR-Agent by adding environment variables under the env section corresponding to any configurable property in the [configuration](./CONFIGURATION.md) file. Some examples: +4. You may configure PR-Agent by adding environment variables under the env section corresponding to any configurable property in the [configuration](./Usage.md) file. Some examples: ```yaml env: # ... previous environment values @@ -125,40 +159,6 @@ When you open your next PR, you should see a comment from `github-actions` bot w --- -### Method 3: Run from source - -1. Clone this repository: - -``` -git clone https://github.com/Codium-ai/pr-agent.git -``` - -2. Install the requirements in your favorite virtual environment: - -``` -pip install -r requirements.txt -``` - -3. Copy the secrets template file and fill in your OpenAI key and your GitHub user token: - -``` -cp pr_agent/settings/.secrets_template.toml pr_agent/settings/.secrets.toml -chmod 600 pr_agent/settings/.secrets.toml -# Edit .secrets.toml file -``` - -4. Add the pr_agent folder to your PYTHONPATH, then run the cli.py script: - -``` -export PYTHONPATH=[$PYTHONPATH:] -python pr_agent/cli.py --pr_url review -python pr_agent/cli.py --pr_url ask -python pr_agent/cli.py --pr_url describe -python pr_agent/cli.py --pr_url improve -``` - ---- - ### Method 4: Run as a polling server Request reviews by tagging your Github user on a PR @@ -253,7 +253,7 @@ docker push codiumai/pr-agent:github_app # Push to your Docker repository > **Note:** When running PR-Agent from GitHub App, the default configuration file (configuration.toml) will be loaded.
> However, you can override the default tool parameters by uploading a local configuration file
-> For more information please check out [CONFIGURATION.md](CONFIGURATION.md#working-from-github-app-pre-built-repo) +> For more information please check out [CONFIGURATION.md](Usage.md#working-from-github-app-pre-built-repo) --- ### Method 6 - Deploy as a Lambda Function diff --git a/README.md b/README.md index d0f8e9db..cdd2688f 100644 --- a/README.md +++ b/README.md @@ -87,7 +87,7 @@ CodiumAI `PR-Agent` is an open-source tool aiming to help developers review pull - [Overview](#overview) - [Try it now](#try-it-now) - [Installation](#installation) -- [Configuration](./CONFIGURATION.md) +- [Usage guide](./Usage.md) - [How it works](#how-it-works) - [Why use PR-Agent](#why-use-pr-agent) - [Roadmap](#roadmap) @@ -117,7 +117,7 @@ CodiumAI `PR-Agent` is an open-source tool aiming to help developers review pull | | Multiple models support | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | | | Incremental PR Review | :white_check_mark: | | | | | -Review the **[configuration](./CONFIGURATION.md)** section for detailed instructions how to use the different tools, select the relevant git provider (GitHub, Gitlab, Bitbucket,...), and adjust the configuration file to your needs. +Review the **[usage guide](./Usage.md)** section for detailed instructions how to use the different tools, select the relevant git provider (GitHub, Gitlab, Bitbucket,...), and adjust the configuration file to your needs. ## Try it now @@ -145,8 +145,8 @@ To get started with PR-Agent quickly, 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 as a GitHub Action](INSTALL.md#method-2-run-as-a-github-action) -- [Method 3: Run from source](INSTALL.md#method-3-run-from-source) +- [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) @@ -170,7 +170,7 @@ Here are some advantages of PR-Agent: - We emphasize **real-life practical usage**. Each tool (review, improve, ask, ...) has a single GPT-4 call, no more. We feel that this is critical for realistic team usage - obtaining an answer quickly (~30 seconds) and affordably. - Our [PR Compression strategy](./PR_COMPRESSION.md) is a core ability that enables to effectively tackle both short and long PRs. -- Our JSON prompting strategy enables to have **modular, customizable tools**. For example, the '/review' tool categories can be controlled via the [configuration](./CONFIGURATION.md) file. Adding additional categories is easy and accessible. +- Our JSON prompting strategy enables to have **modular, customizable tools**. For example, the '/review' tool categories can be controlled via the [configuration](pr_agent/settings/configuration.toml) file. Adding additional categories is easy and accessible. - We support **multiple git providers** (GitHub, Gitlab, Bitbucket, CodeCommit), **multiple ways** to use the tool (CLI, GitHub Action, GitHub App, Docker, ...), and **multiple models** (GPT-4, GPT-3.5, Anthropic, Cohere, Llama2). - We are open-source, and welcome contributions from the community. diff --git a/CONFIGURATION.md b/Usage.md similarity index 62% rename from CONFIGURATION.md rename to Usage.md index b02c7e2b..baca3db9 100644 --- a/CONFIGURATION.md +++ b/Usage.md @@ -1,20 +1,39 @@ -## Configuration +## Usage guide +### Introduction + +There are 3 basic ways to invoke CodiumAI PR-Agent: +1. Locally running a CLI command +2. Online usage - by [commenting](https://github.com/Codium-ai/pr-agent/pull/229#issuecomment-1695021901) on a PR +3. Enabling PR-Agent specific tools to run automatically when a new PR is opened + +See the [installation guide](/INSTALL.md) for instructions on how to install and run your own PR-Agent. + +Specifically, CLI commands can be issued by invoking a pre-built [docker image](/INSTALL.md#running-from-source), or by invoking a [locally cloned repo](INSTALL.md#method-2-run-from-source) + +For online usage, you will need to setup either a [GitHub App](INSTALL.md#method-5-run-as-a-github-app), or a [GitHub Action](INSTALL.md#method-3-run-as-a-github-action). +GitHub App and GitHub Action also enable to run PR-Agent specific tool automatically when a new PR is opened. + + +#### The configuration file The different tools and sub-tools used by CodiumAI PR-Agent are adjustable via the **[configuration file](pr_agent/settings/configuration.toml)** +In addition to general configuration options, each tool has its own configurations. For example, the 'review' tool will use parameters from the `[pr_reviewer]` section in the [configuration file](/pr_agent/settings/configuration.toml#L16) +** git provider:** The [git_provider](pr_agent/settings/configuration.toml#L4) field in the configuration file determines the GIT provider that will be used by PR-Agent. Currently, the following providers are supported: ` "github", "gitlab", "azure", "codecommit", "local" ` +** online usage:** Options that are available in the configuration file can be specified at run time when calling actions. Two examples: ``` - /review --pr_reviewer.extra_instructions="focus on the file: ..." - /describe --pr_description.add_original_user_description=false -pr_description.extra_instructions="make sure to mention: ..." ``` -### Working from CLI -When running from source (CLI), your local configuration file will be used. +### Working from a local repo (CLI) +When running from your local repo (CLI), your local configuration file, which you can edit, will be used. Examples for invoking the different tools via the CLI: @@ -28,8 +47,10 @@ Examples for invoking the different tools via the CLI: `` is the url of the relevant PR (for example: https://github.com/Codium-ai/pr-agent/pull/50). **Notes:** - -(1) In addition to general configuration options, each tool has its own configurations. For example, the 'review' tool will use parameters from the `[pr_reviewer]` section in the [configuration file](/pr_agent/settings/configuration.toml#L16) +(1) in addition to editing the configuration file, you can also override any configuration by adding it to the command line: +``` +python cli.py --pr_url= review --pr_reviewer.extra_instructions="focus on the file: ..." +``` (2) You can print results locally, without publishing them, by setting in `configuration.toml`: ``` @@ -39,10 +60,32 @@ verbosity_level=2 ``` This is useful for debugging or experimenting with the different tools. -### Working from GitHub App (pre-built repo) -When running PR-Agent from GitHub App, the default configuration file (`configuration.toml`) will be initially loaded. -#### GitHub app default tools +### Online usage + +Online usage means invoking PR-Agent tools by [comments](https://github.com/Codium-ai/pr-agent/pull/229#issuecomment-1695021901) on a PR. +Commands for invoking the different tools via comments: + +- **Review**: `/review` +- **Describe**: `/describe` +- **Improve**: `/improve` +- **Ask**: `/ask "Write me a poem about this PR"` +- **Reflect**: `/reflect` +- **Update Changelog**: `/update_changelog` + + +To edit a specific configuration value, just add `--config_path=` to any command. +For example if you want to edit the `review` tool configurations, you can run: +``` +/review --pr_reviewer.extra_instructions="..." --pr_reviewer.require_score_review=false ... +``` +Any configuration value in [configuration file](pr_agent/settings/configuration.toml) file can be similarly edited. + + +### Working with GitHub App +When running PR-Agent from [GitHub App](INSTALL.md#method-5-run-as-a-github-app), the default configuration file of a pre-built repo will be initially loaded. + +#### GitHub app automatic tools The `[github_app]` section defines the GitHub app specific configurations. An important parameter is `pr_commands`, which is a list of tools that will be **run automatically when a new PR is opened**: ``` @@ -62,7 +105,7 @@ For example, if your local `.pr_agent.toml` file contains: add_original_user_description = false keep_original_user_title = false ``` -Then when a new PR is opened, PR-Agent will run the `describe` tool with the above parameters. +When a new PR is opened, PR-Agent will run the `describe` tool with the above parameters. Note that a local `.pr_agent.toml` file enables you to edit and customize the default parameters of any tool, not just the ones that are run automatically. @@ -84,16 +127,10 @@ 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). -#### Online usage -For online usage (calling tools by comments on a PR like `/ask ...`), just add `--config_path=` to any command, to edit a specific configuration value. -For example if you want to edit `pr_reviewer` configurations, you can run: -``` -/review --pr_reviewer.extra_instructions="..." --pr_reviewer.require_score_review=false ... -``` -Any configuration value in `configuration.toml` file can be similarly edited. +### Working with GitHub Action +TBD - -### General configuration walkthrough +### Appendix - general configuration walkthrough #### Changing a model See [here](pr_agent/algo/__init__.py) for the list of available models. From 990f69a95d9664e7138ebc54bd1dfd849be3da70 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Sat, 2 Sep 2023 09:25:38 +0300 Subject: [PATCH 16/22] update README.md --- Usage.md | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/Usage.md b/Usage.md index baca3db9..f54ef26f 100644 --- a/Usage.md +++ b/Usage.md @@ -5,9 +5,9 @@ There are 3 basic ways to invoke CodiumAI PR-Agent: 1. Locally running a CLI command 2. Online usage - by [commenting](https://github.com/Codium-ai/pr-agent/pull/229#issuecomment-1695021901) on a PR -3. Enabling PR-Agent specific tools to run automatically when a new PR is opened +3. Enabling PR-Agent tools to run automatically when a new PR is opened -See the [installation guide](/INSTALL.md) for instructions on how to install and run your own PR-Agent. +See the [installation guide](/INSTALL.md) for instructions on how to setup your own PR-Agent. Specifically, CLI commands can be issued by invoking a pre-built [docker image](/INSTALL.md#running-from-source), or by invoking a [locally cloned repo](INSTALL.md#method-2-run-from-source) @@ -17,7 +17,7 @@ GitHub App and GitHub Action also enable to run PR-Agent specific tool automatic #### The configuration file The different tools and sub-tools used by CodiumAI PR-Agent are adjustable via the **[configuration file](pr_agent/settings/configuration.toml)** -In addition to general configuration options, each tool has its own configurations. For example, the 'review' tool will use parameters from the `[pr_reviewer]` section in the [configuration file](/pr_agent/settings/configuration.toml#L16) +In addition to general configuration options, each tool has its own configurations. For example, the `review` tool will use parameters from the `[pr_reviewer]` section in the [configuration file](/pr_agent/settings/configuration.toml#L16) ** git provider:** The [git_provider](pr_agent/settings/configuration.toml#L4) field in the configuration file determines the GIT provider that will be used by PR-Agent. Currently, the following providers are supported: @@ -25,12 +25,17 @@ The [git_provider](pr_agent/settings/configuration.toml#L4) field in the configu "github", "gitlab", "azure", "codecommit", "local" ` -** online usage:** -Options that are available in the configuration file can be specified at run time when calling actions. Two examples: -``` -- /review --pr_reviewer.extra_instructions="focus on the file: ..." -- /describe --pr_description.add_original_user_description=false -pr_description.extra_instructions="make sure to mention: ..." -``` +[//]: # (** online usage:**) + +[//]: # (Options that are available in the configuration file can be specified at run time when calling actions. Two examples:) + +[//]: # (```) + +[//]: # (- /review --pr_reviewer.extra_instructions="focus on the file: ...") + +[//]: # (- /describe --pr_description.add_original_user_description=false -pr_description.extra_instructions="make sure to mention: ...") + +[//]: # (```) ### Working from a local repo (CLI) When running from your local repo (CLI), your local configuration file, which you can edit, will be used. @@ -47,7 +52,7 @@ Examples for invoking the different tools via the CLI: `` is the url of the relevant PR (for example: https://github.com/Codium-ai/pr-agent/pull/50). **Notes:** -(1) in addition to editing the configuration file, you can also override any configuration by adding it to the command line: +(1) in addition to editing the configuration file, you can also override any configuration value by adding it to the command line: ``` python cli.py --pr_url= review --pr_reviewer.extra_instructions="focus on the file: ..." ``` @@ -83,10 +88,10 @@ Any configuration value in [configuration file](pr_agent/settings/configuration. ### Working with GitHub App -When running PR-Agent from [GitHub App](INSTALL.md#method-5-run-as-a-github-app), the default configuration file of a pre-built repo will be initially loaded. +When running PR-Agent from [GitHub App](INSTALL.md#method-5-run-as-a-github-app), the default configurations of a pre-built repo will be initially loaded. #### GitHub app automatic tools -The `[github_app]` section defines the GitHub app specific configurations. +The `[github_app]` section of the [configuration file](pr_agent/settings/configuration.toml) defines GitHub app specific configurations. An important parameter is `pr_commands`, which is a list of tools that will be **run automatically when a new PR is opened**: ``` [github_app] @@ -112,8 +117,8 @@ Note that a local `.pr_agent.toml` file enables you to edit and customize the de #### Editing the prompts The prompts for the various PR-Agent tools are defined in the `pr_agent/settings` folder. -In practice, the prompts are loaded and stored as a standard setting object. Hence, -editing them is similar to editing any other configuration value - just place the relevant key in `.pr_agent.toml`file, and override the default value. +In practice, the prompts are loaded and stored as a standard setting object. +Hence, editing them is similar to editing any other configuration value - just place the relevant key in `.pr_agent.toml`file, and override the default value. For example, if you want to edit the prompts of the [describe](./pr_agent/settings/pr_description_prompts.toml) tool, you can add the following to your `.pr_agent.toml` file: ``` @@ -130,7 +135,7 @@ Note that the new prompt will need to generate an output compatible with the rel ### Working with GitHub Action TBD -### Appendix - general configuration walkthrough +### Appendix - additional configurations walkthrough #### Changing a model See [here](pr_agent/algo/__init__.py) for the list of available models. From 1f7a833a540e60cab531696d992b54e0ecd352b9 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Sat, 2 Sep 2023 09:33:33 +0300 Subject: [PATCH 17/22] update README.md --- Usage.md | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/Usage.md b/Usage.md index f54ef26f..c1277103 100644 --- a/Usage.md +++ b/Usage.md @@ -8,9 +8,7 @@ There are 3 basic ways to invoke CodiumAI PR-Agent: 3. Enabling PR-Agent tools to run automatically when a new PR is opened See the [installation guide](/INSTALL.md) for instructions on how to setup your own PR-Agent. - Specifically, CLI commands can be issued by invoking a pre-built [docker image](/INSTALL.md#running-from-source), or by invoking a [locally cloned repo](INSTALL.md#method-2-run-from-source) - For online usage, you will need to setup either a [GitHub App](INSTALL.md#method-5-run-as-a-github-app), or a [GitHub Action](INSTALL.md#method-3-run-as-a-github-action). GitHub App and GitHub Action also enable to run PR-Agent specific tool automatically when a new PR is opened. @@ -19,7 +17,7 @@ GitHub App and GitHub Action also enable to run PR-Agent specific tool automatic The different tools and sub-tools used by CodiumAI PR-Agent are adjustable via the **[configuration file](pr_agent/settings/configuration.toml)** In addition to general configuration options, each tool has its own configurations. For example, the `review` tool will use parameters from the `[pr_reviewer]` section in the [configuration file](/pr_agent/settings/configuration.toml#L16) -** git provider:** +**git provider:** The [git_provider](pr_agent/settings/configuration.toml#L4) field in the configuration file determines the GIT provider that will be used by PR-Agent. Currently, the following providers are supported: ` "github", "gitlab", "azure", "codecommit", "local" @@ -38,7 +36,7 @@ The [git_provider](pr_agent/settings/configuration.toml#L4) field in the configu [//]: # (```) ### Working from a local repo (CLI) -When running from your local repo (CLI), your local configuration file, which you can edit, will be used. +When running from your local repo (CLI), your local configuration file will be used. Examples for invoking the different tools via the CLI: @@ -52,7 +50,7 @@ Examples for invoking the different tools via the CLI: `` is the url of the relevant PR (for example: https://github.com/Codium-ai/pr-agent/pull/50). **Notes:** -(1) in addition to editing the configuration file, you can also override any configuration value by adding it to the command line: +(1) in addition to editing your local configuration file, you can also change any configuration value by adding it to the command line: ``` python cli.py --pr_url= review --pr_reviewer.extra_instructions="focus on the file: ..." ``` @@ -74,7 +72,7 @@ Commands for invoking the different tools via comments: - **Review**: `/review` - **Describe**: `/describe` - **Improve**: `/improve` -- **Ask**: `/ask "Write me a poem about this PR"` +- **Ask**: `/ask "..."` - **Reflect**: `/reflect` - **Update Changelog**: `/update_changelog` @@ -82,7 +80,7 @@ Commands for invoking the different tools via comments: To edit a specific configuration value, just add `--config_path=` to any command. For example if you want to edit the `review` tool configurations, you can run: ``` -/review --pr_reviewer.extra_instructions="..." --pr_reviewer.require_score_review=false ... +/review --pr_reviewer.extra_instructions="..." --pr_reviewer.require_score_review=false ``` Any configuration value in [configuration file](pr_agent/settings/configuration.toml) file can be similarly edited. @@ -91,7 +89,7 @@ Any configuration value in [configuration file](pr_agent/settings/configuration. When running PR-Agent from [GitHub App](INSTALL.md#method-5-run-as-a-github-app), the default configurations of a pre-built repo will be initially loaded. #### GitHub app automatic tools -The `[github_app]` section of the [configuration file](pr_agent/settings/configuration.toml) defines GitHub app specific configurations. +The [github_app](pr_agent/settings/configuration.toml#L56) section defines GitHub app specific configurations. An important parameter is `pr_commands`, which is a list of tools that will be **run automatically when a new PR is opened**: ``` [github_app] From 9567199bb2b723b17dad03113fa951e2282d952b Mon Sep 17 00:00:00 2001 From: mrT23 Date: Sat, 2 Sep 2023 09:37:44 +0300 Subject: [PATCH 18/22] update README.md --- Usage.md | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Usage.md b/Usage.md index c1277103..329bba54 100644 --- a/Usage.md +++ b/Usage.md @@ -8,14 +8,16 @@ There are 3 basic ways to invoke CodiumAI PR-Agent: 3. Enabling PR-Agent tools to run automatically when a new PR is opened See the [installation guide](/INSTALL.md) for instructions on how to setup your own PR-Agent. -Specifically, CLI commands can be issued by invoking a pre-built [docker image](/INSTALL.md#running-from-source), or by invoking a [locally cloned repo](INSTALL.md#method-2-run-from-source) + +Specifically, CLI commands can be issued by invoking a pre-built [docker image](/INSTALL.md#running-from-source), or by invoking a [locally cloned repo](INSTALL.md#method-2-run-from-source). + For online usage, you will need to setup either a [GitHub App](INSTALL.md#method-5-run-as-a-github-app), or a [GitHub Action](INSTALL.md#method-3-run-as-a-github-action). GitHub App and GitHub Action also enable to run PR-Agent specific tool automatically when a new PR is opened. #### The configuration file -The different tools and sub-tools used by CodiumAI PR-Agent are adjustable via the **[configuration file](pr_agent/settings/configuration.toml)** -In addition to general configuration options, each tool has its own configurations. For example, the `review` tool will use parameters from the `[pr_reviewer]` section in the [configuration file](/pr_agent/settings/configuration.toml#L16) +The different tools and sub-tools used by CodiumAI PR-Agent are adjustable via the **[configuration file](pr_agent/settings/configuration.toml)**. +In addition to general configuration options, each tool has its own configurations. For example, the `review` tool will use parameters from the [pr_reviewer](/pr_agent/settings/configuration.toml#L16) section in the configuration file. **git provider:** The [git_provider](pr_agent/settings/configuration.toml#L4) field in the configuration file determines the GIT provider that will be used by PR-Agent. Currently, the following providers are supported: @@ -50,6 +52,7 @@ Examples for invoking the different tools via the CLI: `` is the url of the relevant PR (for example: https://github.com/Codium-ai/pr-agent/pull/50). **Notes:** + (1) in addition to editing your local configuration file, you can also change any configuration value by adding it to the command line: ``` python cli.py --pr_url= review --pr_reviewer.extra_instructions="focus on the file: ..." @@ -86,7 +89,7 @@ Any configuration value in [configuration file](pr_agent/settings/configuration. ### Working with GitHub App -When running PR-Agent from [GitHub App](INSTALL.md#method-5-run-as-a-github-app), the default configurations of a pre-built repo will be initially loaded. +When running PR-Agent from [GitHub App](INSTALL.md#method-5-run-as-a-github-app), the default configurations from a pre-built repo will be initially loaded. #### GitHub app automatic tools The [github_app](pr_agent/settings/configuration.toml#L56) section defines GitHub app specific configurations. From 544bac70109fdaf848abb9dd28fb3ac64d7e4416 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Sat, 2 Sep 2023 09:43:46 +0300 Subject: [PATCH 19/22] update README.md --- Usage.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Usage.md b/Usage.md index 329bba54..12ff23aa 100644 --- a/Usage.md +++ b/Usage.md @@ -1,5 +1,13 @@ ## Usage guide +### Table of Contents +- [Introduction](#introduction) +- [Working from a local repo (CLI)](#working-from-a-local-repo-cli) +- [Online usage](#online-usage) +- [Working with GitHub App](#working-with-github-app) +- [Working with GitHub Action](#working-with-github-action) +- [Appendix - additional configurations walkthrough](#appendix---additional-configurations-walkthrough) + ### Introduction There are 3 basic ways to invoke CodiumAI PR-Agent: From 0203086aac2bdb12bc8bf858cdafdbe37bd004f0 Mon Sep 17 00:00:00 2001 From: Phill Zarfos Date: Sat, 2 Sep 2023 15:39:57 -0400 Subject: [PATCH 20/22] removed duplicate swift statement --- pr_agent/git_providers/git_provider.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pr_agent/git_providers/git_provider.py b/pr_agent/git_providers/git_provider.py index 4651d47d..330590a1 100644 --- a/pr_agent/git_providers/git_provider.py +++ b/pr_agent/git_providers/git_provider.py @@ -161,7 +161,6 @@ def get_main_pr_language(languages, files) -> str: most_common_extension == 'scala' and top_language == 'scala' or \ most_common_extension == 'kt' and top_language == 'kotlin' or \ most_common_extension == 'pl' and top_language == 'perl' or \ - most_common_extension == 'swift' and top_language == 'swift' or \ most_common_extension == top_language: main_language_str = top_language From 916d7c236ed167028b1149f8e2407b8b77fb57a4 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Sun, 3 Sep 2023 11:16:20 +0300 Subject: [PATCH 21/22] update README.md --- INSTALL.md | 8 ++++---- README.md | 30 +++++++++++++++--------------- Usage.md | 14 +++++++------- 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index 37bee57e..74368ac0 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -81,10 +81,10 @@ chmod 600 pr_agent/settings/.secrets.toml ``` export PYTHONPATH=[$PYTHONPATH:] -python pr_agent/cli.py --pr_url review -python pr_agent/cli.py --pr_url ask -python pr_agent/cli.py --pr_url describe -python pr_agent/cli.py --pr_url improve +python pr_agent/cli.py --pr_url /review +python pr_agent/cli.py --pr_url /ask +python pr_agent/cli.py --pr_url /describe +python pr_agent/cli.py --pr_url /improve ``` --- diff --git a/README.md b/README.md index cdd2688f..f946a59c 100644 --- a/README.md +++ b/README.md @@ -17,17 +17,20 @@ Making pull requests less painful with an AI agent CodiumAI `PR-Agent` is an open-source tool aiming to help developers review pull requests faster and more efficiently. It automatically analyzes the pull request and can provide several types of PR feedback: -**Auto-Description**: Automatically generating [PR description](https://github.com/Codium-ai/pr-agent/pull/229#issue-1860711415) - title, type, summary, code walkthrough and labels. +**Auto Description (/describe)**: Automatically generating [PR description](https://github.com/Codium-ai/pr-agent/pull/229#issue-1860711415) - title, type, summary, code walkthrough and labels. \ -**Auto Review**: [Adjustable feedback](https://github.com/Codium-ai/pr-agent/pull/229#issuecomment-1695022908) about the PR main theme, type, relevant tests, security issues, score, and various suggestions for the PR content. +**Auto Review (/review)**: [Adjustable feedback](https://github.com/Codium-ai/pr-agent/pull/229#issuecomment-1695022908) about the PR main theme, type, relevant tests, security issues, score, and various suggestions for the PR content. \ -**Question Answering**: Answering [free-text questions](https://github.com/Codium-ai/pr-agent/pull/229#issuecomment-1695021332) about the PR. +**Question Answering (/ask ...)**: Answering [free-text questions](https://github.com/Codium-ai/pr-agent/pull/229#issuecomment-1695021332) about the PR. \ -**Code Suggestions**: [Committable code suggestions](https://github.com/Codium-ai/pr-agent/pull/229#discussion_r1306919276) for improving the PR. +**Code Suggestions (/improve)**: [Committable code suggestions](https://github.com/Codium-ai/pr-agent/pull/229#discussion_r1306919276) for improving the PR. \ -**Update Changelog**: Automatically updating the CHANGELOG.md file with the [PR changes](https://github.com/Codium-ai/pr-agent/pull/168#discussion_r1282077645). +**Update Changelog (/update_changelog)**: Automatically updating the CHANGELOG.md file with the [PR changes](https://github.com/Codium-ai/pr-agent/pull/168#discussion_r1282077645). -

Example results:

+ +See the [usage guide](./Usage.md) for instructions how to run the different tools from [CLI](./Usage.md#working-from-a-local-repo-cli), or by [online usage](./Usage.md#online-usage). + +

Example results:

/describe:

@@ -36,16 +39,13 @@ CodiumAI `PR-Agent` is an open-source tool aiming to help developers review pull

-[//]: # (

/review:

) -[//]: # (
) +

/review:

+
+

+ +

+
-[//]: # (

) - -[//]: # () - -[//]: # (

) - -[//]: # (
) [//]: # (

/reflect_and_review:

) [//]: # (
) diff --git a/Usage.md b/Usage.md index 12ff23aa..336de974 100644 --- a/Usage.md +++ b/Usage.md @@ -50,12 +50,12 @@ When running from your local repo (CLI), your local configuration file will be u Examples for invoking the different tools via the CLI: -- **Review**: `python cli.py --pr_url= review` -- **Describe**: `python cli.py --pr_url= describe` -- **Improve**: `python cli.py --pr_url= improve` -- **Ask**: `python cli.py --pr_url= ask "Write me a poem about this PR"` -- **Reflect**: `python cli.py --pr_url= reflect` -- **Update Changelog**: `python cli.py --pr_url= update_changelog` +- **Review**: `python cli.py --pr_url= /review` +- **Describe**: `python cli.py --pr_url= /describe` +- **Improve**: `python cli.py --pr_url= /improve` +- **Ask**: `python cli.py --pr_url= /ask "Write me a poem about this PR"` +- **Reflect**: `python cli.py --pr_url= /reflect` +- **Update Changelog**: `python cli.py --pr_url= /update_changelog` `` is the url of the relevant PR (for example: https://github.com/Codium-ai/pr-agent/pull/50). @@ -63,7 +63,7 @@ Examples for invoking the different tools via the CLI: (1) in addition to editing your local configuration file, you can also change any configuration value by adding it to the command line: ``` -python cli.py --pr_url= review --pr_reviewer.extra_instructions="focus on the file: ..." +python cli.py --pr_url= /review --pr_reviewer.extra_instructions="focus on the file: ..." ``` (2) You can print results locally, without publishing them, by setting in `configuration.toml`: From ae3d7067d353e3a890b163f6a908101dc771a915 Mon Sep 17 00:00:00 2001 From: Phill Zarfos Date: Sun, 3 Sep 2023 09:22:08 -0400 Subject: [PATCH 22/22] implemented 'improve' command for CodeCommit --- README.md | 4 +- pr_agent/git_providers/codecommit_client.py | 54 +++++++++++++++---- pr_agent/git_providers/codecommit_provider.py | 42 ++++++++++++--- tests/unittest/test_codecommit_client.py | 2 +- 4 files changed, 82 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index f946a59c..5bf7d52e 100644 --- a/README.md +++ b/README.md @@ -101,8 +101,8 @@ See the [usage guide](./Usage.md) for instructions how to run the different tool | TOOLS | Review | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | | | Ask | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | | Auto-Description | :white_check_mark: | :white_check_mark: | | :white_check_mark: | :white_check_mark: | -| | Improve Code | :white_check_mark: | :white_check_mark: | | | | -| | ⮑ Extended | :white_check_mark: | :white_check_mark: | | | | +| | Improve Code | :white_check_mark: | :white_check_mark: | | :white_check_mark: | | +| | ⮑ Extended | :white_check_mark: | :white_check_mark: | | :white_check_mark: | | | | Reflect and Review | :white_check_mark: | | | | :white_check_mark: | | | Update CHANGELOG.md | :white_check_mark: | | | | | | | | | | | | | diff --git a/pr_agent/git_providers/codecommit_client.py b/pr_agent/git_providers/codecommit_client.py index 6200340d..1112ee22 100644 --- a/pr_agent/git_providers/codecommit_client.py +++ b/pr_agent/git_providers/codecommit_client.py @@ -90,7 +90,11 @@ class CodeCommitClient: ): differences.extend(page.get("differences", [])) except botocore.exceptions.ClientError as e: - raise ValueError(f"Failed to retrieve differences from CodeCommit PR #{self.pr_num}") from e + if e.response["Error"]["Code"] == 'RepositoryDoesNotExistException': + raise ValueError(f"CodeCommit cannot retrieve differences: Repository does not exist: {repo_name}") from e + raise ValueError(f"CodeCommit cannot retrieve differences for {source_commit}..{destination_commit}") from e + except Exception as e: + raise ValueError(f"CodeCommit cannot retrieve differences for {source_commit}..{destination_commit}") from e output = [] for json in differences: @@ -122,6 +126,8 @@ class CodeCommitClient: try: response = self.boto_client.get_file(repositoryName=repo_name, commitSpecifier=sha_hash, filePath=file_path) except botocore.exceptions.ClientError as e: + if e.response["Error"]["Code"] == 'RepositoryDoesNotExistException': + raise ValueError(f"CodeCommit cannot retrieve PR: Repository does not exist: {repo_name}") from e # if the file does not exist, but is flagged as optional, then return an empty string if optional and e.response["Error"]["Code"] == 'FileDoesNotExistException': return "" @@ -133,11 +139,12 @@ class CodeCommitClient: return response.get("fileContent", "") - def get_pr(self, pr_number: int): + def get_pr(self, repo_name: str, pr_number: int): """ Get a information about a CodeCommit PR. Args: + - repo_name: Name of the repository - pr_number: The PR number you are requesting Returns: @@ -155,6 +162,8 @@ class CodeCommitClient: except botocore.exceptions.ClientError as e: if e.response["Error"]["Code"] == 'PullRequestDoesNotExistException': raise ValueError(f"CodeCommit cannot retrieve PR: PR number does not exist: {pr_number}") from e + if e.response["Error"]["Code"] == 'RepositoryDoesNotExistException': + raise ValueError(f"CodeCommit cannot retrieve PR: Repository does not exist: {repo_name}") from e raise ValueError(f"CodeCommit cannot retrieve PR: {pr_number}: boto client error") from e except Exception as e: raise ValueError(f"CodeCommit cannot retrieve PR: {pr_number}") from e @@ -201,7 +210,7 @@ class CodeCommitClient: except Exception as e: raise ValueError(f"Error calling publish_description") from e - def publish_comment(self, repo_name: str, pr_number: int, destination_commit: str, source_commit: str, comment: str): + def publish_comment(self, repo_name: str, pr_number: int, destination_commit: str, source_commit: str, comment: str, annotation_file: str = None, annotation_line: int = None): """ Publish a comment to a pull request @@ -210,7 +219,13 @@ class CodeCommitClient: - pr_number: number of the pull request - destination_commit: The commit hash you want to merge into (the "before" hash) (usually on the main or master branch) - source_commit: The commit hash of the code you are adding (the "after" branch) - - pr_comment: comment + - comment: The comment you want to publish + - annotation_file: The file you want to annotate (optional) + - annotation_line: The line number you want to annotate (optional) + + Comment annotations for CodeCommit are different than GitHub. + CodeCommit only designates the starting line number for the comment. + It does not support the ending line number to highlight a range of lines. Returns: - None @@ -223,13 +238,30 @@ class CodeCommitClient: self._connect_boto_client() try: - self.boto_client.post_comment_for_pull_request( - pullRequestId=str(pr_number), - repositoryName=repo_name, - beforeCommitId=destination_commit, - afterCommitId=source_commit, - content=comment, - ) + # If the comment has code annotations, + # then set the file path and line number in the location dictionary + if annotation_file and annotation_line: + self.boto_client.post_comment_for_pull_request( + pullRequestId=str(pr_number), + repositoryName=repo_name, + beforeCommitId=destination_commit, + afterCommitId=source_commit, + content=comment, + location={ + "filePath": annotation_file, + "filePosition": annotation_line, + "relativeFileVersion": "AFTER", + }, + ) + else: + # The comment does not have code annotations + self.boto_client.post_comment_for_pull_request( + pullRequestId=str(pr_number), + repositoryName=repo_name, + beforeCommitId=destination_commit, + afterCommitId=source_commit, + content=comment, + ) except botocore.exceptions.ClientError as e: if e.response["Error"]["Code"] == 'RepositoryDoesNotExistException': raise ValueError(f"Repository does not exist: {repo_name}") from e diff --git a/pr_agent/git_providers/codecommit_provider.py b/pr_agent/git_providers/codecommit_provider.py index d43409c3..1f570a1a 100644 --- a/pr_agent/git_providers/codecommit_provider.py +++ b/pr_agent/git_providers/codecommit_provider.py @@ -180,10 +180,37 @@ class CodeCommitProvider(GitProvider): comment=pr_comment, ) except Exception as e: - raise ValueError(f"CodeCommit Cannot post comment for PR: {self.pr_num}") from e + raise ValueError(f"CodeCommit Cannot publish comment for PR: {self.pr_num}") from e def publish_code_suggestions(self, code_suggestions: list) -> bool: - return [""] # not implemented yet + counter = 1 + for suggestion in code_suggestions: + # Verify that each suggestion has the required keys + if not all(key in suggestion for key in ["body", "relevant_file", "relevant_lines_start"]): + logging.warning(f"Skipping code suggestion #{counter}: Each suggestion must have 'body', 'relevant_file', 'relevant_lines_start' keys") + continue + + # Publish the code suggestion to CodeCommit + try: + logging.debug(f"Code Suggestion #{counter} in file: {suggestion['relevant_file']}: {suggestion['relevant_lines_start']}") + self.codecommit_client.publish_comment( + repo_name=self.repo_name, + pr_number=self.pr_num, + destination_commit=self.pr.destination_commit, + source_commit=self.pr.source_commit, + comment=suggestion["body"], + annotation_file=suggestion["relevant_file"], + annotation_line=suggestion["relevant_lines_start"], + ) + except Exception as e: + raise ValueError(f"CodeCommit Cannot publish code suggestions for PR: {self.pr_num}") from e + + counter += 1 + + # The calling function passes in a list of code suggestions, and this function publishes each suggestion one at a time. + # If we were to return False here, the calling function will attempt to publish the same list of code suggestions again, one at a time. + # Since this function publishes the suggestions one at a time anyway, we always return True here to avoid the retry. + return True def publish_labels(self, labels): return [""] # not implemented yet @@ -195,6 +222,7 @@ class CodeCommitProvider(GitProvider): return "" # not implemented yet def publish_inline_comment(self, body: str, relevant_file: str, relevant_line_in_file: str): + # https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/codecommit/client/post_comment_for_compared_commit.html raise NotImplementedError("CodeCommit provider does not support publishing inline comments yet") def create_inline_comment(self, body: str, relevant_file: str, relevant_line_in_file: str): @@ -255,9 +283,11 @@ class CodeCommitProvider(GitProvider): return self.codecommit_client.get_file(self.repo_name, settings_filename, self.pr.source_commit, optional=True) def add_eyes_reaction(self, issue_comment_id: int) -> Optional[int]: + logging.info("CodeCommit provider does not support eyes reaction yet") return True def remove_reaction(self, issue_comment_id: int, reaction_id: int) -> bool: + logging.info("CodeCommit provider does not support removing reactions yet") return True @staticmethod @@ -315,16 +345,16 @@ class CodeCommitProvider(GitProvider): return re.match(r"^[a-z]{2}-(gov-)?[a-z]+-\d\.console\.aws\.amazon\.com$", hostname) is not None def _get_pr(self): - response = self.codecommit_client.get_pr(self.pr_num) + response = self.codecommit_client.get_pr(self.repo_name, self.pr_num) if len(response.targets) == 0: raise ValueError(f"No files found in CodeCommit PR: {self.pr_num}") - # TODO: implement support for multiple commits in one CodeCommit PR - # for now, we are only using the first commit in the PR + # TODO: implement support for multiple targets in one CodeCommit PR + # for now, we are only using the first target in the PR if len(response.targets) > 1: logging.warning( - "Multiple commits in one PR is not supported for CodeCommit yet. Continuing, using the first commit only..." + "Multiple targets in one PR is not supported for CodeCommit yet. Continuing, using the first target only..." ) # Return our object that mimics PullRequest class from the PyGithub library diff --git a/tests/unittest/test_codecommit_client.py b/tests/unittest/test_codecommit_client.py index 5d09bdd1..0aa1ffa6 100644 --- a/tests/unittest/test_codecommit_client.py +++ b/tests/unittest/test_codecommit_client.py @@ -125,7 +125,7 @@ class TestCodeCommitProvider: } } - pr = api.get_pr(321) + pr = api.get_pr("my_test_repo", 321) assert pr.title == "My PR" assert pr.description == "My PR description"