From f9e4c2b098406afd8ea807e2abfd75d837eba20a Mon Sep 17 00:00:00 2001 From: Krystal Boozel <139939801+Kryslynn93@users.noreply.github.com> Date: Mon, 23 Oct 2023 21:34:12 -0400 Subject: [PATCH 01/10] Update configuration.toml --- 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 6f44bc53..97d92261 100644 --- a/pr_agent/settings/configuration.toml +++ b/pr_agent/settings/configuration.toml @@ -123,4 +123,4 @@ max_issues_to_scan = 500 [pinecone] # fill and place in .secrets.toml #api_key = ... -# environment = "gcp-starter" \ No newline at end of file +# environment = "gcp-starter" From ec673214c88bc15259a218c08ec1479901fdd2b6 Mon Sep 17 00:00:00 2001 From: Ori Kotek Date: Thu, 26 Oct 2023 11:18:07 +0300 Subject: [PATCH 02/10] Update INSTALL.md --- INSTALL.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/INSTALL.md b/INSTALL.md index b1e2c486..42a16ea6 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -396,7 +396,9 @@ pipelines: OPENAI_API_KEY: BITBUCKET_BEARER_TOKEN: -You can get a Bitbucket token for your repository by following Repository Settings -> Security -> Access Tokens +You can get a Bitbucket token for your repository by following Repository Settings -> Security -> Access Tokens. + +Please contact if you're interested in a hosted BitBucket app solution that provides full functionality including PR reviews and comment handling. It's based on the [bitbucket_app.py](https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/git_providers/bitbucket_provider.py) implmentation. ======= From b6c9e01a59df7a921c179fffcba2d073111abe7d Mon Sep 17 00:00:00 2001 From: mrT23 Date: Thu, 26 Oct 2023 11:51:32 +0300 Subject: [PATCH 03/10] readme --- INSTALL.md | 52 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index 42a16ea6..ebe80cdb 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -8,18 +8,25 @@ 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 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) -- [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) +- [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 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) + +GitLab specific methods: +- [un 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) +- [Run on a hosted app](INSTALL.md#run-on-a-hosted-bitbucket-app) --- -### Method 1: Use Docker image (no installation required) +### Use Docker image (no installation required) To request a review for a PR, or ask a question about a PR, you can run directly from the Docker image. Here's how: @@ -63,7 +70,7 @@ Possible questions you can ask include: --- -### Method 2: Run from source +### Run from source 1. Clone this repository: @@ -97,7 +104,7 @@ python3 -m pr_agent.cli --pr_url improve --- -### Method 3: Run as a GitHub Action +### Run as a GitHub Action You can use our pre-built Github Action Docker image to run PR-Agent as a Github Action. @@ -167,8 +174,8 @@ When you open your next PR, you should see a comment from `github-actions` bot w --- -### Method 4: Run as a polling server -Request reviews by tagging your Github user on a PR +### Run as a polling server +Request reviews by tagging your GitHub user on a PR Follow steps 1-3 of method 2. Run the following command to start the server: @@ -179,7 +186,7 @@ python pr_agent/servers/github_polling.py --- -### Method 5: Run as a GitHub App +### Run as a GitHub App Allowing you to automate the review process on your private or public repositories. 1. Create a GitHub App from the [Github Developer Portal](https://docs.github.com/en/developers/apps/creating-a-github-app). @@ -264,9 +271,9 @@ docker push codiumai/pr-agent:github_app # Push to your Docker repository > For more information please check out [CONFIGURATION.md](Usage.md#working-from-github-app-pre-built-repo) --- -### Method 6 - Deploy as a Lambda Function +### Deploy as a Lambda Function -1. Follow steps 1-5 of [Method 5](#method-5-run-as-a-github-app). +1. Follow steps 1-5 of [Method 5](#run-as-a-github-app). 2. Build a docker image that can be used as a lambda function ```shell docker buildx build --platform=linux/amd64 . -t codiumai/pr-agent:serverless -f docker/Dockerfile.lambda @@ -278,12 +285,12 @@ docker push codiumai/pr-agent:github_app # Push to your Docker repository ``` 4. Create a lambda function that uses the uploaded image. Set the lambda timeout to be at least 3m. 5. Configure the lambda function to have a Function URL. -6. Go back to steps 8-9 of [Method 5](#method-5-run-as-a-github-app) with the function url as your Webhook URL. +6. Go back to steps 8-9 of [Method 5](#run-as-a-github-app) with the function url as your Webhook URL. The Webhook URL would look like `https:///api/v1/github_webhooks` --- -### Method 7 - AWS CodeCommit Setup +### AWS CodeCommit Setup Not all features have been added to CodeCommit yet. As of right now, CodeCommit has been implemented to run the pr-agent CLI on the command line, using AWS credentials stored in environment variables. (More features will be added in the future.) The following is a set of instructions to have pr-agent do a review of your CodeCommit pull request from the command line: @@ -353,7 +360,7 @@ PYTHONPATH="/PATH/TO/PROJECTS/pr-agent" python pr_agent/cli.py \ --- -### Method 8 - Run a GitLab webhook server +### Run a GitLab webhook server 1. From the GitLab workspace or group, create an access token. Enable the "api" scope only. 2. Generate a random secret for your app, and save it for later. For example, you can use: @@ -372,7 +379,7 @@ In the "Trigger" section, check the ‘comments’ and ‘merge request events -### Method 9: Run as a Bitbucket Pipeline +### Run as a Bitbucket Pipeline You can use the Bitbucket Pipeline system to run PR-Agent on every pull request open or update. @@ -398,6 +405,9 @@ BITBUCKET_BEARER_TOKEN: You can get a Bitbucket token for your repository by following Repository Settings -> Security -> Access Tokens. + +### Run on a hosted Bitbucket app + Please contact if you're interested in a hosted BitBucket app solution that provides full functionality including PR reviews and comment handling. It's based on the [bitbucket_app.py](https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/git_providers/bitbucket_provider.py) implmentation. From c77cc1d6ed22160a9a8117db8dcb70302587ebdd Mon Sep 17 00:00:00 2001 From: mrT23 Date: Thu, 26 Oct 2023 11:56:03 +0300 Subject: [PATCH 04/10] readme --- README.md | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index f5bc474e..94a3675a 100644 --- a/README.md +++ b/README.md @@ -28,16 +28,14 @@ CodiumAI `PR-Agent` is an open-source tool aiming to help developers review pull \ ‣ **Update Changelog ([`/update_changelog`](./docs/UPDATE_CHANGELOG.md))**: Automatically updating the CHANGELOG.md file with the PR changes. \ -‣ **Find similar issue ([`/similar_issue`](./docs/SIMILAR_ISSUE.md))**: Automatically retrieves and presents similar issues +‣ **Find Similar Issue ([`/similar_issue`](./docs/SIMILAR_ISSUE.md))**: Automatically retrieves and presents similar issues \ ‣ **Add Documentation ([`/add_docs`](./docs/ADD_DOCUMENTATION.md))**: Automatically adds documentation to un-documented functions/classes in the PR. -See the [Usage Guide](./Usage.md) for instructions how to run the different tools from _CLI_, _online usage_, Or by _automatically triggering_ them when a new PR is opened. - +See the [Installation Guide](./INSTALL.md) for instructions how to install and run the tool on different platforms. +See the [Usage Guide](./Usage.md) for instructions how to run the different tools from _CLI_, _online usage_, or by _automatically triggering_ them when a new PR is opened. See the [Tools Guide](./docs/TOOLS_GUIDE.md) for detailed description of the different tools. -See the [Release notes](./RELEASE_NOTES.md) for updates on the latest changes. -

