✨ webui与resources支持git更新

This commit is contained in:
HibiKier
2025-08-01 17:01:21 +08:00
parent ab7aad0488
commit 56bb311c2b
9 changed files with 99 additions and 35 deletions
+22 -12
View File
@@ -69,7 +69,7 @@ class AliyunCodeupManager(BaseRepoManager):
self._check_config()
# 获取仓库名称(从URL中提取)
repo_url = repo_url.split("/")[-1].replace(".git", "")
repo_url = repo_url.split("/tree/")[0].split("/")[-1].replace(".git", "")
# 获取仓库最新提交ID
newest_commit = await self._get_newest_commit(repo_url, branch)
@@ -77,7 +77,9 @@ class AliyunCodeupManager(BaseRepoManager):
# 创建结果对象
result = RepoUpdateResult(
repo_type=RepoType.ALIYUN,
repo_name=repo_url.split("/")[-1].replace(".git", ""),
repo_name=repo_url.split("/tree/")[0]
.split("/")[-1]
.replace(".git", ""),
owner=self.config.aliyun_codeup.organization_id,
old_version="", # 将在后面更新
new_version=newest_commit,
@@ -99,7 +101,7 @@ class AliyunCodeupManager(BaseRepoManager):
local_path.mkdir(parents=True, exist_ok=True)
# 获取仓库名称(从URL中提取)
repo_name = repo_url.split("/")[-1].replace(".git", "")
repo_name = repo_url.split("/tree/")[0].split("/")[-1].replace(".git", "")
# 获取变更的文件列表
changed_files = await self._get_changed_files(
@@ -135,7 +137,7 @@ class AliyunCodeupManager(BaseRepoManager):
except RepoUpdateError as e:
logger.error(f"更新仓库失败: {e}")
# 从URL中提取仓库名称
repo_name = repo_url.split("/")[-1].replace(".git", "")
repo_name = repo_url.split("/tree/")[0].split("/")[-1].replace(".git", "")
return RepoUpdateResult(
repo_type=RepoType.ALIYUN,
repo_name=repo_name,
@@ -147,7 +149,7 @@ class AliyunCodeupManager(BaseRepoManager):
except Exception as e:
logger.error(f"更新仓库失败: {e}")
# 从URL中提取仓库名称
repo_name = repo_url.split("/")[-1].replace(".git", "")
repo_name = repo_url.split("/tree/")[0].split("/")[-1].replace(".git", "")
return RepoUpdateResult(
repo_type=RepoType.ALIYUN,
repo_name=repo_name,
@@ -181,12 +183,16 @@ class AliyunCodeupManager(BaseRepoManager):
self._check_config()
# 获取仓库名称(从URL中提取)
repo_identifier = repo_url.split("/")[-1].replace(".git", "")
repo_identifier = (
repo_url.split("/tree/")[0].split("/")[-1].replace(".git", "")
)
# 创建结果对象
result = FileDownloadResult(
repo_type=RepoType.ALIYUN,
repo_name=repo_url.split("/")[-1].replace(".git", ""),
repo_name=repo_url.split("/tree/")[0]
.split("/")[-1]
.replace(".git", ""),
file_path=file_path,
version=branch,
)
@@ -206,7 +212,7 @@ class AliyunCodeupManager(BaseRepoManager):
except RepoDownloadError as e:
logger.error(f"下载文件失败: {e}")
# 从URL中提取仓库名称
repo_name = repo_url.split("/")[-1].replace(".git", "")
repo_name = repo_url.split("/tree/")[0].split("/")[-1].replace(".git", "")
return FileDownloadResult(
repo_type=RepoType.ALIYUN,
repo_name=repo_name,
@@ -217,7 +223,7 @@ class AliyunCodeupManager(BaseRepoManager):
except Exception as e:
logger.error(f"下载文件失败: {e}")
# 从URL中提取仓库名称
repo_name = repo_url.split("/")[-1].replace(".git", "")
repo_name = repo_url.split("/tree/")[0].split("/")[-1].replace(".git", "")
return FileDownloadResult(
repo_type=RepoType.ALIYUN,
repo_name=repo_name,
@@ -250,7 +256,9 @@ class AliyunCodeupManager(BaseRepoManager):
self._check_config()
# 获取仓库名称(从URL中提取)
repo_identifier = repo_url.split("/")[-1].replace(".git", "")
repo_identifier = (
repo_url.split("/tree/")[0].split("/")[-1].replace(".git", "")
)
# 获取文件列表
search_type = "RECURSIVE" if recursive else "DIRECT"
@@ -298,7 +306,9 @@ class AliyunCodeupManager(BaseRepoManager):
self._check_config()
# 获取仓库名称(从URL中提取)
repo_identifier = repo_url.split("/")[-1].replace(".git", "")
repo_identifier = (
repo_url.split("/tree/")[0].split("/")[-1].replace(".git", "")
)
# 获取提交信息
# 注意:这里假设AliyunFileInfo有get_commit_info方法,如果没有,需要实现
@@ -440,7 +450,7 @@ class AliyunCodeupManager(BaseRepoManager):
def prepare_aliyun_url(repo_url: str) -> str:
import base64
repo_name = repo_url.split("/")[-1].replace(".git", "")
repo_name = repo_url.split("/tree/")[0].split("/")[-1].replace(".git", "")
# 构建仓库URL
# 阿里云CodeUp的仓库URL格式通常为:
# https://codeup.aliyun.com/{organization_id}/{organization_name}/{repo_name}.git
+1 -1
View File
@@ -230,7 +230,7 @@ class BaseRepoManager(ABC):
"""
from .models import RepoType
repo_name = repo_url.split("/")[-1].replace(".git", "")
repo_name = repo_url.split("/tree/")[0].split("/")[-1].replace(".git", "")
try:
# 创建结果对象
+3 -1
View File
@@ -172,7 +172,9 @@ class GithubManager(BaseRepoManager):
返回:
FileDownloadResult: 下载结果
"""
repo_name = repo_url.split("/")[-1].replace(".git", "").strip()
repo_name = (
repo_url.split("/tree/")[0].split("/")[-1].replace(".git", "").strip()
)
try:
# 解析仓库URL
repo_info = GithubUtils.parse_github_url(repo_url)
+11
View File
@@ -31,6 +31,17 @@ async def check_git() -> bool:
return False
async def clean_git(cwd: Path):
"""
清理git仓库
参数:
cwd: 工作目录
"""
await run_git_command("reset --hard", cwd)
await run_git_command("clean -xdf", cwd)
async def run_git_command(
command: str, cwd: Path | None = None
) -> tuple[bool, str, str]: