Skip to content
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

Tr/err protections #1134

Merged
merged 4 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion pr_agent/algo/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,8 +561,13 @@ def load_yaml(response_text: str, keys_fix_yaml: List[str] = [], first_key="", l
try:
data = yaml.safe_load(response_text)
except Exception as e:
get_logger().error(f"Failed to parse AI prediction: {e}")
get_logger().warning(f"Initial failure to parse AI prediction: {e}")
data = try_fix_yaml(response_text, keys_fix_yaml=keys_fix_yaml, first_key=first_key, last_key=last_key)
if not data:
get_logger().error(f"Failed to parse AI prediction after fallbacks", artifact={'response_text': response_text})
else:
get_logger().info(f"Successfully parsed AI prediction after fallbacks",
artifact={'response_text': response_text})
return data


Expand Down
2 changes: 1 addition & 1 deletion pr_agent/git_providers/azuredevops_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def publish_labels(self, pr_types):
pull_request_id=self.pr_num,
)
except Exception as e:
get_logger().exception(f"Failed to publish labels, error: {e}")
get_logger().warning(f"Failed to publish labels, error: {e}")

def get_pr_labels(self, update=False):
try:
Expand Down
7 changes: 5 additions & 2 deletions pr_agent/git_providers/bitbucket_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,12 @@ def get_diff_files(self) -> list[FilePatchInfo]:
else:
if diffs[i].data.get('lines_added', 0) == 0 and diffs[i].data.get('lines_removed', 0) == 0:
diff_split[i] = ""
elif len(diff_split_lines) <= 3:
diff_split[i] = ""
get_logger().info(f"Disregarding empty diff for file {_gef_filename(diffs[i])}")
else:
get_logger().error(f"Error - failed to remove the bitbucket header from diff {i}")
break
get_logger().error(f"Error - failed to get diff for file {_gef_filename(diffs[i])}")
diff_split[i] = ""

invalid_files_names = []
diff_files = []
Expand Down
2 changes: 1 addition & 1 deletion pr_agent/git_providers/github_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ def publish_labels(self, pr_types):
"PUT", f"{self.pr.issue_url}/labels", input=post_parameters
)
except Exception as e:
get_logger().exception(f"Failed to publish labels, error: {e}")
get_logger().warning(f"Failed to publish labels, error: {e}")

def get_pr_labels(self, update=False):
try:
Expand Down
2 changes: 1 addition & 1 deletion pr_agent/git_providers/gitlab_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ def publish_labels(self, pr_types):
self.mr.labels = list(set(pr_types))
self.mr.save()
except Exception as e:
get_logger().exception(f"Failed to publish labels, error: {e}")
get_logger().warning(f"Failed to publish labels, error: {e}")

def publish_inline_comments(self, comments: list[dict]):
pass
Expand Down
2 changes: 1 addition & 1 deletion pr_agent/tools/pr_code_suggestions.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ async def _prepare_prediction(self, model: str) -> dict:
get_logger().debug(f"PR diff", artifact=self.patches_diff)
self.prediction = await self._get_prediction(model, self.patches_diff)
else:
get_logger().error(f"Error getting PR diff")
get_logger().warning(f"Empty PR diff")
self.prediction = None

data = self.prediction
Expand Down
4 changes: 3 additions & 1 deletion pr_agent/tools/pr_description.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ async def run(self):
if self.prediction:
self._prepare_data()
else:
get_logger().error(f"Error getting AI prediction {self.pr_id}")
get_logger().warning(f"Empty prediction, PR: {self.pr_id}")
self.git_provider.remove_initial_comment()
return None

Expand Down Expand Up @@ -508,6 +508,8 @@ def _prepare_pr_answer(self) -> Tuple[str, str, str, List[dict]]:

def _prepare_file_labels(self):
file_label_dict = {}
if not self.data or 'pr_files' not in self.data:
return file_label_dict
for file in self.data['pr_files']:
try:
required_fields = ['changes_summary', 'changes_title', 'filename', 'label']
Expand Down
Loading