Example results:

/describe:

@@ -204,6 +202,9 @@ Here are some advantages of PR-Agent: - [x] Documentation (is the PR properly documented) - [ ] ... +See the [Release notes](./RELEASE_NOTES.md) for updates on the latest changes. + + ## Similar Projects - [CodiumAI - Meaningful tests for busy devs](https://github.com/Codium-ai/codiumai-vscode-release) (although various capabilities are much more advanced in the CodiumAI IDE plugins) @@ -211,7 +212,12 @@ Here are some advantages of PR-Agent: - [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) - + +## Data Privacy + +If you use self-host PR-Agent, e.g. via CLI running on your computer, with your OpenAI API key, it is between you and OpenAI. You can read their API data privacy policy here: +https://openai.com/enterprise-privacy + ## Links [![Join our Discord community](https://raw.githubusercontent.com/Codium-ai/codiumai-vscode-release/main/media/docs/Joincommunity.png)](https://discord.gg/kG35uSHDBc) From 726594600b4436d1a9c1c3615c66c1198c6d9d57 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Thu, 26 Oct 2023 12:10:14 +0300 Subject: [PATCH 05/10] readme --- INSTALL.md | 46 ++++++++++++++++++++++------------------------ README.md | 2 ++ Usage.md | 2 +- 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index ebe80cdb..3b0ebbe2 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -4,24 +4,25 @@ To get started with PR-Agent quickly, you first need to acquire two tokens: 1. An OpenAI key from [here](https://platform.openai.com/), with access to GPT-4. -2. A GitHub personal access token (classic) with the repo scope. +2. A GitHub\GitLab\BitBucket\... personal access token (classic) with the repo scope. There are several ways to use PR-Agent: -- [Use Docker image (no installation required)](INSTALL.md#use-docker-image-no-installation-required) +**Locally** +- [Using Docker image (no installation required)](INSTALL.md#use-docker-image-no-installation-required) - [Run from source](INSTALL.md#run-from-source) -GitHub specific methods: +**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) -GitLab specific methods: -- [un a GitLab webhook server](INSTALL.md#run-a-gitlab-webhook-server) +**GitLab specific methods** +- [Run a GitLab webhook server](INSTALL.md#run-a-gitlab-webhook-server) -BitBucket specific methods: +**BitBucket specific methods** - [Run as a Bitbucket Pipeline](INSTALL.md#run-as-a-bitbucket-pipeline) - [Run on a hosted app](INSTALL.md#run-on-a-hosted-bitbucket-app) --- @@ -34,12 +35,17 @@ To request a review for a PR, or ask a question about a PR, you can run directly For GitHub: ``` -docker run --rm -it -e OPENAI.KEY= -e GITHUB.USER_TOKEN= codiumai/pr-agent --pr_url review +docker run --rm -it -e OPENAI.KEY= -e GITHUB.USER_TOKEN= codiumai/pr-agent:latest --pr_url review ``` For GitLab: ``` -docker run --rm -it -e OPENAI.KEY= -e CONFIG.GIT_PROVIDER=gitlab -e GITLAB.PERSONAL_ACCESS_TOKEN= codiumai/pr-agent --pr_url review +docker run --rm -it -e OPENAI.KEY= -e CONFIG.GIT_PROVIDER=gitlab -e GITLAB.PERSONAL_ACCESS_TOKEN= codiumai/pr-agent:latest --pr_url review ``` +For BitBucker: +``` +docker run -e CONFIG.GIT_PROVIDER=bitbucket -e OPENAI.KEY=$OPENAI_API_KEY -e BITBUCKET.BEARER_TOKEN=$BITBUCKET_BEARER_TOKEN codiumai/pr-agent:latest --pr_url=https://bitbucket.org/$BITBUCKET_WORKSPACE/$BITBUCKET_REPO_SLUG/pull-requests/$BITBUCKET_PR_ID review +``` + For other git providers, update CONFIG.GIT_PROVIDER accordingly, and check the `pr_agent/settings/.secrets_template.toml` file for the environment variables expected names and values. 2. To ask a question about a PR, run the following command: @@ -49,24 +55,15 @@ docker run --rm -it -e OPENAI.KEY= -e GITHUB.USER_TOKEN= c ``` Note: If you want to ensure you're running a specific version of the Docker image, consider using the image's digest. The digest is a unique identifier for a specific version of an image. You can pull and run an image using its digest by referencing it like so: repository@sha256:digest. Always ensure you're using the correct and trusted digest for your operations. - -1. To request a review for a PR using a specific digest, run the following command: +For example, to request a review for a PR using a specific digest, run the following command: ```bash docker run --rm -it -e OPENAI.KEY= -e GITHUB.USER_TOKEN= codiumai/pr-agent@sha256:71b5ee15df59c745d352d84752d01561ba64b6d51327f97d46152f0c58a5f678 --pr_url review ``` -2. To ask a question about a PR using the same digest, run the following command: -```bash -docker run --rm -it -e OPENAI.KEY= -e GITHUB.USER_TOKEN= codiumai/pr-agent@sha256:71b5ee15df59c745d352d84752d01561ba64b6d51327f97d46152f0c58a5f678 --pr_url ask "" +in addition, you can use tags to pull a [specific released versions](./RELEASE_NOTES.md) of the image, for example: +``` +codiumai/pr-agent@v0.8 ``` - -Possible questions you can ask include: - -- What is the main theme of this PR? -- Is the PR ready for merge? -- What are the main changes in this PR? -- Should this PR be split into smaller parts? -- Can you compose a rhymed song about this PR? --- @@ -177,7 +174,8 @@ 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 of method 2. +Follow steps 1-3 of [the previous step](#run-as-a-github-app). + Run the following command to start the server: ``` @@ -267,8 +265,8 @@ docker push codiumai/pr-agent:github_app # Push to your Docker repository 9. Install the app by navigating to the "Install App" tab and selecting your desired repositories. > **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](Usage.md#working-from-github-app-pre-built-repo) +> However, you can override the default tool parameters by uploading a local configuration file `.pr_agent.toml`
+> For more information please check out the [USAGE GUIDE](./Usage.md#working-from-github-app-pre-built-repo) --- ### Deploy as a Lambda Function diff --git a/README.md b/README.md index 94a3675a..26cb77d1 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,9 @@ CodiumAI `PR-Agent` is an open-source tool aiming to help developers review pull ‣ **Add Documentation ([`/add_docs`](./docs/ADD_DOCUMENTATION.md))**: Automatically adds documentation to un-documented functions/classes in the PR. See the [Installation Guide](./INSTALL.md) for instructions how to install and run the tool on different platforms. + See the [Usage Guide](./Usage.md) for instructions how to run the different tools from _CLI_, _online usage_, or by _automatically triggering_ them when a new PR is opened. + See the [Tools Guide](./docs/TOOLS_GUIDE.md) for detailed description of the different tools.

Example results:

diff --git a/Usage.md b/Usage.md index 867ccc44..fc5d7b3b 100644 --- a/Usage.md +++ b/Usage.md @@ -12,7 +12,7 @@ ### Introduction -See the **[installation guide](/INSTALL.md)** for instructions on how to setup PR-Agent. After installation, there are three basic ways to invoke CodiumAI PR-Agent: +After [installation](/INSTALL.md), there are three 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 tools to run automatically when a new PR is opened From b8583c998d314f54f0cc72530277e8f4d10de5dd Mon Sep 17 00:00:00 2001 From: mrT23 Date: Thu, 26 Oct 2023 12:16:58 +0300 Subject: [PATCH 06/10] readme --- INSTALL.md | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index 3b0ebbe2..2ea8a75d 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -4,7 +4,7 @@ To get started with PR-Agent quickly, you first need to acquire two tokens: 1. An OpenAI key from [here](https://platform.openai.com/), with access to GPT-4. -2. A GitHub\GitLab\BitBucket\... personal access token (classic) with the repo scope. +2. A GitHub\GitLab\BitBucket personal access token (classic) with the repo scope. There are several ways to use PR-Agent: @@ -31,8 +31,6 @@ There are several ways to use PR-Agent: To request a review for a PR, or ask a question about a PR, you can run directly from the Docker image. Here's how: -1. To request a review for a PR, run the following command: - For GitHub: ``` docker run --rm -it -e OPENAI.KEY= -e GITHUB.USER_TOKEN= codiumai/pr-agent:latest --pr_url review @@ -41,26 +39,27 @@ For GitLab: ``` docker run --rm -it -e OPENAI.KEY= -e CONFIG.GIT_PROVIDER=gitlab -e GITLAB.PERSONAL_ACCESS_TOKEN= codiumai/pr-agent:latest --pr_url review ``` -For BitBucker: +For BitBucket: ``` docker run -e CONFIG.GIT_PROVIDER=bitbucket -e OPENAI.KEY=$OPENAI_API_KEY -e BITBUCKET.BEARER_TOKEN=$BITBUCKET_BEARER_TOKEN codiumai/pr-agent:latest --pr_url=https://bitbucket.org/$BITBUCKET_WORKSPACE/$BITBUCKET_REPO_SLUG/pull-requests/$BITBUCKET_PR_ID review ``` For other git providers, update CONFIG.GIT_PROVIDER accordingly, and check the `pr_agent/settings/.secrets_template.toml` file for the environment variables expected names and values. -2. To ask a question about a PR, run the following command: +Similarly, to ask a question about a PR, run the following command: ``` docker run --rm -it -e OPENAI.KEY= -e GITHUB.USER_TOKEN= codiumai/pr-agent --pr_url ask "" ``` -Note: If you want to ensure you're running a specific version of the Docker image, consider using the image's digest. -The digest is a unique identifier for a specific version of an image. You can pull and run an image using its digest by referencing it like so: repository@sha256:digest. Always ensure you're using the correct and trusted digest for your operations. -For example, to request a review for a PR using a specific digest, run the following command: + +A list of the relevant tools can be found in the [tools guide](./docs/TOOLS_GUIDE.md). + + +Note: If you want to ensure you're running a specific version of the Docker image, consider using the image's digest: ```bash docker run --rm -it -e OPENAI.KEY= -e GITHUB.USER_TOKEN= codiumai/pr-agent@sha256:71b5ee15df59c745d352d84752d01561ba64b6d51327f97d46152f0c58a5f678 --pr_url review ``` - -in addition, you can use tags to pull a [specific released versions](./RELEASE_NOTES.md) of the image, for example: +in addition, you can run a [specific released versions](./RELEASE_NOTES.md) of pr-agent, for example: ``` codiumai/pr-agent@v0.8 ``` @@ -97,6 +96,9 @@ python3 -m pr_agent.cli --pr_url review python3 -m pr_agent.cli --pr_url ask python3 -m pr_agent.cli --pr_url describe python3 -m pr_agent.cli --pr_url improve +python3 -m pr_agent.cli --pr_url add_docs +python3 -m pr_agent.cli --issue_url similar_issue +... ``` --- @@ -174,7 +176,7 @@ 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 of [the previous step](#run-as-a-github-app). +Follow [steps 1-3](#run-as-a-github-action) of the GitHub Action setup. Run the following command to start the server: @@ -266,7 +268,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 `.pr_agent.toml`
-> For more information please check out the [USAGE GUIDE](./Usage.md#working-from-github-app-pre-built-repo) +> For more information please check out the [USAGE GUIDE](./Usage.md#working-with-github-app) --- ### Deploy as a Lambda Function From f7666cb59aa5288844e278e25176cfde7219817d Mon Sep 17 00:00:00 2001 From: mrT23 Date: Fri, 27 Oct 2023 11:49:39 +0300 Subject: [PATCH 07/10] Update INSTALL.md --- INSTALL.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/INSTALL.md b/INSTALL.md index 2ea8a75d..ec6090b0 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -41,7 +41,7 @@ docker run --rm -it -e OPENAI.KEY= -e CONFIG.GIT_PROVIDER=gitlab -e GI ``` For BitBucket: ``` -docker run -e CONFIG.GIT_PROVIDER=bitbucket -e OPENAI.KEY=$OPENAI_API_KEY -e BITBUCKET.BEARER_TOKEN=$BITBUCKET_BEARER_TOKEN codiumai/pr-agent:latest --pr_url=https://bitbucket.org/$BITBUCKET_WORKSPACE/$BITBUCKET_REPO_SLUG/pull-requests/$BITBUCKET_PR_ID review +docker run --rm -it -e CONFIG.GIT_PROVIDER=bitbucket -e OPENAI.KEY=$OPENAI_API_KEY -e BITBUCKET.BEARER_TOKEN=$BITBUCKET_BEARER_TOKEN codiumai/pr-agent:latest --pr_url= review ``` For other git providers, update CONFIG.GIT_PROVIDER accordingly, and check the `pr_agent/settings/.secrets_template.toml` file for the environment variables expected names and values. From 638db96311e46068e4a7339a61bf48942423a078 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Sat, 28 Oct 2023 13:34:32 +0300 Subject: [PATCH 08/10] github action now also uses .pr_agent.toml --- pr_agent/git_providers/github_provider.py | 5 ++++- pr_agent/git_providers/utils.py | 1 + pr_agent/servers/github_action_runner.py | 11 +++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/pr_agent/git_providers/github_provider.py b/pr_agent/git_providers/github_provider.py index 7a47fbf5..f868e482 100644 --- a/pr_agent/git_providers/github_provider.py +++ b/pr_agent/git_providers/github_provider.py @@ -258,7 +258,10 @@ class GithubProvider(GitProvider): def get_repo_settings(self): try: - contents = self.repo_obj.get_contents(".pr_agent.toml", ref=self.pr.head.sha).decoded_content + # contents = self.repo_obj.get_contents(".pr_agent.toml", ref=self.pr.head.sha).decoded_content + + # more logical to take 'pr_agent.toml' from the default branch + contents = self.repo_obj.get_contents(".pr_agent.toml").decoded_content return contents except Exception: return "" diff --git a/pr_agent/git_providers/utils.py b/pr_agent/git_providers/utils.py index c8d80dfc..50fd3915 100644 --- a/pr_agent/git_providers/utils.py +++ b/pr_agent/git_providers/utils.py @@ -26,6 +26,7 @@ def apply_repo_settings(pr_url): section_dict[key] = value get_settings().unset(section) get_settings().set(section, section_dict, merge=False) + get_logger().info(f"Applying repo settings for section {section}, contents: {contents}") finally: if repo_settings_file: diff --git a/pr_agent/servers/github_action_runner.py b/pr_agent/servers/github_action_runner.py index e1a5e56a..344cc62c 100644 --- a/pr_agent/servers/github_action_runner.py +++ b/pr_agent/servers/github_action_runner.py @@ -5,6 +5,8 @@ import os from pr_agent.agent.pr_agent import PRAgent from pr_agent.config_loader import get_settings from pr_agent.git_providers import get_git_provider +from pr_agent.git_providers.utils import apply_repo_settings +from pr_agent.log import get_logger from pr_agent.tools.pr_code_suggestions import PRCodeSuggestions from pr_agent.tools.pr_description import PRDescription from pr_agent.tools.pr_reviewer import PRReviewer @@ -57,6 +59,15 @@ async def run_action(): # Handle pull request event if GITHUB_EVENT_NAME == "pull_request": action = event_payload.get("action") + + try: + get_logger().info("Applying repo settings") + pr_url = event_payload.get("pull_request", {}).get("html_url") + if pr_url: + apply_repo_settings(pr_url) + except Exception as e: + get_logger().info(f"github action: failed to apply repo settings: {e}") + if action in ["opened", "reopened"]: pr_url = event_payload.get("pull_request", {}).get("url") if pr_url: From d772213cfce31e7b9dc998c9e558acac88c53e30 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Sun, 29 Oct 2023 08:58:12 +0200 Subject: [PATCH 09/10] fix labels --- docs/GENERATE_CUSTOM_LABELS.md | 2 +- pr_agent/git_providers/github_provider.py | 5 ++-- pr_agent/settings/custom_labels.toml | 30 ++++++++++++----------- pr_agent/tools/pr_generate_labels.py | 2 +- pr_agent/tools/pr_reviewer.py | 2 +- 5 files changed, 22 insertions(+), 19 deletions(-) diff --git a/docs/GENERATE_CUSTOM_LABELS.md b/docs/GENERATE_CUSTOM_LABELS.md index 5c1743f4..25876fe0 100644 --- a/docs/GENERATE_CUSTOM_LABELS.md +++ b/docs/GENERATE_CUSTOM_LABELS.md @@ -3,7 +3,7 @@ The `generte_labels` tool scans the PR code changes, and given a list of labels It can be invoked manually by commenting on any PR: ``` -/generte_labels +/generate_labels ``` For example: diff --git a/pr_agent/git_providers/github_provider.py b/pr_agent/git_providers/github_provider.py index 7a47fbf5..494f2df7 100644 --- a/pr_agent/git_providers/github_provider.py +++ b/pr_agent/git_providers/github_provider.py @@ -258,9 +258,10 @@ class GithubProvider(GitProvider): def get_repo_settings(self): try: - contents = self.repo_obj.get_contents(".pr_agent.toml", ref=self.pr.head.sha).decoded_content + contents = self.repo_obj.get_contents(".pr_agent.toml").decoded_content return contents - except Exception: + except Exception as e: + # get_logger().exception(f"Failed to get repo settings, error: {e}") return "" def add_eyes_reaction(self, issue_comment_id: int) -> Optional[int]: diff --git a/pr_agent/settings/custom_labels.toml b/pr_agent/settings/custom_labels.toml index 8b1340f2..43e14b0e 100644 --- a/pr_agent/settings/custom_labels.toml +++ b/pr_agent/settings/custom_labels.toml @@ -1,16 +1,18 @@ +[config] enable_custom_labels=false -[custom_labels."Bug fix"] -description = "Fixes a bug in the code" -[custom_labels."Tests"] -description = "Adds or modifies tests" -[custom_labels."Bug fix with tests"] -description = "Fixes a bug in the code and adds or modifies tests" -[custom_labels."Refactoring"] -description = "Code refactoring without changing functionality" -[custom_labels."Enhancement"] -description = "Adds new features or functionality" -[custom_labels."Documentation"] -description = "Adds or modifies documentation" -[custom_labels."Other"] -description = "Other changes that do not fit in any of the above categories" \ No newline at end of file +## template for custom labels +#[custom_labels."Bug fix"] +#description = "Fixes a bug in the code" +#[custom_labels."Tests"] +#description = "Adds or modifies tests" +#[custom_labels."Bug fix with tests"] +#description = "Fixes a bug in the code and adds or modifies tests" +#[custom_labels."Refactoring"] +#description = "Code refactoring without changing functionality" +#[custom_labels."Enhancement"] +#description = "Adds new features or functionality" +#[custom_labels."Documentation"] +#description = "Adds or modifies documentation" +#[custom_labels."Other"] +#description = "Other changes that do not fit in any of the above categories" \ No newline at end of file diff --git a/pr_agent/tools/pr_generate_labels.py b/pr_agent/tools/pr_generate_labels.py index bf5b5f98..3fcccda0 100644 --- a/pr_agent/tools/pr_generate_labels.py +++ b/pr_agent/tools/pr_generate_labels.py @@ -45,7 +45,7 @@ class PRGenerateLabels: "commit_messages_str": self.git_provider.get_commit_messages(), "custom_labels": "", "custom_labels_examples": "", - "enable_custom_labels": get_settings().enable_custom_labels, + "enable_custom_labels": get_settings().config.enable_custom_labels, } # Initialize the token handler diff --git a/pr_agent/tools/pr_reviewer.py b/pr_agent/tools/pr_reviewer.py index 0eeb5578..78669d1a 100644 --- a/pr_agent/tools/pr_reviewer.py +++ b/pr_agent/tools/pr_reviewer.py @@ -64,7 +64,7 @@ class PRReviewer: "extra_instructions": get_settings().pr_reviewer.extra_instructions, "commit_messages_str": self.git_provider.get_commit_messages(), "custom_labels": "", - "enable_custom_labels": get_settings().enable_custom_labels, + "enable_custom_labels": get_settings().config.enable_custom_labels, } self.token_handler = TokenHandler( From 7374243d0b86171792d0a2f9f2ab8c827f0e25b1 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Sun, 29 Oct 2023 11:40:36 +0200 Subject: [PATCH 10/10] enable_custom_labels --- 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 a88ff336..4f0081fb 100644 --- a/pr_agent/tools/pr_description.py +++ b/pr_agent/tools/pr_description.py @@ -43,7 +43,7 @@ class PRDescription: "use_bullet_points": get_settings().pr_description.use_bullet_points, "extra_instructions": get_settings().pr_description.extra_instructions, "commit_messages_str": self.git_provider.get_commit_messages(), - "enable_custom_labels": get_settings().enable_custom_labels, + "enable_custom_labels": get_settings().config.enable_custom_labels, "custom_labels": "", "custom_labels_examples": "", }