From ce54a7b79ece3a2fcaee17db6dc81eb6c667f168 Mon Sep 17 00:00:00 2001 From: Itamar Friedman <108689937+coditamar@users.noreply.github.com> Date: Mon, 28 Aug 2023 22:08:08 +0300 Subject: [PATCH 01/10] Update README.md --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 47dca106..7bb4b47d 100644 --- a/README.md +++ b/README.md @@ -108,6 +108,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). 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 specificied 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: ..." ## Try it now @@ -177,7 +180,7 @@ Here are some advantages of PR-Agent: ## Similar Projects -- [CodiumAI - Meaningful tests for busy devs](https://github.com/Codium-ai/codiumai-vscode-release) +- [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) - [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) From edaeb99b43f01b496523145b58a86f5167da0bb5 Mon Sep 17 00:00:00 2001 From: Itamar Friedman <108689937+coditamar@users.noreply.github.com> Date: Mon, 28 Aug 2023 22:29:08 +0300 Subject: [PATCH 02/10] Update README.md type Co-authored-by: Tim Perkins --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7bb4b47d..65f1c8d6 100644 --- a/README.md +++ b/README.md @@ -108,7 +108,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). 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 specificied at run time when calling actions. Two examples: +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: ..." From f26264daf1d16703b4e549edb612c950b677632b Mon Sep 17 00:00:00 2001 From: Phill Zarfos Date: Tue, 29 Aug 2023 17:59:52 -0400 Subject: [PATCH 03/10] added describe command to CodeCommit --- INSTALL.md | 4 +- README.md | 2 +- pr_agent/git_providers/codecommit_client.py | 61 +++++++++--- pr_agent/git_providers/codecommit_provider.py | 99 +++++++++++++++++-- tests/unittest/test_codecommit_provider.py | 53 ++++++++++ 5 files changed, 199 insertions(+), 20 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index 88ad92bb..ba2547b1 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -309,7 +309,9 @@ Example IAM permissions to that user to allow access to CodeCommit: "codecommit:Get*", "codecommit:List*", "codecommit:PostComment*", - "codecommit:PutCommentReaction" + "codecommit:PutCommentReaction", + "codecommit:UpdatePullRequestDescription", + "codecommit:UpdatePullRequestTitle" ], "Resource": "*" } diff --git a/README.md b/README.md index 47dca106..faab0af1 100644 --- a/README.md +++ b/README.md @@ -80,7 +80,7 @@ CodiumAI `PR-Agent` is an open-source tool aiming to help developers review pull | 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: | | | +| | 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: | | | | diff --git a/pr_agent/git_providers/codecommit_client.py b/pr_agent/git_providers/codecommit_client.py index c1cfa763..6200340d 100644 --- a/pr_agent/git_providers/codecommit_client.py +++ b/pr_agent/git_providers/codecommit_client.py @@ -64,7 +64,7 @@ class CodeCommitClient: """ Get the differences between two commits in CodeCommit. - Parameters: + Args: - repo_name: Name of the repository - destination_commit: Commit hash you want to merge into (the "before" hash) (usually on the main or master branch) - source_commit: Commit hash of the code you are adding (the "after" branch) @@ -73,8 +73,8 @@ class CodeCommitClient: - List of CodeCommitDifferencesResponse objects Boto3 Documentation: - aws codecommit get-differences - https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/codecommit/client/get_differences.html + - aws codecommit get-differences + - https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/codecommit/client/get_differences.html """ if self.boto_client is None: self._connect_boto_client() @@ -101,7 +101,7 @@ class CodeCommitClient: """ Retrieve a file from CodeCommit. - Parameters: + Args: - repo_name: Name of the repository - file_path: Path to the file you are retrieving - sha_hash: Commit hash of the file you are retrieving @@ -110,8 +110,8 @@ class CodeCommitClient: - File contents Boto3 Documentation: - aws codecommit get_file - https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/codecommit/client/get_file.html + - aws codecommit get_file + - https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/codecommit/client/get_file.html """ if not file_path: return "" @@ -137,15 +137,15 @@ class CodeCommitClient: """ Get a information about a CodeCommit PR. - Parameters: + Args: - pr_number: The PR number you are requesting Returns: - CodeCommitPullRequestResponse object Boto3 Documentation: - aws codecommit get_pull_request - https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/codecommit/client/get_pull_request.html + - aws codecommit get_pull_request + - https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/codecommit/client/get_pull_request.html """ if self.boto_client is None: self._connect_boto_client() @@ -164,11 +164,48 @@ class CodeCommitClient: return CodeCommitPullRequestResponse(response.get("pullRequest", {})) + def publish_description(self, pr_number: int, pr_title: str, pr_body: str): + """ + Set the title and description on a pull request + + Args: + - pr_number: the AWS CodeCommit pull request number + - pr_title: title of the pull request + - pr_body: body of the pull request + + Returns: + - None + + Boto3 Documentation: + - aws codecommit update_pull_request_title + - https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/codecommit/client/update_pull_request_title.html + - aws codecommit update_pull_request_description + - https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/codecommit/client/update_pull_request_description.html + """ + if self.boto_client is None: + self._connect_boto_client() + + try: + self.boto_client.update_pull_request_title(pullRequestId=str(pr_number), title=pr_title) + self.boto_client.update_pull_request_description(pullRequestId=str(pr_number), description=pr_body) + except botocore.exceptions.ClientError as e: + if e.response["Error"]["Code"] == 'PullRequestDoesNotExistException': + raise ValueError(f"PR number does not exist: {pr_number}") from e + if e.response["Error"]["Code"] == 'InvalidTitleException': + raise ValueError(f"Invalid title for PR number: {pr_number}") from e + if e.response["Error"]["Code"] == 'InvalidDescriptionException': + raise ValueError(f"Invalid description for PR number: {pr_number}") from e + if e.response["Error"]["Code"] == 'PullRequestAlreadyClosedException': + raise ValueError(f"PR is already closed: PR number: {pr_number}") from e + raise ValueError(f"Boto3 client error calling publish_description") from e + 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): """ Publish a comment to a pull request - Parameters: + Args: - repo_name: name of the repository - 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) @@ -179,8 +216,8 @@ class CodeCommitClient: - None Boto3 Documentation: - aws codecommit post_comment_for_pull_request - https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/codecommit/client/post_comment_for_pull_request.html + - aws codecommit post_comment_for_pull_request + - https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/codecommit/client/post_comment_for_pull_request.html """ if self.boto_client is None: self._connect_boto_client() diff --git a/pr_agent/git_providers/codecommit_provider.py b/pr_agent/git_providers/codecommit_provider.py index a747e7f2..d43409c3 100644 --- a/pr_agent/git_providers/codecommit_provider.py +++ b/pr_agent/git_providers/codecommit_provider.py @@ -1,5 +1,6 @@ import logging import os +import re from collections import Counter from typing import List, Optional, Tuple from urllib.parse import urlparse @@ -153,17 +154,27 @@ class CodeCommitProvider(GitProvider): return self.diff_files def publish_description(self, pr_title: str, pr_body: str): - return "" # not implemented yet + try: + self.codecommit_client.publish_description( + pr_number=self.pr_num, + pr_title=pr_title, + pr_body=CodeCommitProvider._add_additional_newlines(pr_body), + ) + except Exception as e: + raise ValueError(f"CodeCommit Cannot publish description for PR: {self.pr_num}") from e def publish_comment(self, pr_comment: str, is_temporary: bool = False): if is_temporary: logging.info(pr_comment) return + pr_comment = CodeCommitProvider._remove_markdown_html(pr_comment) + pr_comment = CodeCommitProvider._add_additional_newlines(pr_comment) + try: self.codecommit_client.publish_comment( repo_name=self.repo_name, - pr_number=str(self.pr_num), + pr_number=self.pr_num, destination_commit=self.pr.destination_commit, source_commit=self.pr.source_commit, comment=pr_comment, @@ -200,7 +211,7 @@ class CodeCommitProvider(GitProvider): Returns a dictionary of languages, containing the percentage of each language used in the PR. Returns: - dict: A dictionary where each key is a language name and the corresponding value is the percentage of that language in the PR. + - dict: A dictionary where each key is a language name and the corresponding value is the percentage of that language in the PR. """ commit_files = self.get_files() filenames = [ item.filename for item in commit_files ] @@ -251,11 +262,20 @@ class CodeCommitProvider(GitProvider): @staticmethod def _parse_pr_url(pr_url: str) -> Tuple[str, int]: + """ + Parse the CodeCommit PR URL and return the repository name and PR number. + + Args: + - pr_url: the full AWS CodeCommit pull request URL + + Returns: + - Tuple[str, int]: A tuple containing the repository name and PR number. + """ # Example PR URL: # https://us-east-1.console.aws.amazon.com/codesuite/codecommit/repositories/__MY_REPO__/pull-requests/123456" parsed_url = urlparse(pr_url) - if "us-east-1.console.aws.amazon.com" not in parsed_url.netloc: + if not CodeCommitProvider._is_valid_codecommit_hostname(parsed_url.netloc): raise ValueError(f"The provided URL is not a valid CodeCommit URL: {pr_url}") path_parts = parsed_url.path.strip("/").split("/") @@ -278,6 +298,22 @@ class CodeCommitProvider(GitProvider): return repo_name, pr_number + @staticmethod + def _is_valid_codecommit_hostname(hostname: str) -> bool: + """ + Check if the provided hostname is a valid AWS CodeCommit hostname. + + This is not an exhaustive check of AWS region names, + but instead uses a regex to check for matching AWS region patterns. + + Args: + - hostname: the hostname to check + + Returns: + - bool: True if the hostname is valid, False otherwise. + """ + 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) @@ -306,13 +342,52 @@ class CodeCommitProvider(GitProvider): return "" # not implemented yet @staticmethod - def _get_edit_type(codecommit_change_type): + def _add_additional_newlines(body: str) -> str: + """ + Replace single newlines in a PR body with double newlines. + + CodeCommit Markdown does not seem to render as well as GitHub Markdown, + so we add additional newlines to the PR body to make it more readable in CodeCommit. + + Args: + - body: the PR body + + Returns: + - str: the PR body with the double newlines added + """ + return re.sub(r'(? str: + """ + Remove the HTML tags from a PR comment. + + CodeCommit Markdown does not seem to render as well as GitHub Markdown, + so we remove the HTML tags from the PR comment to make it more readable in CodeCommit. + + Args: + - comment: the PR comment + + Returns: + - str: the PR comment with the HTML tags removed + """ + comment = comment.replace("
", "") + comment = comment.replace("
", "") + comment = comment.replace("", "") + comment = comment.replace("", "") + return comment + + @staticmethod + def _get_edit_type(codecommit_change_type: str): """ Convert the CodeCommit change type string to the EDIT_TYPE enum. The CodeCommit change type string is returned from the get_differences SDK method. + Args: + - codecommit_change_type: the CodeCommit change type string + Returns: - An EDIT_TYPE enum representing the modified, added, deleted, or renamed file in the PR diff. + - An EDIT_TYPE enum representing the modified, added, deleted, or renamed file in the PR diff. """ t = codecommit_change_type.upper() edit_type = None @@ -333,6 +408,12 @@ class CodeCommitProvider(GitProvider): The returned extensions will include the dot "." prefix, to accommodate for the dots in the existing language_extension_map settings. Filenames with no extension will return an empty string for the extension. + + Args: + - filenames: a list of filenames + + Returns: + - list: A list of file extensions, including the dot "." prefix. """ extensions = [] for filename in filenames: @@ -349,6 +430,12 @@ class CodeCommitProvider(GitProvider): Return a dictionary containing the programming language name (as the key), and the percentage that language is used (as the value), given a list of file extensions. + + Args: + - extensions: a list of file extensions + + Returns: + - dict: A dictionary where each key is a language name and the corresponding value is the percentage of that language in the PR. """ total_files = len(extensions) if total_files == 0: diff --git a/tests/unittest/test_codecommit_provider.py b/tests/unittest/test_codecommit_provider.py index e35f7250..9de7c45c 100644 --- a/tests/unittest/test_codecommit_provider.py +++ b/tests/unittest/test_codecommit_provider.py @@ -26,11 +26,48 @@ class TestCodeCommitFile: class TestCodeCommitProvider: def test_parse_pr_url(self): + # Test that the _parse_pr_url() function can extract the repo name and PR number from a CodeCommit URL url = "https://us-east-1.console.aws.amazon.com/codesuite/codecommit/repositories/my_test_repo/pull-requests/321" repo_name, pr_number = CodeCommitProvider._parse_pr_url(url) assert repo_name == "my_test_repo" assert pr_number == 321 + def test_is_valid_codecommit_hostname(self): + # Test the various AWS regions + assert CodeCommitProvider._is_valid_codecommit_hostname("af-south-1.console.aws.amazon.com") + assert CodeCommitProvider._is_valid_codecommit_hostname("ap-east-1.console.aws.amazon.com") + assert CodeCommitProvider._is_valid_codecommit_hostname("ap-northeast-1.console.aws.amazon.com") + assert CodeCommitProvider._is_valid_codecommit_hostname("ap-northeast-2.console.aws.amazon.com") + assert CodeCommitProvider._is_valid_codecommit_hostname("ap-northeast-3.console.aws.amazon.com") + assert CodeCommitProvider._is_valid_codecommit_hostname("ap-south-1.console.aws.amazon.com") + assert CodeCommitProvider._is_valid_codecommit_hostname("ap-south-2.console.aws.amazon.com") + assert CodeCommitProvider._is_valid_codecommit_hostname("ap-southeast-1.console.aws.amazon.com") + assert CodeCommitProvider._is_valid_codecommit_hostname("ap-southeast-2.console.aws.amazon.com") + assert CodeCommitProvider._is_valid_codecommit_hostname("ap-southeast-3.console.aws.amazon.com") + assert CodeCommitProvider._is_valid_codecommit_hostname("ap-southeast-4.console.aws.amazon.com") + assert CodeCommitProvider._is_valid_codecommit_hostname("ca-central-1.console.aws.amazon.com") + assert CodeCommitProvider._is_valid_codecommit_hostname("eu-central-1.console.aws.amazon.com") + assert CodeCommitProvider._is_valid_codecommit_hostname("eu-central-2.console.aws.amazon.com") + assert CodeCommitProvider._is_valid_codecommit_hostname("eu-north-1.console.aws.amazon.com") + assert CodeCommitProvider._is_valid_codecommit_hostname("eu-south-1.console.aws.amazon.com") + assert CodeCommitProvider._is_valid_codecommit_hostname("eu-south-2.console.aws.amazon.com") + assert CodeCommitProvider._is_valid_codecommit_hostname("eu-west-1.console.aws.amazon.com") + assert CodeCommitProvider._is_valid_codecommit_hostname("eu-west-2.console.aws.amazon.com") + assert CodeCommitProvider._is_valid_codecommit_hostname("eu-west-3.console.aws.amazon.com") + assert CodeCommitProvider._is_valid_codecommit_hostname("il-central-1.console.aws.amazon.com") + assert CodeCommitProvider._is_valid_codecommit_hostname("me-central-1.console.aws.amazon.com") + assert CodeCommitProvider._is_valid_codecommit_hostname("me-south-1.console.aws.amazon.com") + assert CodeCommitProvider._is_valid_codecommit_hostname("sa-east-1.console.aws.amazon.com") + assert CodeCommitProvider._is_valid_codecommit_hostname("us-east-1.console.aws.amazon.com") + assert CodeCommitProvider._is_valid_codecommit_hostname("us-east-2.console.aws.amazon.com") + assert CodeCommitProvider._is_valid_codecommit_hostname("us-gov-east-1.console.aws.amazon.com") + assert CodeCommitProvider._is_valid_codecommit_hostname("us-gov-west-1.console.aws.amazon.com") + assert CodeCommitProvider._is_valid_codecommit_hostname("us-west-1.console.aws.amazon.com") + assert CodeCommitProvider._is_valid_codecommit_hostname("us-west-2.console.aws.amazon.com") + # Test non-AWS regions + assert not CodeCommitProvider._is_valid_codecommit_hostname("no-such-region.console.aws.amazon.com") + assert not CodeCommitProvider._is_valid_codecommit_hostname("console.aws.amazon.com") + # Test that an error is raised when an invalid CodeCommit URL is provided to the set_pr() method of the CodeCommitProvider class. # Generated by CodiumAI def test_invalid_codecommit_url(self): @@ -106,6 +143,7 @@ class TestCodeCommitProvider: assert percentages == {} def test_get_edit_type(self): + # Test that the _get_edit_type() function can convert a CodeCommit letter to an EDIT_TYPE enum assert CodeCommitProvider._get_edit_type("A") == EDIT_TYPE.ADDED assert CodeCommitProvider._get_edit_type("D") == EDIT_TYPE.DELETED assert CodeCommitProvider._get_edit_type("M") == EDIT_TYPE.MODIFIED @@ -117,3 +155,18 @@ class TestCodeCommitProvider: assert CodeCommitProvider._get_edit_type("r") == EDIT_TYPE.RENAMED assert CodeCommitProvider._get_edit_type("X") is None + + def test_add_additional_newlines(self): + # a short string to test adding double newlines + input = "abc\ndef\n\n___\nghi\njkl\nmno\n\npqr\n" + expect = "abc\n\ndef\n\n___\n\nghi\n\njkl\n\nmno\n\npqr\n\n" + assert CodeCommitProvider._add_additional_newlines(input) == expect + # a test example from a real PR + input = "## PR Type:\nEnhancement\n\n___\n## PR Description:\nThis PR introduces a new feature to the script, allowing users to filter servers by name.\n\n___\n## PR Main Files Walkthrough:\n`foo`: The foo script has been updated to include a new command line option `-f` or `--filter`.\n`bar`: The bar script has been updated to list stopped servers.\n" + expect = "## PR Type:\n\nEnhancement\n\n___\n\n## PR Description:\n\nThis PR introduces a new feature to the script, allowing users to filter servers by name.\n\n___\n\n## PR Main Files Walkthrough:\n\n`foo`: The foo script has been updated to include a new command line option `-f` or `--filter`.\n\n`bar`: The bar script has been updated to list stopped servers.\n\n" + assert CodeCommitProvider._add_additional_newlines(input) == expect + + def test_remove_markdown_html(self): + input = "## PR Feedback\n
Code feedback:\nfile foo\n\n" + expect = "## PR Feedback\nCode feedback:\nfile foo\n\n" + assert CodeCommitProvider._remove_markdown_html(input) == expect \ No newline at end of file From d64b1f80da65c5dfc07a75c593cb116fa7dadc21 Mon Sep 17 00:00:00 2001 From: Ori Kotek Date: Wed, 30 Aug 2023 12:12:09 +0300 Subject: [PATCH 04/10] Allow overriding GitHub app default action by using repo local file --- pr_agent/servers/github_app.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pr_agent/servers/github_app.py b/pr_agent/servers/github_app.py index 1d1c901c..10584e54 100644 --- a/pr_agent/servers/github_app.py +++ b/pr_agent/servers/github_app.py @@ -12,6 +12,7 @@ from starlette_context import context from starlette_context.middleware import RawContextMiddleware from pr_agent.agent.pr_agent import PRAgent +from pr_agent.algo.utils import update_settings_from_args from pr_agent.config_loader import get_settings, global_settings from pr_agent.git_providers import get_git_provider from pr_agent.servers.utils import verify_signature @@ -123,8 +124,13 @@ async def handle_request(body: Dict[str, Any], event: str): return {} logging.info(f"Performing review because of event={event} and action={action}") for command in get_settings().github_app.pr_commands: - logging.info(f"Performing command: {command}") - await agent.handle_request(api_url, command) + split_command = command.split(" ") + command = split_command[0] + args = split_command[1:] + other_args = update_settings_from_args(args) + new_command = ' '.join([command] + other_args) + logging.info(f"Performing command: {new_command}") + await agent.handle_request(api_url, new_command) logging.info("event or action does not require handling") return {} From 307b3b4bf7560ee676636d9dc810329e1c794f14 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Wed, 30 Aug 2023 19:42:46 +0300 Subject: [PATCH 05/10] GitHub App instructions --- CONFIGURATION.md | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/CONFIGURATION.md b/CONFIGURATION.md index 9bbfd910..79f86313 100644 --- a/CONFIGURATION.md +++ b/CONFIGURATION.md @@ -21,20 +21,41 @@ verbosity_level=2 ``` This is useful for debugging or experimenting with the different tools. -### Working from pre-built repo (GitHub Action/GitHub App/Docker) -When running PR-Agent from a pre-built repo, the default configuration file will be loaded. +### Working from GitHub App (pre-built repo) +When running PR-Agent from GitHub App, the default configuration file (`configuration.toml`) will be loaded. -To edit the configuration, you have two options: -1. Place a local configuration file in the root of your local repo. The local file will be used instead of the default one. -2. For online usage, just add `--config_path=` to you command, to edit a specific configuration value. +#### GitHub app default tools +The GitHub app configuration is defined in the `[github_app]` section of the configuration file. +The main parameter is `pr_commands`, which is a list of tools to run when a new PR is opened: +``` +[github_app] +pr_commands = [ + "/describe --pr_description.add_original_user_description=true --pr_description.keep_original_user_title=true", + "/auto_review", +] +``` +This means that when a new PR is opened, PR-Agent will run the `describe` and `auto_review` tools. +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 actions parameters by uploading a local configuration called `.pr_agent.toml`, to the root of your repo. +For example, if your local `.pr_agent.toml` file contains: +``` +[pr_description] +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. + +#### Online usage +For online usage (calling tools by comments on a PR), 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. -### General configuration parameters + +### General configuration walkthrough #### Changing a model See [here](pr_agent/algo/__init__.py) for the list of available models. From ad6dd38fe37a7b700eea4ebc5ec8c831f0c61429 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Wed, 30 Aug 2023 19:46:33 +0300 Subject: [PATCH 06/10] GitHub App instructions --- CONFIGURATION.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/CONFIGURATION.md b/CONFIGURATION.md index 79f86313..07cc5701 100644 --- a/CONFIGURATION.md +++ b/CONFIGURATION.md @@ -25,7 +25,7 @@ This is useful for debugging or experimenting with the different tools. When running PR-Agent from GitHub App, the default configuration file (`configuration.toml`) will be loaded. #### GitHub app default tools -The GitHub app configuration is defined in the `[github_app]` section of the configuration file. +The GitHub app specific configurations are defined in the `[github_app]` section of the configuration file. The main parameter is `pr_commands`, which is a list of tools to run when a new PR is opened: ``` [github_app] @@ -37,7 +37,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 actions parameters by uploading a local configuration called `.pr_agent.toml`, to the root of your repo. +However, you can override the default tool parameters by uploading a local configuration called `.pr_agent.toml`, to the root of your repo. For example, if your local `.pr_agent.toml` file contains: ``` [pr_description] @@ -46,6 +46,8 @@ keep_original_user_title = false ``` Then 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 by default. + #### Online usage For online usage (calling tools by comments on a PR), 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: From eec62c14dcf0917160a6c5902c6e8deb5b2a7fb9 Mon Sep 17 00:00:00 2001 From: Krish Dholakia Date: Wed, 30 Aug 2023 09:49:01 -0700 Subject: [PATCH 07/10] bump litellm version - prevent default logging --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index fe92a74b..2441b1c1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -13,7 +13,7 @@ atlassian-python-api==3.39.0 GitPython~=3.1.32 PyYAML==6.0 starlette-context==0.3.6 -litellm~=0.1.445 +litellm~=0.1.504 boto3~=1.28.25 google-cloud-storage==2.10.0 ujson==5.8.0 From 3c27432f50ba074171896761ec1e4e6b7c35f3f5 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Wed, 30 Aug 2023 19:53:28 +0300 Subject: [PATCH 08/10] GitHub App instructions --- CONFIGURATION.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/CONFIGURATION.md b/CONFIGURATION.md index 07cc5701..66ec4f06 100644 --- a/CONFIGURATION.md +++ b/CONFIGURATION.md @@ -25,8 +25,8 @@ This is useful for debugging or experimenting with the different tools. When running PR-Agent from GitHub App, the default configuration file (`configuration.toml`) will be loaded. #### GitHub app default tools -The GitHub app specific configurations are defined in the `[github_app]` section of the configuration file. -The main parameter is `pr_commands`, which is a list of tools to run when a new PR is opened: +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: ``` [github_app] pr_commands = [ @@ -37,7 +37,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 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] @@ -46,10 +46,10 @@ keep_original_user_title = false ``` Then 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 by default. +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. #### Online usage -For online usage (calling tools by comments on a PR), just add `--config_path=` to any command, to edit a specific configuration value. +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 ... From 92e23ff260f6f6dcd59bf26ab41f4781e8556388 Mon Sep 17 00:00:00 2001 From: zmeir Date: Wed, 30 Aug 2023 23:05:41 +0300 Subject: [PATCH 09/10] Fix #254 --- pr_agent/git_providers/git_provider.py | 4 ++-- pr_agent/tools/pr_description.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pr_agent/git_providers/git_provider.py b/pr_agent/git_providers/git_provider.py index 9dced773..4651d47d 100644 --- a/pr_agent/git_providers/git_provider.py +++ b/pr_agent/git_providers/git_provider.py @@ -86,11 +86,11 @@ class GitProvider(ABC): def get_pr_description_full(self) -> str: pass - def get_pr_description(self) -> str: + def get_pr_description(self, *, full: bool = True) -> str: from pr_agent.config_loader import get_settings from pr_agent.algo.pr_processing import clip_tokens max_tokens = get_settings().get("CONFIG.MAX_DESCRIPTION_TOKENS", None) - description = self.get_pr_description_full() + description = self.get_pr_description_full() if full else self.get_user_description() if max_tokens: return clip_tokens(description, max_tokens) return description diff --git a/pr_agent/tools/pr_description.py b/pr_agent/tools/pr_description.py index acd272bc..c45917f4 100644 --- a/pr_agent/tools/pr_description.py +++ b/pr_agent/tools/pr_description.py @@ -36,7 +36,7 @@ class PRDescription: self.vars = { "title": self.git_provider.pr.title, "branch": self.git_provider.get_pr_branch(), - "description": self.git_provider.get_pr_description(), + "description": self.git_provider.get_pr_description(full=False), "language": self.main_pr_language, "diff": "", # empty diff for initial calculation "extra_instructions": get_settings().pr_description.extra_instructions, From 8263bf5f9cf4a3c8bb6ec098ee446afefc84e0cb Mon Sep 17 00:00:00 2001 From: Ori Kotek Date: Thu, 31 Aug 2023 09:26:16 +0300 Subject: [PATCH 10/10] small refactor of azure devops --- Dockerfile.github_action | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfile.github_action b/Dockerfile.github_action index d6763f0a..dd1ae750 100644 --- a/Dockerfile.github_action +++ b/Dockerfile.github_action @@ -2,7 +2,8 @@ FROM python:3.10 as base WORKDIR /app ADD pyproject.toml . -RUN pip install . && rm pyproject.toml +ADD requirements.txt . +RUN pip install . && rm pyproject.toml requirements.txt ENV PYTHONPATH=/app ADD pr_agent pr_agent ADD github_action/entrypoint.sh /