From 9c0b677d38f713069159f53f649468c5ebde3e06 Mon Sep 17 00:00:00 2001 From: shenlei Date: Fri, 23 Oct 2026 11:02:28 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=80=9A=E7=94=A8=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=E4=BB=A5=20App=20=E5=AD=97=E6=AE=B5=E4=BD=9C=E4=B8=BA=E4=BA=A7?= =?UTF-8?q?=E7=89=A9=E6=96=87=E4=BB=B6=E5=90=8D=E5=92=8C=E9=80=9A=E7=9F=A5?= =?UTF-8?q?=E4=B8=AD=E7=9A=84=20App=20=E6=A0=87=E8=AF=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 通用项目(如朵云轩)没有 AppGuid,通知中 App Guid 为空、产物文件名以 _ 开头。 改为取第一个 App 字段(如 APPID)作为 App 标识,并在通知中显示该字段名; 未填写时回退到 upload_key。Readoor 项目不变。 Co-Authored-By: Claude Opus 5.5 --- backend/services/build_service.py | 9 +++++++- backend/services/notification.py | 2 +- tests/test_build_service.py | 36 ++++++++++++++++++++++++++++++- tests/test_notification.py | 13 ++++++++++- 4 files changed, 56 insertions(+), 4 deletions(-) diff --git a/backend/services/build_service.py b/backend/services/build_service.py index d64f9f6..3faacf8 100644 --- a/backend/services/build_service.py +++ b/backend/services/build_service.py @@ -20,7 +20,7 @@ from ..config import ( get_git_remote_url, mask_git_remote_url, ) -from ..projects import LEGACY_PROJECT_ID, get_definition, get_project_source +from ..projects import LEGACY_PROJECT_ID, PATCHER_READOOR, get_definition, get_project_source from .log_streamer import log_streamer from .distribution import DistributionError, publish_dsym, publish_ipa from .notification import NotificationError, send_dingtalk_notification @@ -808,6 +808,13 @@ async def generate_config(task_id: str, task, build_dir: Path) -> dict: config_data["APP_VARS"] = { field["key"]: app.get(field["key"], "") for field in definition["app_fields"] if field.get("key") } + # 通用项目没有 AppGuid:以第一个 App 字段(如 APPID)作为 App 标识, + # 用于产物文件名和通知;未配置 App 字段时用 upload_key。 + if definition["patcher"] != PATCHER_READOOR: + id_field = next((field for field in definition["app_fields"] if field.get("key")), None) + app_ident = config_data["APP_VARS"].get(id_field["key"], "") if id_field else "" + config_data["APPID"] = app_ident or config_data["UPLOAD_KEY"] + config_data["APPID_LABEL"] = (id_field.get("label") or id_field["key"]) if app_ident else "App 标识" config_data["SERVER_VARS"] = { field["key"]: server.get(field["key"], "") for field in definition["server_fields"] if field.get("key") } diff --git a/backend/services/notification.py b/backend/services/notification.py index eef732b..d087dd0 100644 --- a/backend/services/notification.py +++ b/backend/services/notification.py @@ -59,7 +59,7 @@ def build_dingtalk_payload( f"**版本:** {config_data.get('VERSION', '')}\n\n" f"**APP名称:** {config_data.get('APPID_NAME', '')}\n\n" f"**包名:** {config_data.get('BUNDLE_ID', '')}\n\n" - f"**App Guid:** {config_data.get('APPID', '')}" + f"**{config_data.get('APPID_LABEL', 'App Guid')}:** {config_data.get('APPID', '')}" ) text = f"## {heading}\n\n{details}\n\n**iOS 下载链接:** {download_url}\n" if qr_code_url: diff --git a/tests/test_build_service.py b/tests/test_build_service.py index 7f88a75..bf3ff9b 100644 --- a/tests/test_build_service.py +++ b/tests/test_build_service.py @@ -350,7 +350,41 @@ async def test_generate_config(tmp_path, log_streamer): assert saved["APPID"] == "guid-123" -def test_resolve_provisioning_profile_extracts_name_and_team(tmp_path): +@pytest.mark.parametrize("app_fields, appid, expected_id, expected_label", [ + ([{"key": "APPID", "label": "APPID"}], "1587365345", "1587365345", "APPID"), + ([{"key": "APPID", "label": "APPID"}], "", "dy_app", "App 标识"), + ([], "", "dy_app", "App 标识"), +]) +async def test_generate_config_generic_project_identifier( + tmp_path, log_streamer, app_fields, appid, expected_id, expected_label, +): + """通用项目没有 AppGuid,以第一个 App 字段作为产物文件名和通知中的 App 标识""" + build_dir = tmp_path / "build" + build_dir.mkdir() + + task = MagicMock() + task.project_id = "dyauction" + task.app_id = "1" + task.scheme_id = "1" + task.build_type = "Ad_Hoc" + task.obfuscation = False + + mock_config = { + "patcher": "generic", + "app_fields": app_fields, + "apps": {"1": {"name": "朵云轩", "server": "正式环境", "APPID": appid, "upload_key": "dy_app", + "certificates": {}}}, + "schemes": {"1": {"name": "DyAuction", "ossFloder": "dy"}}, + } + + with patch("backend.routers.config.load_config", return_value=mock_config): + result = await generate_config("t1", task, build_dir) + + assert result["APPID"] == expected_id + assert result["APPID_LABEL"] == expected_label + + + profile_path = tmp_path / "profile.mobileprovision" profile_path.write_bytes(b"signed profile") decoded = plistlib.dumps({"Name": "a4YX061_adHoc", "TeamIdentifier": ["MG4Z7FU83W"]}) diff --git a/tests/test_notification.py b/tests/test_notification.py index 367fe4b..f1d3d4c 100644 --- a/tests/test_notification.py +++ b/tests/test_notification.py @@ -35,7 +35,18 @@ def test_dingtalk_payload_matches_autopacking_content(): assert "![image](https://download.example.com/app.png)" in text -def test_dingtalk_payload_at_mobiles_appended_to_text_and_at_field(): +def test_dingtalk_payload_uses_project_identifier_label(): + payload = build_dingtalk_payload( + {**_build_config(), "APPID": "1587365345", "APPID_LABEL": "APPID"}, + "https://download.example.com/app.html", + ) + + text = payload["markdown"]["text"] + assert "**APPID:** 1587365345" in text + assert "App Guid" not in text + + + payload = build_dingtalk_payload( _build_config(), "https://download.example.com/app.html",