diff --git a/pr_agent/agent/pr_agent.py b/pr_agent/agent/pr_agent.py index 2ab13d69f..2b9013912 100644 --- a/pr_agent/agent/pr_agent.py +++ b/pr_agent/agent/pr_agent.py @@ -15,6 +15,7 @@ from pr_agent.tools.pr_config import PRConfig command2class = { + "auto_review": PRReviewer, "answer": PRReviewer, "review": PRReviewer, "review_pr": PRReviewer, @@ -43,8 +44,10 @@ async def handle_request(self, pr_url, request, notify=None) -> bool: repo_settings_file = None try: git_provider = get_git_provider()(pr_url) + logging.info(f'Fetching repo settings {git_provider.repo}') repo_settings = git_provider.get_repo_settings() if repo_settings: + logging.debug(f'Found settings for repo {git_provider.repo}\n{repo_settings}') repo_settings_file = None fd, repo_settings_file = tempfile.mkstemp(suffix='.toml') os.write(fd, repo_settings) @@ -70,6 +73,8 @@ async def handle_request(self, pr_url, request, notify=None) -> bool: if notify: notify() await PRReviewer(pr_url, is_answer=True, args=args).run() + elif action == "auto_review": + await PRReviewer(pr_url, is_auto=True, args=args).run() elif action in command2class: if notify: notify() diff --git a/pr_agent/servers/github_app.py b/pr_agent/servers/github_app.py index 18943ae85..498bb81f2 100644 --- a/pr_agent/servers/github_app.py +++ b/pr_agent/servers/github_app.py @@ -93,7 +93,7 @@ async def handle_request(body: Dict[str, Any]): api_url = pull_request.get("url") if not api_url: return {} - await agent.handle_request(api_url, "/review") + await agent.handle_request(api_url, "/auto_review") return {} diff --git a/pr_agent/settings/configuration.toml b/pr_agent/settings/configuration.toml index 0c502df9f..ce920efd3 100644 --- a/pr_agent/settings/configuration.toml +++ b/pr_agent/settings/configuration.toml @@ -19,6 +19,7 @@ require_security_review=true num_code_suggestions=3 inline_code_comments = false ask_and_reflect=false +automatic_review=true extra_instructions = "" [pr_description] # /describe # diff --git a/pr_agent/tools/pr_reviewer.py b/pr_agent/tools/pr_reviewer.py index fd6479aef..a89c27a37 100644 --- a/pr_agent/tools/pr_reviewer.py +++ b/pr_agent/tools/pr_reviewer.py @@ -23,7 +23,7 @@ class PRReviewer: """ The PRReviewer class is responsible for reviewing a pull request and generating feedback using an AI model. """ - def __init__(self, pr_url: str, is_answer: bool = False, args: list = None): + def __init__(self, pr_url: str, is_answer: bool = False, is_auto: bool = False, args: list = None): """ Initialize the PRReviewer object with the necessary attributes and objects to review a pull request. @@ -40,6 +40,7 @@ def __init__(self, pr_url: str, is_answer: bool = False, args: list = None): ) self.pr_url = pr_url self.is_answer = is_answer + self.is_auto = is_auto if self.is_answer and not self.git_provider.is_supported("get_issue_comments"): raise Exception(f"Answer mode is not supported for {get_settings().config.git_provider} for now") @@ -93,8 +94,12 @@ async def run(self) -> None: """ Review the pull request and generate feedback. """ - logging.info('Reviewing PR...') - + if self.is_auto and not get_settings().pr_reviewer.automatic_review: + logging.info(f'Automatic review is disabled {self.pr_url}') + return None + + logging.info(f'Reviewing PR: {self.pr_url} ...') + if get_settings().config.publish_output: self.git_provider.publish_comment("Preparing review...", is_temporary=True)