From 372e92f5c510e312d369878ac2c95a2cd7f2584e Mon Sep 17 00:00:00 2001 From: xuaner Date: Thu, 17 Jul 2025 08:51:15 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(aliyun):=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E9=98=BF=E9=87=8C=E4=BA=91=E8=8E=B7=E5=8F=96commit=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- zhenxun/utils/github_utils/models.py | 50 ++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/zhenxun/utils/github_utils/models.py b/zhenxun/utils/github_utils/models.py index c7702c56..06e0ca33 100644 --- a/zhenxun/utils/github_utils/models.py +++ b/zhenxun/utils/github_utils/models.py @@ -445,6 +445,56 @@ class AliyunFileInfo: except Exception as e: raise ValueError(f"获取仓库树信息失败: {e}") + @classmethod + async def get_newest_commit(cls, repo: str, branch: str = "main") -> str: + """获取最新提交 + 参数: + repo: 仓库名称 + branch: sha 分支名称/标签名称/提交版本号 + 返回: + commit: 最新提交信息 + """ + try: + repository_id = ALIYUN_REPO_MAPPING.get(repo) + if not repository_id: + raise ValueError(f"未找到仓库 {repo} 对应的阿里云仓库ID") + + config = open_api_models.Config( + access_key_id=Aliyun_AccessKey_ID, + access_key_secret=base64.b64decode( + Aliyun_Secret_AccessKey_encrypted.encode() + ).decode(), + endpoint=ALIYUN_ENDPOINT, + region_id=ALIYUN_REGION, + ) + + client = devops20210625Client(config) + + request = devops_20210625_models.GetRepositoryCommitRequest( + organization_id=ALIYUN_ORG_ID, + access_token=base64.b64decode( + RDC_access_token_encrypted.encode() + ).decode(), + ) + + runtime = util_models.RuntimeOptions() + headers = {} + + response = await client.get_repository_commit_with_options_async( + repository_id, branch, request, headers, runtime + ) + + if response and response.body: + if not response.body.success: + raise ValueError( + f"阿里云请求失败: {response.body.error_code} - " + f"{response.body.error_message}" + ) + return response.body.result.id or "" + raise ValueError("获取仓库commit信息失败") + except Exception as e: + raise ValueError(f"获取仓库commit信息失败: {e}") + def export_files( self, tree_list: list[AliyunTree], module_path: str, is_dir: bool ) -> list[str]: