-
Notifications
You must be signed in to change notification settings - Fork 719
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enhancement of PR Agent with User Interaction #78
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# Conflicts: # pr_agent/tools/pr_description.py
Preparing pr description... |
@@ -53,8 +54,14 @@ async def run_action(): | |||
pr_url = event_payload.get("issue", {}).get("pull_request", {}).get("url", None) | |||
if pr_url: | |||
body = comment_body.strip().lower() | |||
if any(cmd in body for cmd in ["/review", "/review_pr"]): | |||
await PRReviewer(pr_url).review() | |||
if any(cmd in body for cmd in ["/answer"]): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let me replace that with PRAgent call
pr_agent/tools/pr_reviewer.py
Outdated
@@ -9,18 +9,22 @@ | |||
from pr_agent.algo.token_handler import TokenHandler | |||
from pr_agent.algo.utils import convert_to_markdown, try_fix_json | |||
from pr_agent.config_loader import settings | |||
from pr_agent.git_providers import get_git_provider | |||
from pr_agent.git_providers import get_git_provider, GithubProvider |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from pr_agent.git_providers import get_git_provider, GithubProvider | |
from pr_agent.git_providers import get_git_provider |
pr_agent/tools/pr_reviewer.py
Outdated
|
||
self.git_provider = get_git_provider()(pr_url) | ||
self.main_language = get_main_pr_language( | ||
self.git_provider.get_languages(), self.git_provider.get_files() | ||
) | ||
self.is_answer = is_answer | ||
if self.is_answer and type(self.git_provider) != GithubProvider: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let me add is_supported in git provider
pr_agent/tools/pr_reviewer.py
Outdated
answer_str = question_str = "" | ||
if self.is_answer: | ||
discussion_messages = self.git_provider.pr.get_issue_comments() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me add that function in the base class
/answer |
PR Analysis
PR Feedback
How to use
|
|
||
|
||
class PRAgent: | ||
def __init__(self): | ||
pass | ||
|
||
async def handle_request(self, pr_url, request) -> bool: | ||
if any(cmd in request for cmd in ["/review", "/review_pr"]): | ||
await PRReviewer(pr_url).review() | ||
if any(cmd in request for cmd in ["/answer"]): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider refactoring the handle_request
method to reduce its complexity and improve readability. You could extract the logic for each command into separate methods. [important]
|
||
self.git_provider = get_git_provider()(pr_url) | ||
self.main_language = get_main_pr_language( | ||
self.git_provider.get_languages(), self.git_provider.get_files() | ||
) | ||
self.is_answer = is_answer | ||
if self.is_answer and not self.git_provider.is_supported("get_issue_comments"): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be beneficial to handle the case where the get_issue_comments
method is not supported by the git provider in a more user-friendly way. Instead of raising an exception, you could display a message to the user informing them that this feature is not supported. [medium]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably do that
/reflect_and_review |
Questions to better understand the PR:
Please respond to the questions above in the following format:
|
/answer
|
PR Analysis
PR Feedback
How to use
|
|
||
self.git_provider = get_git_provider()(pr_url) | ||
self.main_language = get_main_pr_language( | ||
self.git_provider.get_languages(), self.git_provider.get_files() | ||
) | ||
self.is_answer = is_answer | ||
if self.is_answer and not self.git_provider.is_supported("get_issue_comments"): | ||
raise Exception(f"Answer mode is not supported for {settings.config.git_provider} for now") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using a more specific exception type instead of the generic Exception. This can help with debugging and error handling. For example, you could define a custom exception for this specific error case. [important]
pass | ||
|
||
def _get_user_answers(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding a docstring to the '_get_user_answers' method to explain its purpose, inputs, and outputs. This can improve code readability and maintainability. [medium]
""") | ||
parser.add_argument('--pr_url', type=str, help='The URL of the PR to review', required=True) | ||
parser.add_argument('command', type=str, help='The', choices=['review', 'review_pr', | ||
'ask', 'ask_question', | ||
'describe', 'describe_pr', | ||
'improve', 'improve_code', | ||
'user_questions'], default='review') | ||
'reflect', 'review_after_reflect'], | ||
default='review') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using an enum or constants for command names instead of hardcoding them in multiple places. This can reduce the risk of typos and make the code easier to maintain. [medium]
Enhancement of PR Agent with User Interaction
Type of PR:
Enhancement
PR Description:
This PR introduces the ability for the PR Agent to interact with the user by asking questions and processing the user's answers. It also includes changes to the command line interface and the GitHub action runner to support these new features. Additionally, it modifies the configuration settings and the prompts used by the PR Agent.
PR Main Files Walkthrough:
-
pr_agent/agent/pr_agent.py
: The main agent class has been updated to handle new commands for asking questions and processing answers. It also uses the settings to decide whether to ask questions before reviewing a PR.-
pr_agent/cli.py
: The command line interface has been updated to support the new 'user_answers' command.-
pr_agent/servers/github_action_runner.py
: The GitHub action runner has been updated to handle the new '/answer' command and to ask questions before reviewing a PR based on the settings.-
pr_agent/tools/pr_information_from_user.py
: The method for preparing the PR answer has been updated to change the format of the response.-
pr_agent/tools/pr_reviewer.py
: The PRReviewer class has been updated to handle the new 'is_answer' parameter and to get the user's answers from the PR discussion. It also publishes inline code comments based on the settings.-
pr_agent/settings/configuration.toml
: The configuration settings have been updated to include a new 'ask_and_reflect' setting for the PR reviewer.-
pr_agent/settings/pr_information_from_user_prompts.toml
: The prompts for getting information from the user have been updated to change the format of the questions.-
pr_agent/settings/pr_reviewer_prompts.toml
: The prompts for the PR reviewer have been updated to include insights from the user's answers and to change the format of the questions.