Skip to content

Commit

Permalink
Merge pull request Codium-ai#215 from tjwp/auto-review
Browse files Browse the repository at this point in the history
Addition of Automatic Review Configuration for GitHub App
  • Loading branch information
mrT23 committed Aug 19, 2023
2 parents dee1f16 + 631fb93 commit 532dfd2
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
5 changes: 5 additions & 0 deletions pr_agent/agent/pr_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from pr_agent.tools.pr_config import PRConfig

command2class = {
"auto_review": PRReviewer,
"answer": PRReviewer,
"review": PRReviewer,
"review_pr": PRReviewer,
Expand Down Expand Up @@ -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)
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion pr_agent/servers/github_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}

Expand Down
1 change: 1 addition & 0 deletions pr_agent/settings/configuration.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 #
Expand Down
11 changes: 8 additions & 3 deletions pr_agent/tools/pr_reviewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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")
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 532dfd2

Please sign in to comment.