Merge pull request #1662 from qodo-ai/tr/more_protections

Tr/more protections gitlab
This commit is contained in:
Tal
2025-03-31 14:02:33 +03:00
committed by GitHub
2 changed files with 15 additions and 2 deletions

View File

@ -515,7 +515,8 @@ class GitLabProvider(GitProvider):
def get_repo_settings(self):
try:
contents = self.gl.projects.get(self.id_project).files.get(file_path='.pr_agent.toml', ref=self.mr.target_branch).decode()
main_branch = self.gl.projects.get(self.id_project).default_branch
contents = self.gl.projects.get(self.id_project).files.get(file_path='.pr_agent.toml', ref=main_branch).decode()
return contents
except Exception:
return ""

View File

@ -9,7 +9,7 @@ from pr_agent.algo.pr_processing import get_pr_diff, retry_with_fallback_models
from pr_agent.algo.token_handler import TokenHandler
from pr_agent.algo.utils import ModelType
from pr_agent.config_loader import get_settings
from pr_agent.git_providers import get_git_provider
from pr_agent.git_providers import get_git_provider, GitLabProvider
from pr_agent.git_providers.git_provider import get_main_pr_language
from pr_agent.log import get_logger
from pr_agent.servers.help import HelpMessage
@ -116,10 +116,22 @@ class PRQuestions:
model=model, temperature=get_settings().config.temperature, system=system_prompt, user=user_prompt)
return response
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()
# sanitize the answer so that no line will start with "/"
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_protections(model_answer_sanitized)
if model_answer_sanitized.startswith("/"):
model_answer_sanitized = " " + model_answer_sanitized
if model_answer_sanitized != model_answer: