diff --git a/pr_agent/tools/pr_code_suggestions.py b/pr_agent/tools/pr_code_suggestions.py
index d0fd1218..2070a621 100644
--- a/pr_agent/tools/pr_code_suggestions.py
+++ b/pr_agent/tools/pr_code_suggestions.py
@@ -68,6 +68,8 @@ class PRCodeSuggestions:
data = self._prepare_pr_code_suggestions()
else:
data = await retry_with_fallback_models(self._prepare_prediction_extended)
+
+
if (not data) or (not 'code_suggestions' in data):
get_logger().info('No code suggestions found for PR.')
return
@@ -330,7 +332,7 @@ class PRCodeSuggestions:
pr_body += f""" | {header} |
"""
pr_body += """
"""
suggestions_labels = dict()
- # add all suggestions related to to each label
+ # add all suggestions related to each label
for suggestion in data['code_suggestions']:
label = suggestion['label'].strip().strip("'").strip('"')
if label not in suggestions_labels:
diff --git a/pr_agent/tools/pr_description.py b/pr_agent/tools/pr_description.py
index 51df9ee4..e3ec92ff 100644
--- a/pr_agent/tools/pr_description.py
+++ b/pr_agent/tools/pr_description.py
@@ -86,6 +86,7 @@ class PRDescription:
if self.prediction:
self._prepare_data()
else:
+ self.git_provider.remove_initial_comment()
return None
if get_settings().pr_description.enable_semantic_files_types:
@@ -135,26 +136,17 @@ class PRDescription:
return ""
async def _prepare_prediction(self, model: str) -> None:
- """
- Prepare the AI prediction for the PR description based on the provided model.
-
- Args:
- model (str): The name of the model to be used for generating the prediction.
-
- Returns:
- None
-
- Raises:
- Any exceptions raised by the 'get_pr_diff' and '_get_prediction' functions.
-
- """
if get_settings().pr_description.use_description_markers and 'pr_agent:' not in self.user_description:
return None
get_logger().info(f"Getting PR diff {self.pr_id}")
self.patches_diff = get_pr_diff(self.git_provider, self.token_handler, model)
- get_logger().info(f"Getting AI prediction {self.pr_id}")
- self.prediction = await self._get_prediction(model)
+ if self.patches_diff:
+ get_logger().info(f"Getting AI prediction {self.pr_id}")
+ self.prediction = await self._get_prediction(model)
+ else:
+ get_logger().error(f"Error getting PR diff {self.pr_id}")
+ self.prediction = None
async def _get_prediction(self, model: str) -> str:
"""
diff --git a/pr_agent/tools/pr_reviewer.py b/pr_agent/tools/pr_reviewer.py
index 7c350c11..31cc1c43 100644
--- a/pr_agent/tools/pr_reviewer.py
+++ b/pr_agent/tools/pr_reviewer.py
@@ -98,14 +98,7 @@ class PRReviewer:
self.incremental = IncrementalPR(is_incremental)
async def run(self) -> None:
- """
- Review the pull request and generate feedback.
- """
-
try:
- # if self.is_auto and not get_settings().pr_reviewer.automatic_review:
- # get_logger().info(f'Automatic review is disabled {self.pr_url}')
- # return None
if self.incremental.is_incremental and not self._can_run_incremental_review():
return None
@@ -115,6 +108,9 @@ class PRReviewer:
self.git_provider.publish_comment("Preparing review...", is_temporary=True)
await retry_with_fallback_models(self._prepare_prediction)
+ if not self.prediction:
+ self.git_provider.remove_initial_comment()
+ return None
get_logger().info('Preparing PR review...')
pr_comment = self._prepare_pr_review()
@@ -141,19 +137,14 @@ class PRReviewer:
get_logger().error(f"Failed to review PR: {e}")
async def _prepare_prediction(self, model: str) -> None:
- """
- Prepare the AI prediction for the pull request review.
-
- Args:
- model: A string representing the AI model to be used for the prediction.
-
- Returns:
- None
- """
get_logger().info('Getting PR diff...')
self.patches_diff = get_pr_diff(self.git_provider, self.token_handler, model)
- get_logger().info('Getting AI prediction...')
- self.prediction = await self._get_prediction(model)
+ if self.patches_diff:
+ get_logger().info('Getting AI prediction...')
+ self.prediction = await self._get_prediction(model)
+ else:
+ get_logger().error(f"Error getting PR diff")
+ self.prediction = None
async def _get_prediction(self, model: str) -> str:
"""