From e9382b18b626abd916a496a63a2baa053261f78f Mon Sep 17 00:00:00 2001 From: mrT23 Date: Sun, 18 Feb 2024 12:01:16 +0200 Subject: [PATCH 1/5] Added PRHelpMessage to command execution in pr_agent.py --- pr_agent/agent/pr_agent.py | 2 + pr_agent/tools/pr_help_message.py | 62 +++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 pr_agent/tools/pr_help_message.py diff --git a/pr_agent/agent/pr_agent.py b/pr_agent/agent/pr_agent.py index ae390cd4..55c3c267 100644 --- a/pr_agent/agent/pr_agent.py +++ b/pr_agent/agent/pr_agent.py @@ -13,6 +13,7 @@ from pr_agent.tools.pr_code_suggestions import PRCodeSuggestions from pr_agent.tools.pr_config import PRConfig from pr_agent.tools.pr_description import PRDescription from pr_agent.tools.pr_generate_labels import PRGenerateLabels +from pr_agent.tools.pr_help_message import PRHelpMessage from pr_agent.tools.pr_information_from_user import PRInformationFromUser from pr_agent.tools.pr_line_questions import PR_LineQuestions from pr_agent.tools.pr_questions import PRQuestions @@ -37,6 +38,7 @@ command2class = { "update_changelog": PRUpdateChangelog, "config": PRConfig, "settings": PRConfig, + "help": PRHelpMessage, "similar_issue": PRSimilarIssue, "add_docs": PRAddDocs, "generate_labels": PRGenerateLabels, diff --git a/pr_agent/tools/pr_help_message.py b/pr_agent/tools/pr_help_message.py new file mode 100644 index 00000000..f781cbd0 --- /dev/null +++ b/pr_agent/tools/pr_help_message.py @@ -0,0 +1,62 @@ +from pr_agent.config_loader import get_settings +from pr_agent.git_providers import get_git_provider +from pr_agent.log import get_logger + + +class PRHelpMessage: + """ + The PRConfig class is responsible for listing all configuration options available for the user. + """ + def __init__(self, pr_url: str, args=None, ai_handler=None): + """ + Initialize the PRConfig object with the necessary attributes and objects to comment on a pull request. + + Args: + pr_url (str): The URL of the pull request to be reviewed. + args (list, optional): List of arguments passed to the PRReviewer class. Defaults to None. + """ + self.git_provider = get_git_provider()(pr_url) + + async def run(self): + get_logger().info('Getting PR Help Message...') + pr_comment="## PR Agent Intro\n\n" + pr_comment +="🤖 Welcome to the PR Agent, an AI-powered tool for automated pull request analysis, feedback, suggestions and more.""" + pr_comment +="\n\nHere are the tools you can use to interact with the PR Agent:\n" + base_path ="https://github.com/Codium-ai/pr-agent/tree/main/docs" + pr_comment +=f""" +\n\n +- [DESCRIBE]({base_path}/DESCRIBE.md) +- [REVIEW]({base_path}/REVIEW.md) +- [IMPROVE](./IMPROVE.md) +- [ASK]({base_path}/ASK.md) +- [SIMILAR_ISSUE]({base_path}/SIMILAR_ISSUE.md) +- [UPDATE CHANGELOG]({base_path}/UPDATE_CHANGELOG.md) +- [ADD DOCUMENTATION]({base_path}/ADD_DOCUMENTATION.md) +- [GENERATE CUSTOM LABELS]({base_path}/GENERATE_CUSTOM_LABELS.md) +- [Analyze]({base_path}/Analyze.md) +- [Test]({base_path}/TEST.md) +- [CI Feedback]({base_path}/CI_FEEDBACK.md) +""" + pr_comment +=f"""\n\nNote that each command be [applied automatically](https://github.com/Codium-ai/pr-agent/blob/main/Usage.md#github-app-automatic-tools-for-pr-actions) when a new PR is opened, or invoked manually by [commenting on a PR](https://github.com/Codium-ai/pr-agent/blob/main/Usage.md#online-usage).""" + if get_settings().config.publish_output: + self.git_provider.publish_comment(pr_comment) + return "" + + def _prepare_pr_configs(self) -> str: + import tomli + with open(get_settings().find_file("configuration.toml"), "rb") as conf_file: + configuration_headers = [header.lower() for header in tomli.load(conf_file).keys()] + relevant_configs = { + header: configs for header, configs in get_settings().to_dict().items() + if header.lower().startswith("pr_") and header.lower() in configuration_headers + } + comment_str = "Possible Configurations:" + for header, configs in relevant_configs.items(): + if configs: + comment_str += "\n" + for key, value in configs.items(): + comment_str += f"\n{header.lower()}.{key.lower()} = {repr(value) if isinstance(value, str) else value}" + comment_str += " " + if get_settings().config.verbosity_level >= 2: + get_logger().info(f"comment_str:\n{comment_str}") + return comment_str From ed5856493c2d840846de0e3426af666cf6784df0 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Sun, 18 Feb 2024 13:06:57 +0200 Subject: [PATCH 2/5] Added PRHelpMessage to command execution in pr_agent.py --- pr_agent/tools/pr_help_message.py | 54 ++++++++++++++----------------- 1 file changed, 25 insertions(+), 29 deletions(-) diff --git a/pr_agent/tools/pr_help_message.py b/pr_agent/tools/pr_help_message.py index f781cbd0..5fdca901 100644 --- a/pr_agent/tools/pr_help_message.py +++ b/pr_agent/tools/pr_help_message.py @@ -8,38 +8,34 @@ class PRHelpMessage: The PRConfig class is responsible for listing all configuration options available for the user. """ def __init__(self, pr_url: str, args=None, ai_handler=None): - """ - Initialize the PRConfig object with the necessary attributes and objects to comment on a pull request. - - Args: - pr_url (str): The URL of the pull request to be reviewed. - args (list, optional): List of arguments passed to the PRReviewer class. Defaults to None. - """ self.git_provider = get_git_provider()(pr_url) async def run(self): - get_logger().info('Getting PR Help Message...') - pr_comment="## PR Agent Intro\n\n" - pr_comment +="🤖 Welcome to the PR Agent, an AI-powered tool for automated pull request analysis, feedback, suggestions and more.""" - pr_comment +="\n\nHere are the tools you can use to interact with the PR Agent:\n" - base_path ="https://github.com/Codium-ai/pr-agent/tree/main/docs" - pr_comment +=f""" -\n\n -- [DESCRIBE]({base_path}/DESCRIBE.md) -- [REVIEW]({base_path}/REVIEW.md) -- [IMPROVE](./IMPROVE.md) -- [ASK]({base_path}/ASK.md) -- [SIMILAR_ISSUE]({base_path}/SIMILAR_ISSUE.md) -- [UPDATE CHANGELOG]({base_path}/UPDATE_CHANGELOG.md) -- [ADD DOCUMENTATION]({base_path}/ADD_DOCUMENTATION.md) -- [GENERATE CUSTOM LABELS]({base_path}/GENERATE_CUSTOM_LABELS.md) -- [Analyze]({base_path}/Analyze.md) -- [Test]({base_path}/TEST.md) -- [CI Feedback]({base_path}/CI_FEEDBACK.md) -""" - pr_comment +=f"""\n\nNote that each command be [applied automatically](https://github.com/Codium-ai/pr-agent/blob/main/Usage.md#github-app-automatic-tools-for-pr-actions) when a new PR is opened, or invoked manually by [commenting on a PR](https://github.com/Codium-ai/pr-agent/blob/main/Usage.md#online-usage).""" - if get_settings().config.publish_output: - self.git_provider.publish_comment(pr_comment) + try: + get_logger().info('Getting PR Help Message...') + pr_comment="## PR Agent Intro\n\n" + pr_comment +="🤖 Welcome to the PR Agent, an AI-powered tool for automated pull request analysis, feedback, suggestions and more.""" + pr_comment +="\n\nHere are the tools you can use to interact with the PR Agent:\n" + base_path ="https://github.com/Codium-ai/pr-agent/tree/main/docs" + pr_comment +=f""" + \n\n + - [DESCRIBE]({base_path}/DESCRIBE.md) + - [REVIEW]({base_path}/REVIEW.md) + - [IMPROVE]({base_path}/IMPROVE.md) + - [ASK]({base_path}/ASK.md) + - [SIMILAR_ISSUE]({base_path}/SIMILAR_ISSUE.md) + - [UPDATE CHANGELOG]({base_path}/UPDATE_CHANGELOG.md) + - [ADD DOCUMENTATION]({base_path}/ADD_DOCUMENTATION.md) + - [GENERATE CUSTOM LABELS]({base_path}/GENERATE_CUSTOM_LABELS.md) + - [Analyze]({base_path}/Analyze.md) + - [Test]({base_path}/TEST.md) + - [CI Feedback]({base_path}/CI_FEEDBACK.md) + """ + pr_comment +=f"""\n\nNote that each command be [applied automatically](https://github.com/Codium-ai/pr-agent/blob/main/Usage.md#github-app-automatic-tools-for-pr-actions) when a new PR is opened, or invoked manually by [commenting on a PR](https://github.com/Codium-ai/pr-agent/blob/main/Usage.md#online-usage).""" + if get_settings().config.publish_output: + self.git_provider.publish_comment(pr_comment) + except Exception as e: + get_logger().error(f"Error while running PRHelpMessage: {e}") return "" def _prepare_pr_configs(self) -> str: From 0515b802473fa31f1ffdec0fe5e1532731542bc2 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Sun, 18 Feb 2024 13:08:05 +0200 Subject: [PATCH 3/5] Added PRHelpMessage to command execution in pr_agent.py --- pr_agent/tools/pr_help_message.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/pr_agent/tools/pr_help_message.py b/pr_agent/tools/pr_help_message.py index 5fdca901..f80c6432 100644 --- a/pr_agent/tools/pr_help_message.py +++ b/pr_agent/tools/pr_help_message.py @@ -4,9 +4,6 @@ from pr_agent.log import get_logger class PRHelpMessage: - """ - The PRConfig class is responsible for listing all configuration options available for the user. - """ def __init__(self, pr_url: str, args=None, ai_handler=None): self.git_provider = get_git_provider()(pr_url) From 687ece1e8675c5bfefe5991cb8daa33331f5b132 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Sun, 18 Feb 2024 13:09:17 +0200 Subject: [PATCH 4/5] Added PRHelpMessage to command execution in pr_agent.py --- pr_agent/tools/pr_help_message.py | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/pr_agent/tools/pr_help_message.py b/pr_agent/tools/pr_help_message.py index f80c6432..efadf157 100644 --- a/pr_agent/tools/pr_help_message.py +++ b/pr_agent/tools/pr_help_message.py @@ -34,22 +34,3 @@ class PRHelpMessage: except Exception as e: get_logger().error(f"Error while running PRHelpMessage: {e}") return "" - - def _prepare_pr_configs(self) -> str: - import tomli - with open(get_settings().find_file("configuration.toml"), "rb") as conf_file: - configuration_headers = [header.lower() for header in tomli.load(conf_file).keys()] - relevant_configs = { - header: configs for header, configs in get_settings().to_dict().items() - if header.lower().startswith("pr_") and header.lower() in configuration_headers - } - comment_str = "Possible Configurations:" - for header, configs in relevant_configs.items(): - if configs: - comment_str += "\n" - for key, value in configs.items(): - comment_str += f"\n{header.lower()}.{key.lower()} = {repr(value) if isinstance(value, str) else value}" - comment_str += " " - if get_settings().config.verbosity_level >= 2: - get_logger().info(f"comment_str:\n{comment_str}") - return comment_str From 28e8707c1b6e5a97e60f2e383b00da715a3143b1 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Sun, 18 Feb 2024 13:16:07 +0200 Subject: [PATCH 5/5] Added PRHelpMessage to command execution in pr_agent.py --- pr_agent/tools/pr_help_message.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/pr_agent/tools/pr_help_message.py b/pr_agent/tools/pr_help_message.py index efadf157..bc40b614 100644 --- a/pr_agent/tools/pr_help_message.py +++ b/pr_agent/tools/pr_help_message.py @@ -14,20 +14,20 @@ class PRHelpMessage: pr_comment +="🤖 Welcome to the PR Agent, an AI-powered tool for automated pull request analysis, feedback, suggestions and more.""" pr_comment +="\n\nHere are the tools you can use to interact with the PR Agent:\n" base_path ="https://github.com/Codium-ai/pr-agent/tree/main/docs" - pr_comment +=f""" - \n\n - - [DESCRIBE]({base_path}/DESCRIBE.md) - - [REVIEW]({base_path}/REVIEW.md) - - [IMPROVE]({base_path}/IMPROVE.md) - - [ASK]({base_path}/ASK.md) - - [SIMILAR_ISSUE]({base_path}/SIMILAR_ISSUE.md) - - [UPDATE CHANGELOG]({base_path}/UPDATE_CHANGELOG.md) - - [ADD DOCUMENTATION]({base_path}/ADD_DOCUMENTATION.md) - - [GENERATE CUSTOM LABELS]({base_path}/GENERATE_CUSTOM_LABELS.md) - - [Analyze]({base_path}/Analyze.md) - - [Test]({base_path}/TEST.md) - - [CI Feedback]({base_path}/CI_FEEDBACK.md) - """ + pr_comment +=f"""\ +\n\n +- [DESCRIBE]({base_path}/DESCRIBE.md) +- [REVIEW]({base_path}/REVIEW.md) +- [IMPROVE]({base_path}/IMPROVE.md) +- [ASK]({base_path}/ASK.md) +- [SIMILAR_ISSUE]({base_path}/SIMILAR_ISSUE.md) +- [UPDATE CHANGELOG]({base_path}/UPDATE_CHANGELOG.md) +- [ADD DOCUMENTATION]({base_path}/ADD_DOCUMENTATION.md) +- [GENERATE CUSTOM LABELS]({base_path}/GENERATE_CUSTOM_LABELS.md) +- [Analyze]({base_path}/Analyze.md) +- [Test]({base_path}/TEST.md) +- [CI Feedback]({base_path}/CI_FEEDBACK.md) +""" pr_comment +=f"""\n\nNote that each command be [applied automatically](https://github.com/Codium-ai/pr-agent/blob/main/Usage.md#github-app-automatic-tools-for-pr-actions) when a new PR is opened, or invoked manually by [commenting on a PR](https://github.com/Codium-ai/pr-agent/blob/main/Usage.md#online-usage).""" if get_settings().config.publish_output: self.git_provider.publish_comment(pr_comment)