Merge pull request #1 from Codium-ai/feature/delete_initial_comment

delete "Preparing review..." comment
This commit is contained in:
Ori Kotek
2023-07-06 10:03:50 +03:00
committed by GitHub
4 changed files with 24 additions and 10 deletions

View File

@ -9,7 +9,6 @@ It automatically analyzes the PR, and provides feedback and suggestions, and can
It is powered by GPT-4, and is based on the [CodiumAI](https://github.com/Codium-ai/) platform.
</div>
TBD: Add screenshot of the PR Reviewer (could be gif)
* [Quickstart](#Quickstart)
@ -17,10 +16,7 @@ TBD: Add screenshot of the PR Reviewer (could be gif)
* [Usage and Tools](#usage-and-tools)
* [Roadmap](#roadmap)
* [Similar projects](#similar-projects)
* Additional files:
* CONTRIBUTION.md
* LICENSE
*
## Quickstart

View File

@ -1,3 +1,4 @@
import logging
from collections import namedtuple
from dataclasses import dataclass
from datetime import datetime
@ -39,8 +40,20 @@ class GithubProvider:
diff_files.append(FilePatchInfo(original_file_content_str, new_file_content_str, file.patch, file.filename))
return diff_files
def publish_comment(self, pr_comment: str):
self.pr.create_issue_comment(pr_comment)
def publish_comment(self, pr_comment: str, is_temporary: bool = False):
response = self.pr.create_issue_comment(pr_comment)
response.is_temporary = is_temporary
if not hasattr(self.pr, 'comments_list'):
self.pr.comments_list = []
self.pr.comments_list.append(response)
def remove_initial_comment(self):
try:
for comment in self.pr.comments_list:
if comment.is_temporary:
comment.delete()
except Exception as e:
logging.exception(f"Failed to remove initial comment, error: {e}")
def get_title(self):
return self.pr.title
@ -153,7 +166,9 @@ class GithubProvider:
try:
token = settings.github.user_token
except AttributeError as e:
raise ValueError("GitHub token is required when using user deployment") from e
raise ValueError(
"GitHub token is required when using user deployment. See: "
"https://github.com/Codium-ai/pr-agent#method-2-run-from-source") from e
return Github(token)
def _get_repo(self):

View File

@ -35,7 +35,8 @@ class PRQuestions:
async def answer(self):
logging.info('Answering a PR question...')
self.git_provider.publish_comment("Preparing answer...")
if settings.config.publish_review:
self.git_provider.publish_comment("Preparing answer...", is_temporary=True)
logging.info('Getting PR diff...')
self.patches_diff = get_pr_diff(self.git_provider, self.token_handler)
logging.info('Getting AI prediction...')
@ -45,6 +46,7 @@ class PRQuestions:
if settings.config.publish_review:
logging.info('Pushing answer...')
self.git_provider.publish_comment(pr_comment)
self.git_provider.remove_initial_comment()
return ""
async def _get_prediction(self):

View File

@ -42,7 +42,7 @@ class PRReviewer:
async def review(self):
logging.info('Reviewing PR...')
if settings.config.publish_review:
self.git_provider.publish_comment("Preparing review...")
self.git_provider.publish_comment("Preparing review...", is_temporary=True)
logging.info('Getting PR diff...')
self.patches_diff = get_pr_diff(self.git_provider, self.token_handler)
logging.info('Getting AI prediction...')
@ -52,6 +52,7 @@ class PRReviewer:
if settings.config.publish_review:
logging.info('Pushing PR review...')
self.git_provider.publish_comment(pr_comment)
self.git_provider.remove_initial_comment()
return ""
async def _get_prediction(self):