You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The gitlab_protctions method returns an error string when GitHub quick actions are detected, but doesn't provide a way to recover or continue with a sanitized response.
defgitlab_protctions(self, model_answer: str) ->str:
github_quick_actions_MR= ["/approve", "/close", "/merge", "/reopen", "/unapprove", "/title", "/assign",
"/copy_metadata", "/target_branch"]
ifany(actioninmodel_answerforactioningithub_quick_actions_MR):
str_err="Model answer contains GitHub quick actions, which are not supported in GitLab"get_logger().error(str_err)
returnstr_err
def gitlab_protections(self, model_answer: str) -> str:
github_quick_actions_MR = ["/approve", "/close", "/merge", "/reopen", "/unapprove", "/title", "/assign",
"/copy_metadata", "/target_branch"]
- if any(action in model_answer for action in github_quick_actions_MR):- str_err = "Model answer contains GitHub quick actions, which are not supported in GitLab"- get_logger().error(str_err)- return str_err+ lines = model_answer.split('\n')+ for line in lines:+ if any(line.strip().startswith(action) for action in github_quick_actions_MR):+ str_err = "Model answer contains GitHub quick actions, which are not supported in GitLab"+ get_logger().error(str_err)+ return str_err
return model_answer
Apply this suggestion
Suggestion importance[1-10]: 8
__
Why: The suggestion correctly identifies a potential bug in the GitLab quick actions detection. The current implementation checks if actions appear anywhere in the text, but GitLab only processes them when they appear at the beginning of a line. The improved implementation properly splits the text into lines and checks each line's start, preventing false positives.
Medium
Learned best practice
Add null safety checks and proper error handling when accessing project attributes to prevent potential runtime errors
The code is missing null safety checks for main_branch before using it as a reference. If default_branch is None or if the project retrieval fails, this could lead to runtime errors. Add proper null checks and error handling.
The current implementation checks if any quick action string is contained anywhere in the model answer, which could lead to false positives. Instead, check if any line starts with a quick action to properly identify GitLab quick actions.
def gitlab_protections(self, model_answer: str) -> str:
github_quick_actions_MR = ["/approve", "/close", "/merge", "/reopen", "/unapprove", "/title", "/assign",
"/copy_metadata", "/target_branch"]
- if any(action in model_answer for action in github_quick_actions_MR):- str_err = "Model answer contains GitHub quick actions, which are not supported in GitLab"- get_logger().error(str_err)- return str_err+ lines = model_answer.split('\n')+ for line in lines:+ if any(line.strip().startswith(action) for action in github_quick_actions_MR):+ str_err = "Model answer contains GitHub quick actions, which are not supported in GitLab"+ get_logger().error(str_err)+ return str_err
return model_answer
Suggestion importance[1-10]: 8
__
Why: The suggestion correctly identifies a potential bug in the GitLab quick actions detection. The current implementation checks if actions appear anywhere in the text, which could flag false positives in normal text. The improved code properly checks if lines start with these actions, which is more accurate for detecting actual command usage.
Medium
General
Use specific exception handling
The exception handling is too broad. Catching all exceptions can hide unexpected errors and make debugging difficult. Consider catching specific exceptions like gitlab.exceptions.GitlabGetError for missing files or access issues.
Why: The suggestion improves error handling by catching specific exceptions rather than using a broad catch-all. This makes the code more maintainable and helps with debugging by logging unexpected errors while still handling expected failures gracefully.
✅ Fix function name and returnSuggestion Impact:The commit implemented both changes suggested: 1) Fixed the function name typo from 'gitlab_protctions' to 'gitlab_protections' in both the function definition and where it's called, and 2) Added the missing return statement to return model_answer when no quick actions are detected
code diff:
- def gitlab_protctions(self, model_answer: str) -> str:+ def gitlab_protections(self, model_answer: str) -> str:
github_quick_actions_MR = ["/approve", "/close", "/merge", "/reopen", "/unapprove", "/title", "/assign",
"/copy_metadata", "/target_branch"]
if any(action in model_answer for action in github_quick_actions_MR):
str_err = "Model answer contains GitHub quick actions, which are not supported in GitLab"
get_logger().error(str_err)
return str_err
+ return model_answer
def _prepare_pr_answer(self) -> str:
model_answer = self.prediction.strip()
@@ -130,7 +131,7 @@
model_answer_sanitized = model_answer.replace("\n/", "\n /")
model_answer_sanitized = model_answer_sanitized.replace("\r/", "\r /")
if isinstance(self.git_provider, GitLabProvider):
- model_answer_sanitized = self.gitlab_protctions(model_answer_sanitized)+ model_answer_sanitized = self.gitlab_protections(model_answer_sanitized)
The function has a typo in its name and doesn't handle the case where no quick actions are found. It should return the original model_answer when no quick actions are detected, otherwise it will return None or the error message, causing unexpected behavior.
-def gitlab_protctions(self, model_answer: str) -> str:+def gitlab_protections(self, model_answer: str) -> str:
github_quick_actions_MR = ["/approve", "/close", "/merge", "/reopen", "/unapprove", "/title", "/assign",
"/copy_metadata", "/target_branch"]
if any(action in model_answer for action in github_quick_actions_MR):
str_err = "Model answer contains GitHub quick actions, which are not supported in GitLab"
get_logger().error(str_err)
return str_err
+ return model_answer
[Suggestion has been applied]
Suggestion importance[1-10]: 9
__
Why: The suggestion fixes two critical issues: a typo in the function name and the missing return statement for the normal case. Without the return statement, the function would return None when no quick actions are found, causing unexpected behavior or potential errors.
High
✅ Fix function name typoSuggestion Impact:The commit fixed the typo in both the function definition (line 5-6) and the function call (line 21-22), exactly as suggested
code diff:
- def gitlab_protctions(self, model_answer: str) -> str:+ def gitlab_protections(self, model_answer: str) -> str:
github_quick_actions_MR = ["/approve", "/close", "/merge", "/reopen", "/unapprove", "/title", "/assign",
"/copy_metadata", "/target_branch"]
if any(action in model_answer for action in github_quick_actions_MR):
str_err = "Model answer contains GitHub quick actions, which are not supported in GitLab"
get_logger().error(str_err)
return str_err
+ return model_answer
def _prepare_pr_answer(self) -> str:
model_answer = self.prediction.strip()
@@ -130,7 +131,7 @@
model_answer_sanitized = model_answer.replace("\n/", "\n /")
model_answer_sanitized = model_answer_sanitized.replace("\r/", "\r /")
if isinstance(self.git_provider, GitLabProvider):
- model_answer_sanitized = self.gitlab_protctions(model_answer_sanitized)+ model_answer_sanitized = self.gitlab_protections(model_answer_sanitized)
The function name has a typo ('protctions' instead of 'protections'). This will cause a runtime error when the code is executed with a GitLab provider.
if isinstance(self.git_provider, GitLabProvider):
- model_answer_sanitized = self.gitlab_protctions(model_answer_sanitized)+ model_answer_sanitized = self.gitlab_protections(model_answer_sanitized)
[Suggestion has been applied]
Suggestion importance[1-10]: 9
__
Why: This suggestion correctly identifies a critical typo in the function call that would cause a runtime error when executed with a GitLab provider. The function is called as "gitlab_protctions" but defined as "gitlab_protctions", and this mismatch would break the code.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Type
Bug fix, Enhancement
Description
Fixed GitLab provider to use the default branch for repo settings.
Added protections to prevent GitHub quick actions in GitLab PR questions.
Enhanced PR answer sanitization for GitLab compatibility.
Changes walkthrough 📝
gitlab_provider.py
Use default branch for GitLab repo settings
pr_agent/git_providers/gitlab_provider.py
pr_questions.py
Add GitLab protections and improve answer sanitization
pr_agent/tools/pr_questions.py
GitLabProvider
.