From 83069e7c7558509a91e23e404c06c952567ffe80 Mon Sep 17 00:00:00 2001 From: hukdoesn Date: Mon, 22 Sep 2025 12:27:37 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9E=20fix:=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E9=A1=B9=E7=9B=AE=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/apps/views/gitlab.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/backend/apps/views/gitlab.py b/backend/apps/views/gitlab.py index d880541..e706ccb 100644 --- a/backend/apps/views/gitlab.py +++ b/backend/apps/views/gitlab.py @@ -44,7 +44,21 @@ def get_gitlab_project(repository, git_token=None): repository_parts = repository.split('/') project_path = '/'.join(repository_parts[3:]) # 获取group/project部分 project_path = project_path.replace('.git', '') - return gl.projects.get(project_path) + + # 对项目路径进行URL编码 + import urllib.parse + encoded_path = urllib.parse.quote(project_path, safe='') + + try: + # 使用URL编码的路径 + return gl.projects.get(encoded_path) + except gitlab.exceptions.GitlabGetError: + # 失败,通过搜索项目名称获取项目id + projects = gl.projects.list(search=project_path.split('/')[-1]) + for project in projects: + if project.path_with_namespace == project_path: + return gl.projects.get(project.id) + raise gitlab.exceptions.GitlabGetError(f"Project {project_path} not found") except Exception as e: logger.error(f'获取GitLab项目失败: {str(e)}', exc_info=True) raise