Class: Pindo::PgyerHelper
- Inherits:
-
Object
- Object
- Pindo::PgyerHelper
- Defined in:
- lib/pindo/module/pgyer/pgyerhelper.rb
Class Attribute Summary collapse
-
.instance ⇒ Object
writeonly
Sets the attribute instance.
Class Method Summary collapse
Instance Method Summary collapse
-
#bind_commit_to_package(commit_id:, project_package_ids:) ⇒ Hash
绑定 Git commit 到项目包.
- #find_app_info_with_obj_list(proj_name: nil, bundle_id: nil) ⇒ Object
-
#find_commit_log_by_git_commit_id(git_commit_id, workflow_id = nil) ⇒ Hash?
根据 git commit id 查找对应的 JPS commit_log 记录.
-
#format_file_size(size) ⇒ String
格式化文件大小.
-
#get_adhoc_upload_info(working_directory:, package_type:, conf: nil) ⇒ Array
获取 AdHoc 上传信息 用于 adhoc 编译命令,不保存配置到 JPSBuildConfig.json.
- #get_app_list_in_pgyer ⇒ Object
- #get_app_version(projectId: nil, app_version_index: nil, latest_version: true, package_type: nil) ⇒ Object
- #get_cert_list ⇒ Object
-
#get_commit_bound_package_ids(commit_id:, workflow_id:) ⇒ Array<String>
获取特定 commit 已绑定的包 ID.
- #get_description_from_git(current_project_dir: nil) ⇒ Object
-
#get_project_detail(project_id:) ⇒ Hash?
通过 project_id 获取项目详情(轻量接口,比 find_app_info_with_obj_list 更快).
- #get_user_local_wechat_url ⇒ Object
- #get_versioon_history_item(app_info_obj: nil, list_select_flat: false, package_type: nil) ⇒ Object
-
#get_workflow_bound_package_ids(workflow_id:) ⇒ Array<String>
deprecated
Deprecated.
使用 get_commit_bound_package_ids(commit_id:, workflow_id:) 替代
-
#get_workflow_latest_commit_id(workflow_id:) ⇒ String?
获取工作流中最新的 commit id.
-
#initialize(config_file: nil) ⇒ PgyerHelper
constructor
A new instance of PgyerHelper.
- #login ⇒ Object
- #modify_coment(app_info_obj: nil, version_item_obj: nil) ⇒ Object
-
#parse_jps_build_config(config_file:, package_type:, manage_type: "") ⇒ Hash
尝试从 JPSBuildConfig.json 加载配置.
- #prepare_upload(working_directory: nil, conf: nil, package_type: nil, manage_type: "", bundle_name: nil) ⇒ Object
- #print_app_version_info(app_info_obj: nil, app_version_info_obj: nil) ⇒ Object
- #resign(package_id: nil, cert_id: nil) ⇒ Object
- #resolve_lookup_bundle_id(bundle_name:, workflow_info:) ⇒ Object
-
#select_workflow_for_adhoc(project_id:, package_type:) ⇒ Hash
AdHoc 专用工作流选择 筛选条件: 1.
-
#select_workflow_for_project(project_id:, package_type:, working_directory:, manage_type: "") ⇒ Hash
为项目选择工作流.
- #send_apptest_msg(app_info_obj: nil, app_version_info_obj: nil, receiveType: "self", chatEnv: nil) ⇒ Object
- #send_apptest_wechat_msg(app_info_obj: nil, app_version_info_obj: nil, wechat_url: nil) ⇒ Object
-
#send_workflow_message(project_id:, workflow_id:, commit_id:, branch: 'master', single: true) ⇒ Hash
发送工作流消息(commit log 消息).
- #setForeLogin(beforeLogin: nil) ⇒ Object
-
#start_media_upload(file_paths:, git_commit_id:, workflow_id: nil) ⇒ Hash
上传 media 文件(图片、视频等)到 JPS 上传成功后自动更新 commit_log 记录.
- #start_upload(app_info_obj: nil, ipa_file_upload: nil, description: nil, workflow_info: nil) ⇒ Object
- #wildcard_android_bundle_name?(bundle_name) ⇒ Boolean
Constructor Details
#initialize(config_file: nil) ⇒ PgyerHelper
Returns a new instance of PgyerHelper.
28 29 30 31 32 33 |
# File 'lib/pindo/module/pgyer/pgyerhelper.rb', line 28 def initialize(config_file: nil) @force_login = false @has_login = false # PgyerHelper 提供默认配置路径 @config_file = config_file || File.join(File::(Pindoconfig.instance.pindo_common_configdir), "jps_client_config.json") end |
Class Attribute Details
.instance=(value) ⇒ Object (writeonly)
Sets the attribute instance
20 21 22 |
# File 'lib/pindo/module/pgyer/pgyerhelper.rb', line 20 def instance=(value) @instance = value end |
Class Method Details
.share_instace ⇒ Object
23 24 25 |
# File 'lib/pindo/module/pgyer/pgyerhelper.rb', line 23 def self.share_instace @instance ||= new end |
Instance Method Details
#bind_commit_to_package(commit_id:, project_package_ids:) ⇒ Hash
绑定 Git commit 到项目包
1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 |
# File 'lib/pindo/module/pgyer/pgyerhelper.rb', line 1855 def bind_commit_to_package(commit_id:, project_package_ids:) if commit_id.nil? || commit_id.empty? Funlog.instance.("commit_id 不能为空") return { success: false, error: "commit_id 不能为空" } end if project_package_ids.nil? || project_package_ids.empty? Funlog.instance.("project_package_ids 不能为空") return { success: false, error: "project_package_ids 不能为空" } end begin result = @pgyer_client.bind_commit_to_package( commitId: commit_id, projectPackageIds: project_package_ids ) # 兼容两种响应格式 response_code = result&.dig("code") || result&.dig("meta", "code") if result && (response_code == 0 || response_code == 200) return { success: true, result: result } else error_msg = result&.dig("msg") || result&.dig("meta", "message") || result&.dig("message") || "未知错误" return { success: false, error: error_msg, result: result } end rescue => e Funlog.instance.("绑定失败: #{e.}") return { success: false, error: e. } end end |
#find_app_info_with_obj_list(proj_name: nil, bundle_id: nil) ⇒ Object
1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 |
# File 'lib/pindo/module/pgyer/pgyerhelper.rb', line 1363 def find_app_info_with_obj_list(proj_name:nil, bundle_id:nil) if proj_name.nil? && bundle_id.nil? return nil end Funlog.instance.("正在拉取app信息列表,查找app信息...") get_app_list_in_pgyer() key_proj_name = proj_name&.downcase&.strip&.gsub(/[\s\-_]/, '') key_bundle_id = bundle_id&.downcase&.strip app_info_list = Pindoconfig.instance.get_pgyerapps_info_list() app_info_obj = nil if key_bundle_id && !key_bundle_id.empty? app_info_obj = app_info_list&.find do |app_info_item| app_info_bundle_id = app_info_item["bundleId"].to_s.downcase.strip app_info_bundle_id.eql?(key_bundle_id) end end if app_info_obj.nil? && key_proj_name && !key_proj_name.empty? app_info_obj = app_info_list&.find do |app_info_item| # 新 API 使用 projectName 字段 app_info_item_name = app_info_item["projectName"].to_s.downcase.strip.gsub(/[\s\-_]/, '') app_info_item_name.eql?(key_proj_name) end end Funlog.instance.("拉取app信息列表完成,app信息获取成功!") app_info_obj end |
#find_commit_log_by_git_commit_id(git_commit_id, workflow_id = nil) ⇒ Hash?
根据 git commit id 查找对应的 JPS commit_log 记录
1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 |
# File 'lib/pindo/module/pgyer/pgyerhelper.rb', line 1069 def find_commit_log_by_git_commit_id(git_commit_id, workflow_id = nil) params = { pageNo: 1, pageSize: 50 # 查询最近的 50 条记录 } # 如果指定了 workflow_id,添加到筛选条件 params[:workflowIds] = [workflow_id] if workflow_id begin list_result = @pgyer_client.get_commit_log_list(params: params) if list_result && list_result["data"] && list_result["data"]["details"] details = list_result["data"]["details"] # 遍历查找匹配的 commitId # 支持完整匹配或前缀匹配(git 短 SHA) commit_log = details.find do |item| item_commit_id = item["commitId"] next false unless item_commit_id # 完整匹配 if item_commit_id == git_commit_id true # 前缀匹配(支持 git 短 SHA,如 9e959ffd) elsif git_commit_id.length >= 7 && item_commit_id.start_with?(git_commit_id) true elsif git_commit_id.length >= 7 && git_commit_id.start_with?(item_commit_id) true else false end end return commit_log end rescue => e Funlog.instance.warning("查询 commit_log 列表失败: #{e.}") end nil end |
#format_file_size(size) ⇒ String
格式化文件大小
1676 1677 1678 1679 1680 1681 1682 1683 1684 |
# File 'lib/pindo/module/pgyer/pgyerhelper.rb', line 1676 def format_file_size(size) if size < 1024 "#{size}B" elsif size < 1024 * 1024 "#{(size / 1024.0).round(1)}KB" else "#{(size / 1024.0 / 1024.0).round(1)}MB" end end |
#get_adhoc_upload_info(working_directory:, package_type:, conf: nil) ⇒ Array
获取 AdHoc 上传信息用于 adhoc 编译命令,不保存配置到 JPSBuildConfig.json
393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 |
# File 'lib/pindo/module/pgyer/pgyerhelper.rb', line 393 def get_adhoc_upload_info(working_directory:, package_type:, conf: nil) # 确定配置文件路径 config_path = if conf && !conf.empty? File.(conf) else Pindo::BuildHelper.share_instance.determine_jps_config_path(working_directory) end upload_proj_name = nil # 尝试从配置文件读取项目名称 if File.exist?(config_path) begin config = JSON.parse(File.read(config_path)) upload_proj_name = config['project_name'] rescue => e puts "[get_adhoc_upload_info] 配置文件解析失败: #{e.}" end end # 配置文件中没有,从 IosConfigParser 获取 if upload_proj_name.nil? || upload_proj_name.empty? require 'pindo/config/ios_config_parser' config_parser = Pindo::IosConfigParser.instance if config_parser.config_json upload_proj_name = config_parser.config_json.dig("project_info", "project_name") end end # 仍为空,让用户输入 if upload_proj_name.nil? || upload_proj_name.empty? require 'highline/import' puts "\n未找到项目名称配置" upload_proj_name = ask("请输入 JPS 项目名称: ") do |q| q.validate = /\S+/ q.responses[:not_valid] = "项目名称不能为空" end upload_proj_name = upload_proj_name.strip if upload_proj_name end # 确保已登录 unless login raise Informative, "请先登录 JPS 网站" end # 获取 app_info_obj app_info_obj = find_app_info_with_obj_list(proj_name: upload_proj_name) unless app_info_obj raise Informative, "未找到项目: #{upload_proj_name},请检查项目名称是否正确" end # 4. 获取 AdHoc 工作流(调用专用函数) workflow_info = select_workflow_for_adhoc( project_id: app_info_obj["id"], package_type: package_type ) unless workflow_info raise Informative, "未能获取 AdHoc 工作流信息" end # 5. 输出最终选择的项目和工作流 puts "\n✓ 项目: #{app_info_obj['projectName']}" puts "✓ 工作流: #{workflow_info[:tab_name]}" # 6. 保存项目名称到实例变量 @proj_name = upload_proj_name # 7. 返回结果(不保存配置到 JPSBuildConfig.json) return app_info_obj, workflow_info end |
#get_app_list_in_pgyer ⇒ Object
1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 |
# File 'lib/pindo/module/pgyer/pgyerhelper.rb', line 1444 def get_app_list_in_pgyer() params = { pageNo:1, pageSize:1000 } app_info_list = Pindoconfig.instance.get_pgyerapps_info_list() if app_info_list.nil? res_data = @pgyer_client.get_project_list(params:params) if res_data && !res_data["data"].nil? && res_data["data"].size > 0 app_info_list = res_data["data"] Pindoconfig.instance.set_pgyerapps_info_list(app_info_list:app_info_list) elsif res_data error_msg = res_data["msg"] || "未知错误" error_code = res_data["code"] Funlog.instance.("拉取项目列表失败: [#{error_code}] #{error_msg}") end end if app_info_list.nil? Funlog.instance.("拉取app信息列表失败!") raise Informative, "JPS网络数据异常,请检查网络连接或重新登录(pindo repo login)" end return app_info_list end |
#get_app_version(projectId: nil, app_version_index: nil, latest_version: true, package_type: nil) ⇒ Object
1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 |
# File 'lib/pindo/module/pgyer/pgyerhelper.rb', line 1423 def get_app_version(projectId:nil, app_version_index:nil, latest_version:true, package_type:nil) params = {} params[:nativePackageType] = package_type if package_type version_data = @pgyer_client.get_project_package_list(projectId:projectId, params:params) version_item_obj = nil if latest_version version_item_obj = version_data["data"].find{ |item| item["latest"]} else if !app_version_index.nil? version_item_obj = version_data["data"].find{ |item| item["incId"].to_s.eql?(app_version_index.to_s)} end end # puts JSON.pretty_generate(version_item_obj) return version_item_obj end |
#get_cert_list ⇒ Object
1649 1650 1651 1652 1653 1654 1655 1656 1657 |
# File 'lib/pindo/module/pgyer/pgyerhelper.rb', line 1649 def get_cert_list( ) Funlog.instance.("正在获取可用证书...") result = @pgyer_client.get_cert_list() Funlog.instance.("获取可用证书完成!") return result["data"] end |
#get_commit_bound_package_ids(commit_id:, workflow_id:) ⇒ Array<String>
获取特定 commit 已绑定的包 ID
1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 |
# File 'lib/pindo/module/pgyer/pgyerhelper.rb', line 1691 def get_commit_bound_package_ids(commit_id:, workflow_id:) return [] if commit_id.nil? || commit_id.empty? return [] if workflow_id.nil? begin # 使用 commit_log/preview API 直接查询特定 commit result = @pgyer_client.get_commit_log_preview( workflowId: workflow_id, commitIds: [commit_id], params: { onlyCliff: false } # 需要完整信息 ) # 兼容两种响应格式 response_code = result&.dig("code") || result&.dig("meta", "code") if result && (response_code == 0 || response_code == 200) # 从响应中提取 commit 信息 # preview API 可能返回数组或单个对象 commit_data = result&.dig("data") commit_list = commit_data.is_a?(Array) ? commit_data : [commit_data].compact # 查找匹配的 commit commit_info = commit_list.find { |item| item && item["commitId"] == commit_id } if commit_info && commit_info["bindVersions"] # 从 bindVersions 中提取所有平台的 projectPackageId bind_versions = commit_info["bindVersions"] package_ids = [] # 遍历所有平台(ipa, apk, zip, mac, exe 等) bind_versions.each do |_platform, version_info| if version_info && version_info["projectPackageId"] package_ids << version_info["projectPackageId"] end end return package_ids.compact.uniq else # 如果没有找到或没有绑定信息,返回空数组(可能是首次绑定) if ENV['PINDO_DEBUG'] puts "[PINDO_DEBUG] Commit #{commit_id[0..7]} 没有绑定信息" end return [] end else # 如果获取失败,返回空数组(不阻止绑定流程) if ENV['PINDO_DEBUG'] error_msg = result&.dig("msg") || result&.dig("meta", "message") || "未知错误" puts "[PINDO_DEBUG] 获取 commit 绑定包失败: #{error_msg}" end return [] end rescue => e # 异常时返回空数组,不阻止绑定流程 if ENV['PINDO_DEBUG'] puts "[PINDO_DEBUG] 获取 commit 绑定包异常: #{e.}" puts "[PINDO_DEBUG] Backtrace: #{e.backtrace[0..2].join("\n")}" end return [] end end |
#get_description_from_git(current_project_dir: nil) ⇒ Object
1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 |
# File 'lib/pindo/module/pgyer/pgyerhelper.rb', line 1528 def get_description_from_git(current_project_dir:nil) description = nil # 检查是否是 git 仓库 if !current_project_dir.nil? && Pindo::GitHandler.is_git_directory?(local_repo_dir: current_project_dir) current_git_root_path = Pindo::GitHandler.git_root_directory(local_repo_dir: current_project_dir) # 检查 git-cliff 是否已安装 `git-cliff --version 2>&1` git_cliff_installed = $?.success? if git_cliff_installed temp_dir = Dir.pwd Dir.chdir(current_git_root_path) # 检查 HEAD 是否有 tag head_tag = `git describe --exact-match --tags HEAD 2>/dev/null`.strip has_tag_at_head = $?.success? && !head_tag.empty? # 根据 HEAD 是否有 tag 决定使用哪种参数 cliff_args = if has_tag_at_head # HEAD 有 tag,输出最新 tag 的更改(相对于前一个 tag) puts "HEAD 存在 tag: #{head_tag},使用 --latest 参数" if ENV['PINDO_DEBUG'] "--latest" else # HEAD 没有 tag,输出未发布的更改(从最新 tag 到 HEAD) puts "HEAD 不存在 tag,使用 --unreleased 参数" if ENV['PINDO_DEBUG'] "--unreleased" end # 尝试使用不同的配置文件策略 cliff_config_cmd = nil # 策略1: 使用项目根目录的 cliff.toml project_cliff_toml = File.join(current_git_root_path, "cliff.toml") if File.exist?(project_cliff_toml) puts "使用项目配置文件: #{project_cliff_toml}" if ENV['PINDO_DEBUG'] cliff_config_cmd = "git-cliff -c \"#{project_cliff_toml}\" #{cliff_args} -o -" else # 策略2: 使用 Pindo 默认配置文件(直接从 Pindoconfig 获取目录,避免更新仓库) pindo_common_dir = Pindoconfig.instance.pindo_common_configdir pindo_cliff_toml = File.join(pindo_common_dir, 'cliff.toml') if File.exist?(pindo_cliff_toml) puts "使用 Pindo 默认配置文件: #{pindo_cliff_toml}" if ENV['PINDO_DEBUG'] cliff_config_cmd = "git-cliff -c \"#{pindo_cliff_toml}\" #{cliff_args} -o -" end end # 执行 git-cliff 命令 if cliff_config_cmd # 分别捕获 stdout 和 stderr,只使用 stdout 作为描述 require 'open3' stdout, stderr, status = Open3.capture3(cliff_config_cmd) if status.success? description = stdout.strip # 如果有版本更新提示,输出到终端但不包含在描述中 if stderr && !stderr.empty? puts stderr if stderr.include?("new version") || ENV['PINDO_DEBUG'] end puts "git-cliff 输出成功" if ENV['PINDO_DEBUG'] else Funlog.warning("git-cliff 执行失败,使用默认描述") error_msg = stderr && !stderr.empty? ? stderr : stdout puts "错误信息: #{error_msg}" if ENV['PINDO_DEBUG'] # 使用默认描述而不是抛出异常 description = "版本更新" end else # 没有找到任何配置文件 Funlog.warning("未找到 cliff.toml 配置文件,使用默认描述") if ENV['PINDO_DEBUG'] puts "请确保:" puts " 1. 项目根目录存在 cliff.toml 文件" puts " 2. 或 Pindo 工具目录存在默认配置文件" end # 使用默认描述而不是抛出异常 description = "版本更新" end Dir.chdir(temp_dir) else # git-cliff 未安装,提示用户并退出 puts "\n\e[31m错误: git-cliff 未安装\e[0m" puts "\e[33m请先安装 git-cliff 工具:\e[0m" puts "\e[36m macOS: brew install git-cliff\e[0m" puts "\e[36m 或访问: https://github.com/orhun/git-cliff\e[0m" raise Informative, "git-cliff 未安装,无法生成版本描述" end else puts "当前目录不是 git 仓库" if ENV['PINDO_DEBUG'] end return description end |
#get_project_detail(project_id:) ⇒ Hash?
通过 project_id 获取项目详情(轻量接口,比 find_app_info_with_obj_list 更快)
1356 1357 1358 1359 1360 1361 |
# File 'lib/pindo/module/pgyer/pgyerhelper.rb', line 1356 def get_project_detail(project_id:) return nil if project_id.nil? || project_id.to_s.empty? result = @pgyer_client.get_project_detail(project_id: project_id) result&.dig("data") end |
#get_user_local_wechat_url ⇒ Object
1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 |
# File 'lib/pindo/module/pgyer/pgyerhelper.rb', line 1112 def get_user_local_wechat_url( ) wechat_msg_url = nil wechat_msg_url = PindoUserLocalConfig.instance.read_local_wechat_url if !wechat_msg_url.nil? && wechat_msg_url.length > 1 else wechat_msg_url = ask('请输入Wechat Url:') if !wechat_msg_url.nil? && wechat_msg_url.length > 1 PindoUserLocalConfig.instance.write_local_wechat_url(wechat_msg_url:wechat_msg_url) end end wechat_msg_url end |
#get_versioon_history_item(app_info_obj: nil, list_select_flat: false, package_type: nil) ⇒ Object
1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 |
# File 'lib/pindo/module/pgyer/pgyerhelper.rb', line 1472 def get_versioon_history_item(app_info_obj:nil, list_select_flat:false, package_type:nil) Funlog.instance.("正在拉取app上传记录...") projectId = app_info_obj["id"] # puts "projectId #{projectId}" params = {} params[:nativePackageType] = package_type if package_type params[:pageSize] = 25 # 增加默认返回数量 version_data = @pgyer_client.get_project_package_list(projectId:projectId, params:params) || {} Funlog.instance.("拉取app上传记录完成!") if version_data["data"].nil? || version_data["data"].size <=0 raise Informative, "#{proj_name} 错误, 没有找到上传记录" end app_incId_index = nil if list_select_flat #获取version_data 最后10个数 list_num = [version_data["data"].size, 10].min #获取version_data 最后10个的incId, bundleId, updateTime组成新数组 version_array_temp = version_data["data"].take(list_num).map do |item| { "appVersion" => item["projectVersion"] + "(build " + item["build"] + " )", "incId" => item["incId"], "bundleId" => item["bundleId"], "updateTime" => item["updateTime"] } end version_array_temp.each do |item| puts "版本:#{item["appVersion"]} Build号:#{item["incId"]} bundleId:#{item["bundleId"]} 上传时间:#{item["updateTime"]}" end app_incId_index = ask('请选择上面的Build号:') end version_item_obj = nil if !app_incId_index.nil? version_item_obj = version_data["data"].find{ |item| item["incId"].to_s.eql?(app_incId_index.to_s)} else version_item_obj = version_data["data"].find{ |item| item["latest"]} end version_item_obj end |
#get_workflow_bound_package_ids(workflow_id:) ⇒ Array<String>
使用 get_commit_bound_package_ids(commit_id:, workflow_id:) 替代
获取工作流中已绑定的包 ID(已废弃,请使用 get_commit_bound_package_ids)
1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 |
# File 'lib/pindo/module/pgyer/pgyerhelper.rb', line 1758 def get_workflow_bound_package_ids(workflow_id:) if ENV['PINDO_DEBUG'] puts "[PINDO_DEBUG] ⚠️ get_workflow_bound_package_ids 已废弃,请使用 get_commit_bound_package_ids" end return [] if workflow_id.nil? begin # 调用 JPS API 获取工作流详情 result = @pgyer_client.get_workflow_detail(workflowId: workflow_id) # 兼容两种响应格式 response_code = result&.dig("code") || result&.dig("meta", "code") if result && (response_code == 0 || response_code == 200) # 从响应中提取 boundPackageIds workflow_data = result&.dig("data") || result&.dig("result") bound_ids = workflow_data&.dig("boundPackageIds") || [] # 确保返回数组(兼容字符串和数组) bound_ids = [bound_ids] unless bound_ids.is_a?(Array) return bound_ids.compact else # 如果获取失败,返回空数组(不阻止绑定流程) if ENV['PINDO_DEBUG'] error_msg = result&.dig("msg") || result&.dig("meta", "message") || "未知错误" puts "[PINDO_DEBUG] 获取工作流绑定包失败: #{error_msg}" end return [] end rescue => e # 异常时返回空数组,不阻止绑定流程 if ENV['PINDO_DEBUG'] puts "[PINDO_DEBUG] 获取工作流绑定包异常: #{e.}" end return [] end end |
#get_workflow_latest_commit_id(workflow_id:) ⇒ String?
获取工作流中最新的 commit id
1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 |
# File 'lib/pindo/module/pgyer/pgyerhelper.rb', line 1802 def get_workflow_latest_commit_id(workflow_id:) return nil if workflow_id.nil? begin # 调用 JPS API 获取工作流详情 result = @pgyer_client.get_workflow_detail(workflowId: workflow_id) # 兼容两种响应格式 response_code = result&.dig("code") || result&.dig("meta", "code") if result && (response_code == 0 || response_code == 200) # 从响应中提取工作流数据 workflow_data = result&.dig("data") || result&.dig("result") # 尝试从不同字段获取最新的 commit id # 1. 尝试从 latestCommitId 字段获取 latest_commit = workflow_data&.dig("latestCommitId") # 2. 如果没有 latestCommitId,尝试从 commits 数组获取第一个 if latest_commit.nil? || latest_commit.empty? commits = workflow_data&.dig("commits") || [] latest_commit = commits.first&.dig("id") || commits.first&.dig("commitId") if commits.any? end # 3. 如果还是没有,尝试从 lastCommit 对象获取 if latest_commit.nil? || latest_commit.empty? last_commit = workflow_data&.dig("lastCommit") latest_commit = last_commit&.dig("id") || last_commit&.dig("commitId") end return latest_commit else # 如果获取失败,返回 nil if ENV['PINDO_DEBUG'] error_msg = result&.dig("msg") || result&.dig("meta", "message") || "未知错误" puts "[PINDO_DEBUG] 获取工作流最新 commit id 失败: #{error_msg}" end return nil end rescue => e # 异常时返回 nil if ENV['PINDO_DEBUG'] puts "[PINDO_DEBUG] 获取工作流最新 commit id 异常: #{e.}" end return nil end end |
#login ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/pindo/module/pgyer/pgyerhelper.rb', line 39 def login @pgyer_client = JPSClient::Client.new(config_file: @config_file) if @force_login || !@has_login @has_login = @pgyer_client.do_login(force_login:@force_login) @force_login = false else @has_login = @pgyer_client.do_login(force_login:false) end return @has_login end |
#modify_coment(app_info_obj: nil, version_item_obj: nil) ⇒ Object
1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 |
# File 'lib/pindo/module/pgyer/pgyerhelper.rb', line 1624 def modify_coment(app_info_obj:nil, version_item_obj:nil) current_project_dir = Dir.pwd comment_str = get_description_from_git(current_project_dir:current_project_dir) puts "==========================================" puts puts "#{comment_str}" puts puts "==========================================" puts if comment_str.nil? || comment_str.empty? Funlog.instance.("没有找到git备注信息,无法修改JPS备注!") else Funlog.instance.("开始修复JPS备注...") @pgyer_client.update_project_package(projectId:app_info_obj["id"], id:version_item_obj["id"], comment:comment_str.strip) Funlog.instance.("JPS备注已经修改!") end puts "备注信息修改成功!!" end |
#parse_jps_build_config(config_file:, package_type:, manage_type: "") ⇒ Hash
尝试从 JPSBuildConfig.json 加载配置
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/pindo/module/pgyer/pgyerhelper.rb', line 59 def parse_jps_build_config(config_file:, package_type:, manage_type: "") if ENV['PINDO_DEBUG'] puts "\n[PINDO_DEBUG] parse_jps_build_config 调用:" puts " config_file: #{config_file}" puts " package_type: #{package_type.inspect}" puts " manage_type: #{manage_type.inspect}" end result = { valid: false, project_name: nil, project_id: nil, workflow_info: nil } if ENV['PINDO_DEBUG'] puts "[PINDO_DEBUG] 配置文件路径: #{config_file}" puts "[PINDO_DEBUG] 文件存在: #{File.exist?(config_file)}" end unless File.exist?(config_file) puts "[PINDO_DEBUG] ❌ 配置文件不存在,返回 valid=false" if ENV['PINDO_DEBUG'] puts "[JPSConfig] 配置文件不存在" if ENV['PINDO_DEBUG'] return result end # 2. 读取并解析配置 begin config = JSON.parse(File.read(config_file)) puts "[PINDO_DEBUG] ✓ 配置文件解析成功" if ENV['PINDO_DEBUG'] rescue => e puts "[PINDO_DEBUG] ❌ 配置文件解析失败: #{e.}" if ENV['PINDO_DEBUG'] puts "[JPSConfig] 配置文件解析失败: #{e.}" return result end # 3. 提取项目信息 result[:project_name] = config['project_name'] result[:project_id] = config['project_id'] if ENV['PINDO_DEBUG'] puts "[PINDO_DEBUG] 配置文件内容:" puts " project_name: #{result[:project_name].inspect}" puts " project_id: #{result[:project_id].inspect}" puts " 配置keys: #{config.keys.inspect}" end # 4. 验证项目ID if result[:project_id].nil? || result[:project_id].to_s.empty? puts "[PINDO_DEBUG] ❌ 项目ID为空,返回 valid=false" if ENV['PINDO_DEBUG'] puts "[JPSConfig] 项目ID为空" if ENV['PINDO_DEBUG'] return result end # 5. 根据 manage_type 决定 workflow_key workflow_key = nil if manage_type == "git" # manage_type 为 git 时,直接使用 git_workflow workflow_key = 'git_workflow' puts "[PINDO_DEBUG] ✓ manage_type=git,使用 workflow_key='git_workflow'" if ENV['PINDO_DEBUG'] puts "[JPSConfig] 使用 git_workflow 配置" if ENV['PINDO_DEBUG'] else # 按 package_type 查找 workflow_key = case package_type when 'ipa' then 'ipa_workflow' when 'apk' then 'apk_workflow' when 'zip' then 'webgl_workflow' when 'mac' then 'macos_workflow' when 'exe' then 'win_workflow' else puts "[PINDO_DEBUG] ❌ 不支持的 package_type: #{package_type}" if ENV['PINDO_DEBUG'] puts "[JPSConfig] 不支持的 package_type: #{package_type}" return result end puts "[PINDO_DEBUG] package_type=#{package_type},使用 workflow_key='#{workflow_key}'" if ENV['PINDO_DEBUG'] end # 6. 验证工作流配置 workflow = config[workflow_key] if ENV['PINDO_DEBUG'] puts "[PINDO_DEBUG] 查找 workflow_key='#{workflow_key}'" puts "[PINDO_DEBUG] workflow 存在: #{!workflow.nil?}" puts "[PINDO_DEBUG] workflow 内容: #{workflow.inspect}" if workflow end unless workflow_valid?(workflow) puts "[PINDO_DEBUG] ❌ #{workflow_key} 配置无效或不完整,返回 valid=false" if ENV['PINDO_DEBUG'] puts "[JPSConfig] #{workflow_key} 配置无效或不完整" if ENV['PINDO_DEBUG'] return result end # 7. 所有验证通过 result[:valid] = true result[:workflow_info] = { workflow_id: workflow['workflow_id'], tab_name: workflow['tab_name'], package_name: workflow['package_name'], package_type: workflow['package_type'], manage_type: workflow['manage_type'] || "" } if ENV['PINDO_DEBUG'] puts "[PINDO_DEBUG] ✓✓✓ 配置验证通过 (#{workflow_key})" puts "[PINDO_DEBUG] 返回 valid=true,workflow_info:" puts " workflow_id: #{result[:workflow_info][:workflow_id]}" puts " tab_name: #{result[:workflow_info][:tab_name]}" puts " manage_type: #{result[:workflow_info][:manage_type]}" end puts "[JPSConfig] 配置验证通过 (#{workflow_key})" if ENV['PINDO_DEBUG'] return result end |
#prepare_upload(working_directory: nil, conf: nil, package_type: nil, manage_type: "", bundle_name: nil) ⇒ Object
466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 |
# File 'lib/pindo/module/pgyer/pgyerhelper.rb', line 466 def prepare_upload(working_directory:nil, conf:nil, package_type:nil, manage_type: "", bundle_name: nil) working_directory ||= Dir.pwd if ENV['PINDO_DEBUG'] puts "\n[PINDO_DEBUG] prepare_upload 调用参数:" puts " working_directory: #{working_directory}" puts " conf: #{conf.inspect}" puts " package_type: #{package_type.inspect}" puts " manage_type: #{manage_type.inspect}" end # 确定配置文件路径:显式指定 > 工作目录自动检测 > 工程目录自动检测 config_path = if conf && !conf.empty? File.(conf) else Pindo::BuildHelper.share_instance.determine_jps_config_path(working_directory) end puts "[PINDO_DEBUG] 使用配置文件: #{config_path}" if ENV['PINDO_DEBUG'] # 尝试从配置文件加载 if package_type || manage_type config_result = parse_jps_build_config( config_file: config_path, package_type: package_type, manage_type: manage_type ) puts "[PINDO_DEBUG] 配置加载结果: valid=#{config_result[:valid]}" if ENV['PINDO_DEBUG'] if config_result[:valid] puts "\n使用 JPSBuildConfig.json 配置:" puts " 项目: #{config_result[:project_name]}" puts " 工作流: #{config_result[:workflow_info][:tab_name]}" if ENV['PINDO_DEBUG'] puts "[PINDO_DEBUG] 配置详细信息:" puts " project_name: #{config_result[:project_name]}" puts " project_id: #{config_result[:project_id]}" puts " workflow_info: #{config_result[:workflow_info].inspect}" end unless login raise Informative, "请先登录JPS网站" end puts "[PINDO_DEBUG] 正在查找项目: #{config_result[:project_name]}" if ENV['PINDO_DEBUG'] lookup_bundle_id = resolve_lookup_bundle_id( bundle_name: bundle_name, workflow_info: config_result[:workflow_info] ) puts "[PINDO_DEBUG] bundle_id 查找键: #{lookup_bundle_id.inspect}" if ENV['PINDO_DEBUG'] app_info_obj = find_app_info_with_obj_list( proj_name: config_result[:project_name], bundle_id: lookup_bundle_id ) if app_info_obj puts "[PINDO_DEBUG] 项目找到,返回配置" if ENV['PINDO_DEBUG'] @proj_name = config_result[:project_name] return app_info_obj, config_result[:workflow_info] else puts "[PINDO_DEBUG] 配置的项目在 JPS 中不存在: #{config_result[:project_name]}" if ENV['PINDO_DEBUG'] puts "配置的项目不存在,将重新选择" end else puts "[PINDO_DEBUG] 配置无效,进入交互选择流程" if ENV['PINDO_DEBUG'] end end # ===== 配置无效或不存在,进入用户选择流程 ===== upload_proj_name = nil app_info_obj = nil if login if !app_info_obj.nil? # 如果提供了 package_type 或 manage_type,选择工作流并保存配置 if package_type || manage_type workflow_info = select_workflow_for_project( project_id: app_info_obj["id"], package_type: package_type, working_directory: working_directory, manage_type: manage_type ) save_jps_build_config( working_directory: working_directory, app_info_obj: app_info_obj, workflow_info: workflow_info, package_type: package_type, manage_type: manage_type ) @proj_name = upload_proj_name return app_info_obj, workflow_info else @proj_name = upload_proj_name return app_info_obj end end proj_name_array = [] proj_name_array = proj_name_array + PindoUserLocalConfig.instance.get_last_work_project_array() proj_name_array_append = [] # 尝试从 IosConfigParser 单例获取项目名称 begin require 'pindo/config/ios_config_parser' config_parser = Pindo::IosConfigParser.instance # 如果单例中有配置,使用配置中的项目名称 if !config_parser.config_json.nil? new_proj_string = config_parser.config_json.dig("project_info", "project_name") if !new_proj_string.nil? && !new_proj_string.empty? proj_name_array_append << new_proj_string end end rescue => e # 忽略错误,继续使用其他方式获取项目名称 end xcodeproj_file_name = Dir.glob(File.join(Dir.pwd, "/*.xcodeproj")).max_by {|f| File.mtime(f)} new_proj_string = File.basename(xcodeproj_file_name, ".xcodeproj") if xcodeproj_file_name if !new_proj_string.nil? && !new_proj_string.empty? proj_name_array_append << new_proj_string end dir_base_name = File.basename(working_directory) unless ["Desktop", "Documents", "Downloads"].include?(dir_base_name) proj_name_array_append << dir_base_name end proj_name_array_append.each do |new_string| if !new_string.nil? && !new_string.empty? if proj_name_array.size > 0 new_fromat_string = new_string.gsub(/[\s_]/, "") unless proj_name_array.any? { |s| s.gsub(/[\s_]/, "") == new_fromat_string } # 如果不存在相同字符串,插入到第一位 proj_name_array.push(new_string) end else proj_name_array.push(new_string) end end end proj_name_array.uniq proj_name_array << "自定义输入JPS上的项目名称" # 检查 GlobalOptionsState 缓存(上次交互选择的项目) cached_app_key = Pindo::Options::GlobalOptionsState.instance[:proj] if cached_app_key && proj_name_array.include?(cached_app_key) puts "\n使用之前选择的JPS项目: #{cached_app_key}" upload_proj_name = cached_app_key end # 只有在没有缓存或缓存无效,且没有环境变量时才显示选择菜单 if upload_proj_name.nil? || upload_proj_name.empty? if proj_name_array.size > 1 cli = HighLine.new upload_proj_name = cli.choose do || .prompt = "请选择JPS上的项目:" .choices(*proj_name_array) end if upload_proj_name.include?("自定义输入") upload_proj_name = ask('请输入JPS上的项目名称(大小写空格忽略):') || nil upload_proj_name = upload_proj_name.strip if upload_proj_name end else upload_proj_name = ask('请输入JPS上的项目名称(大小写空格忽略):') || nil upload_proj_name = upload_proj_name.strip if upload_proj_name end # 保存选择到 GlobalOptionsState(排除自定义输入选项) if upload_proj_name && !upload_proj_name.include?("自定义输入") Pindo::Options::GlobalOptionsState.instance[:proj] = upload_proj_name end end app_info_obj = PgyerHelper.share_instace.find_app_info_with_obj_list(proj_name:upload_proj_name) if app_info_obj.nil? upload_proj_name = ask('没有找到结果,请重新输入JPS上的项目名称(大小写空格忽略):') || nil upload_proj_name = upload_proj_name.strip if upload_proj_name app_info_obj = PgyerHelper.share_instace.find_app_info_with_obj_list(proj_name:upload_proj_name) end if app_info_obj.nil? raise Informative, "#{upload_proj_name} 名称错误, 请输入正确的项目名称,JPS网站没有该项目!!!" else # 记录上次上传的项目 PindoUserLocalConfig.instance.write_last_work_project(proj_name:app_info_obj["projectName"]) # 如果提供了 package_type 或 manage_type,选择工作流并保存配置 if package_type || manage_type workflow_info = select_workflow_for_project( project_id: app_info_obj["id"], package_type: package_type, working_directory: working_directory, manage_type: manage_type ) save_jps_build_config( working_directory: working_directory, app_info_obj: app_info_obj, workflow_info: workflow_info, package_type: package_type, manage_type: manage_type ) @proj_name = upload_proj_name return app_info_obj, workflow_info end end else raise Informative, "请先登录JPS网站" end @proj_name = upload_proj_name app_info_obj end |
#print_app_version_info(app_info_obj: nil, app_version_info_obj: nil) ⇒ Object
1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 |
# File 'lib/pindo/module/pgyer/pgyerhelper.rb', line 1293 def print_app_version_info(app_info_obj:nil, app_version_info_obj:nil) # 打印应用版本信息和二维码 return if app_info_obj.nil? || app_version_info_obj.nil? # 从对象提取信息 app_name = app_info_obj["projectName"] download_password = app_info_obj["password"] download_url = "#{app_info_obj["downloadUrl"]}?id=#{app_version_info_obj["id"]}" bundle_id = app_version_info_obj["bundleId"] project_version = app_version_info_obj["projectVersion"] build_version = app_version_info_obj["build"] index_no = app_version_info_obj["indexNo"] || app_version_info_obj["incId"] update_time = app_version_info_obj["updateTime"] description = app_version_info_obj["description"] app_size = app_version_info_obj["appSize"] # 格式化上传时间(时间戳转换为可读格式) if update_time if update_time.is_a?(String) && update_time =~ /^\d+$/ # 如果是字符串格式的时间戳 update_time = update_time.to_i end if update_time.is_a?(Integer) # 将毫秒时间戳转换为秒 update_time = update_time / 1000 if update_time > 9999999999 formatted_time = Time.at(update_time).strftime("%Y-%m-%d %H:%M:%S") else formatted_time = update_time end else formatted_time = "未知" end # appSize已经是格式化后的字符串,直接使用 formatted_size = app_size # 生成二维码 qrcode = RQRCode::QRCode.new(download_url) svg = qrcode.as_ansi( light: "\033[47m", dark: "\033[40m", fill_character: " ", quiet_zone_size: 1, size: 300 ) puts "\r\n\r\n\r\n\r\n" puts svg puts puts "#{app_name} 测试" puts "Bundle Id: #{bundle_id}" puts "版本号: #{project_version} (Build #{build_version})" puts "序号: #{index_no}" puts "包大小: #{formatted_size}" if formatted_size puts "安装密码: #{download_password}" puts "上传时间: #{formatted_time}" puts "链接: #{download_url}" puts "说明: #{description}" puts "\r\n\r\n\r\n\r\n" end |
#resign(package_id: nil, cert_id: nil) ⇒ Object
1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 |
# File 'lib/pindo/module/pgyer/pgyerhelper.rb', line 1659 def resign(package_id:nil, cert_id:nil) Funlog.instance.("正在重签名...") result = @pgyer_client.sign_project_package(packageId:package_id, certId:cert_id) if !result.nil? && (result["code"] == 0 || result["code"] == 200) && result["data"] == "success" Funlog.instance.("重签名成功!") return true else Funlog.instance.("重签名失败!") return false end end |
#resolve_lookup_bundle_id(bundle_name:, workflow_info:) ⇒ Object
1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 |
# File 'lib/pindo/module/pgyer/pgyerhelper.rb', line 1406 def resolve_lookup_bundle_id(bundle_name:, workflow_info:) return nil if bundle_name.nil? || bundle_name.empty? if wildcard_android_bundle_name?(bundle_name) package_name = workflow_info && workflow_info[:package_name] return nil if package_name.nil? || package_name.empty? prefix = bundle_name.sub(/\.\*$/, '').sub(/\.$/, '') return nil if prefix.empty? package_suffix = package_name.to_s.gsub(/[^a-zA-Z0-9]/, '').downcase return "#{prefix}.#{package_suffix}" end bundle_name end |
#select_workflow_for_adhoc(project_id:, package_type:) ⇒ Hash
AdHoc 专用工作流选择筛选条件:
1. package_type 匹配
2. tab_name 必须包含 "提交包"
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 |
# File 'lib/pindo/module/pgyer/pgyerhelper.rb', line 301 def select_workflow_for_adhoc(project_id:, package_type:) # 1. 从 JPS API 获取可用工作流列表 workflow_result = @pgyer_client.get_project_workflows(project_id: project_id) if workflow_result.nil? || workflow_result['data'].nil? raise Informative, "获取工作流列表失败" end workflows = workflow_result['data'] if workflows.empty? raise Informative, "该项目没有可用的工作流" end # 2. 第一层过滤:根据 package_type filtered_by_type = workflows.select do |w| if w['packageType'] case package_type when 'ipa' w['packageType'] == 'ipa' when 'apk' w['packageType'] == 'apk' when 'zip' w['packageType'] == 'zip' when 'mac' w['packageType'] == 'mac' else true end else # 如果没有 packageType 字段,保留(后续通过名称筛选) true end end # 3. 第二层过滤:tab_name 必须包含 "提交包" adhoc_workflows = filtered_by_type.select do |w| tab_name = w['tabName'] || w['tab_name'] || '' tab_name.include?('提交包') end if adhoc_workflows.empty? raise Informative, "未找到符合条件的 AdHoc 工作流\n" \ "要求:package_type=#{package_type} 且 tab_name 包含 '提交包'\n" \ "请检查 JPS 工作流配置" end # 4. 根据匹配数量决定选择方式 workflow = nil if adhoc_workflows.size == 1 # 只有 1 个匹配,自动选择 workflow = adhoc_workflows.first else # 有多个匹配,让用户选择 require 'highline/import' cli = HighLine.new workflow_choices = adhoc_workflows.map do |w| tab_name = w['tabName'] || w['tab_name'] workflow_id = w['id'] || w['workflow_id'] "#{tab_name} (ID: #{workflow_id})" end selected = cli.choose do || .prompt = "请选择 AdHoc 工作流:" .choices(*workflow_choices) end # 提取选择的工作流 selected_index = workflow_choices.index(selected) workflow = adhoc_workflows[selected_index] end # 5. 返回标准化的工作流信息 { workflow_id: workflow['id'] || workflow['workflow_id'], tab_name: workflow['tabName'] || workflow['tab_name'], package_type: workflow['packageType'] || package_type, package_name: workflow['packageName'] || workflow['package_name'] || '', manage_type: workflow['manageType'] || workflow['manage_type'] || '' } end |
#select_workflow_for_project(project_id:, package_type:, working_directory:, manage_type: "") ⇒ Hash
为项目选择工作流
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 |
# File 'lib/pindo/module/pgyer/pgyerhelper.rb', line 180 def select_workflow_for_project(project_id:, package_type:, working_directory:, manage_type: "") # 1. 从 JPS API 获取可用工作流列表 Funlog.instance.("正在获取可用工作流...") workflow_result = @pgyer_client.get_project_workflows(project_id: project_id) if workflow_result.nil? || workflow_result['data'].nil? raise Informative, "获取工作流列表失败" end workflows = workflow_result['data'] if workflows.empty? raise Informative, "该项目没有可用的工作流" end puts "package_type #{package_type} manage_type: #{manage_type}" Funlog.instance.("获取工作流列表成功,共 #{workflows.size} 个工作流") # 2. 根据 manage_type 或 package_type 过滤工作流 if manage_type == "git" # manage_type 为 git 时,只筛选 manage_type == "git" 的工作流,不看 package_type # 严格筛选,不包括 manage_type 为空或其他类型的工作流 filtered_workflows = workflows.select do |w| (w['manageType'] == 'git') || (w['manage_type'] == 'git') end type_desc = 'Git 管理类型' # manage_type == "git" 时严格使用筛选结果,不降级 display_workflows = filtered_workflows else # 按 package_type 过滤工作流 filtered_workflows = workflows.select do |w| # 如果工作流有 packageType 字段,进行过滤 if w['packageType'] case package_type when 'ipa' w['packageType'] == 'ipa' when 'apk' w['packageType'] == 'apk' when 'zip' w['packageType'] == 'zip' when 'mac' w['packageType'] == 'mac' when 'exe' w['packageType'] == 'exe' else true end else # 如果没有 packageType 字段,显示所有工作流 true end end type_desc = case package_type when 'ipa' then 'iOS IPA' when 'apk' then 'Android APK' when 'zip' then 'WebGL' when 'mac' then 'macOS App' when 'exe' then 'Windows EXE' else package_type end # 非 git 模式下,如果过滤后没有结果,使用所有工作流 display_workflows = filtered_workflows.empty? ? workflows : filtered_workflows end # 3. 根据匹配数量决定选择方式 workflow = nil if display_workflows.empty? # 情况1: 没有匹配的工作流 error_msg = if manage_type == "git" "没有找到匹配 #{type_desc} 的工作流,请在 JPS 后台创建 Git 类型工作流(项目ID: #{project_id})" else "没有找到匹配 #{type_desc} 的工作流,请在 JPS 后台配置(项目ID: #{project_id})" end raise Informative, error_msg elsif display_workflows.size == 1 # 情况2: 只有1个匹配的工作流,自动选择 workflow = display_workflows.first workflow_name = workflow['tabName'] || workflow['tab_name'] Funlog.instance.("自动选择唯一匹配的工作流: #{workflow_name}") else # 情况3: 有多个匹配的工作流,让用户选择 cli = HighLine.new workflow_choices = display_workflows.map do |w| "#{w['tabName'] || w['tab_name']} (ID: #{w['id'] || w['workflow_id']})" end selected = cli.choose do || .prompt = "请选择 #{type_desc} 工作流:" .choices(*workflow_choices) end # 提取选择的工作流 selected_index = workflow_choices.index(selected) workflow = display_workflows[selected_index] end # 4. 返回标准化的工作流信息 { workflow_id: workflow['id'] || workflow['workflow_id'], tab_name: workflow['tabName'] || workflow['tab_name'], package_name: workflow['packageName'] || workflow['package_name'] || workflow['tabName'] || workflow['tab_name'], package_type: package_type, manage_type: workflow['manageType'] || workflow['manage_type'] || "" } end |
#send_apptest_msg(app_info_obj: nil, app_version_info_obj: nil, receiveType: "self", chatEnv: nil) ⇒ Object
1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 |
# File 'lib/pindo/module/pgyer/pgyerhelper.rb', line 1128 def send_apptest_msg(app_info_obj:nil, app_version_info_obj:nil, receiveType:"self", chatEnv:nil) # 发送飞书测试消息 # 参数: # - app_info_obj: 项目信息对象 # - app_version_info_obj: 版本信息对象 # - receiveType: 接收类型 ("self" 或 "chat") # - chatEnv: 聊天环境 return false if app_info_obj.nil? || app_version_info_obj.nil? projectId = app_info_obj["id"] packageId = app_version_info_obj["id"] indexNo = app_version_info_obj["indexNo"] if projectId.nil? || packageId.nil? Funlog.instance.("缺少必要的项目ID或包ID") return false end # 根据接收类型显示不同的提示信息 if receiveType == "self" Funlog.instance.("正在发送飞书消息给个人...") elsif receiveType == "chat" if chatEnv == "DevTest" Funlog.instance.("正在发送飞书消息到开发测试群组...") elsif chatEnv == "PreFavTest" Funlog.instance.("正在发送飞书消息到预发布群组...") else Funlog.instance.("正在发送飞书消息到项目群组...") end else Funlog.instance.("正在发送飞书消息到项目群组...") end # 注意:当前版本的 jpsclient 可能不支持 indexNo 参数 result = @pgyer_client.( projectId: projectId, packageId: packageId, chatEnv: chatEnv, receiveType: receiveType, indexNo: indexNo ) if !result.nil? && (result["code"] == 0 || result["code"] == 200 || result["code"].to_s == "0" || result["code"].to_s == "200") # 如果返回码是0或200,无论data是什么都认为成功(支持新旧API响应码) if receiveType == "self" Funlog.instance.("测试信息已发送到飞书(个人)!") elsif receiveType == "chat" if chatEnv == "DevTest" Funlog.instance.("测试信息已发送到飞书开发测试群组!") elsif chatEnv == "PreFavTest" Funlog.instance.("测试信息已发送到飞书预发布群组!") else Funlog.instance.("测试信息已发送到飞书项目群组!") end else Funlog.instance.("测试信息已发送到飞书项目群组!") end return true else if result.nil? Funlog.instance.("未发送飞书测试信息!错误: 请求失败") elsif result["msg"] && !result["msg"].empty? Funlog.instance.("未发送飞书测试信息!错误: #{result["msg"]}") elsif result["message"] && !result["message"].empty? Funlog.instance.("未发送飞书测试信息!错误: #{result["message"]}") else Funlog.instance.("未发送飞书测试信息!错误: 响应码 #{result["code"]}") end return false end end |
#send_apptest_wechat_msg(app_info_obj: nil, app_version_info_obj: nil, wechat_url: nil) ⇒ Object
1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 |
# File 'lib/pindo/module/pgyer/pgyerhelper.rb', line 1202 def send_apptest_wechat_msg(app_info_obj:nil, app_version_info_obj:nil, wechat_url:nil) # 发送企业微信消息 return false if app_info_obj.nil? || app_version_info_obj.nil? wechat_msg_url = wechat_url if wechat_msg_url.nil? || wechat_msg_url.empty? wechat_msg_url = get_user_local_wechat_url() end if wechat_msg_url.nil? || wechat_msg_url.empty? puts "企业微信Wechat Url无效" return false end begin # 从对象提取信息 app_name = app_info_obj["projectName"] download_password = app_info_obj["password"] download_url = "#{app_info_obj["downloadUrl"]}?id=#{app_version_info_obj["id"]}" bundle_id = app_version_info_obj["bundleId"] app_version = app_version_info_obj["projectVersion"] index_num = app_version_info_obj["incId"] upload_time = app_version_info_obj["updateTime"] description = app_version_info_obj["description"] msg_from = @pgyer_client.token["username"] || " " # current_dir = current_dir = Dir.pwd # output_file = File.join(current_dir, app_name + "_qrcode.png") qrcode = RQRCode::QRCode.new(download_url) png = qrcode.as_png( bit_depth: 1, border_modules: 4, color_mode: ChunkyPNG::COLOR_GRAYSCALE, color: "black", file: nil, fill: "white", module_px_size: 6, resize_exactly_to: false, resize_gte_to: false, size: 300 ) checksum = Digest::MD5.hexdigest(png.to_s) image_base64_data = Base64.strict_encode64(png.to_s) body_data = { msgtype:"image", image:{ base64: image_base64_data, md5:checksum } } con = Faraday.new res = con.post do |req| req.url wechat_msg_url req.headers['Content-Type'] = 'application/json' req.body = body_data.to_json end body_data = { msgtype:"text", text:{ content: "#{app_name} 测试\r\r版本号: #{app_version} build:#{index_num}\r安装密码: #{download_password}\r上传时间: #{upload_time}\rBundle Id: #{bundle_id}\r链接:#{download_url}\r\n说明:\r\r#{description}\r\r消息发送来自: #{msg_from}" } } con = Faraday.new res = con.post do |req| req.url wechat_msg_url req.headers['Content-Type'] = 'application/json' req.body = body_data.to_json end puts puts "发送企业微信成功 !!!" puts rescue StandardError => e puts puts "发送企业微信失败 !!!" puts end end |
#send_workflow_message(project_id:, workflow_id:, commit_id:, branch: 'master', single: true) ⇒ Hash
发送工作流消息(commit log 消息)
1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 |
# File 'lib/pindo/module/pgyer/pgyerhelper.rb', line 1895 def (project_id:, workflow_id:, commit_id:, branch: 'master', single: true) if project_id.nil? || project_id.empty? Funlog.instance.("project_id 不能为空") return { success: false, error: "project_id 不能为空" } end if workflow_id.nil? Funlog.instance.("workflow_id 不能为空") return { success: false, error: "workflow_id 不能为空" } end if commit_id.nil? || commit_id.empty? Funlog.instance.("commit_id 不能为空") return { success: false, error: "commit_id 不能为空" } end begin result = @pgyer_client.( projectId: project_id, workflowId: workflow_id, params: { single: single, branch: branch, commitIds: [commit_id] } ) # 兼容两种响应格式 response_code = result&.dig("code") || result&.dig("meta", "code") if result && (response_code == 0 || response_code == 200) return { success: true, result: result } else error_msg = result&.dig("msg") || result&.dig("meta", "message") || result&.dig("message") || "未知错误" return { success: false, error: error_msg, result: result } end rescue => e Funlog.instance.("发送工作流消息失败: #{e.}") return { success: false, error: e. } end end |
#setForeLogin(beforeLogin: nil) ⇒ Object
35 36 37 |
# File 'lib/pindo/module/pgyer/pgyerhelper.rb', line 35 def setForeLogin(beforeLogin:nil) @force_login = beforeLogin end |
#start_media_upload(file_paths:, git_commit_id:, workflow_id: nil) ⇒ Hash
上传 media 文件(图片、视频等)到 JPS 上传成功后自动更新 commit_log 记录
923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 |
# File 'lib/pindo/module/pgyer/pgyerhelper.rb', line 923 def start_media_upload(file_paths:, git_commit_id:, workflow_id: nil) result = { success_urls: [], failed_files: [], existing_urls: [], all_urls: [], commit_log_id: nil, git_commit_id: git_commit_id, update_success: false } # 1. 验证参数 if file_paths.nil? || file_paths.empty? Funlog.instance.("未提供要上传的文件") return result end if git_commit_id.nil? || git_commit_id.empty? Funlog.instance.("git_commit_id 不能为空") return result end # 2. 根据 git_commit_id 查找对应的 commit_log 记录 Funlog.instance.("查找 JPS 提交记录...") commit_log = find_commit_log_by_git_commit_id(git_commit_id, workflow_id) if commit_log.nil? Funlog.instance.("未找到对应的 JPS 提交记录") Funlog.instance.warning("请确保该 commit 已通过 JPS 发送过消息") return result end commit_log_id = commit_log["id"] result[:commit_log_id] = commit_log_id Funlog.instance.("找到提交记录 ##{commit_log_id}") puts " #{commit_log["projectName"]} / #{commit_log["tabName"]} / #{commit_log["branch"]}" # 3. 获取已存在的 fileUrls if commit_log["fileUrls"] && commit_log["fileUrls"].any? result[:existing_urls] = commit_log["fileUrls"] puts " 已有附件: #{result[:existing_urls].size} 个" end puts "" # 4. 显示待上传的文件列表 puts " 📤 待上传文件(共 #{file_paths.size} 个)" file_paths.each_with_index do |file_path, index| if File.exist?(file_path) size_bytes = File.size(file_path) size_str = format_file_size(size_bytes) file_name = File.basename(file_path) puts " #{index + 1}. #{file_name} (#{size_str})" end end puts "" # 5. 使用 UploadMediaClient 并发上传文件 Funlog.instance.("正在上传...") media_client = JPSClient::UploadMediaClient.new(@pgyer_client) # 在非调试模式下,临时重定向 JPSClient 的输出 if ENV['PINDO_DEBUG'] upload_result = media_client.upload_files(file_paths: file_paths) else # 保存原始的 stdout original_stdout = $stdout.clone # 临时重定向到 /dev/null $stdout.reopen(File.new('/dev/null', 'w')) begin upload_result = media_client.upload_files(file_paths: file_paths) ensure # 恢复原始的 stdout $stdout.reopen(original_stdout) end end # 6. 提取上传结果 result[:success_urls] = upload_result["success_urls"] result[:failed_files] = upload_result["failed_files"] # 显示上传结果 if result[:failed_files].any? Funlog.instance.("上传完成:成功 #{result[:success_urls].size} 个,失败 #{result[:failed_files].size} 个") else Funlog.instance.("上传完成:成功 #{result[:success_urls].size} 个") end # 7. 合并 URL 列表 result[:all_urls] = result[:existing_urls] + result[:success_urls] # 8. 更新 commit_log if result[:success_urls].any? Funlog.instance.("更新提交记录...") begin update_result = @pgyer_client.update_commit_log( id: commit_log_id, params: { fileUrls: result[:all_urls] } ) # 兼容两种响应格式: # 1. 新格式:{"code": 0, "data": ..., "msg": ...} # 2. 旧格式:{"meta": {"code": 0}, ...} response_code = update_result&.dig("code") || update_result&.dig("meta", "code") if update_result && (response_code == 0 || response_code == 200) result[:update_success] = true Funlog.instance.("附件已更新(共 #{result[:all_urls].size} 个)") else # 提取详细错误信息 error_code = update_result&.dig("code") || update_result&.dig("meta", "code") error_msg = update_result&.dig("msg") || update_result&.dig("meta", "message") || update_result&.dig("message") if ENV['PINDO_DEBUG'] puts "[PINDO_DEBUG] update_commit_log 返回结果: #{update_result.inspect}" puts "[PINDO_DEBUG] commit_log_id: #{commit_log_id}" puts "[PINDO_DEBUG] fileUrls: #{result[:all_urls].inspect}" end error_detail = error_msg || "未知错误" error_detail = "#{error_detail} (错误码: #{error_code})" if error_code Funlog.instance.("更新失败: #{error_detail}") end rescue => e Funlog.instance.("更新失败: #{e.}") puts "[PINDO_DEBUG] 异常详情: #{e.class} - #{e.backtrace&.first}" if ENV['PINDO_DEBUG'] end else Funlog.instance.warning("没有成功上传的文件") end # 9. 输出统计(简化,因为上面已经显示了上传结果) if result[:all_urls].size > result[:success_urls].size puts " 总附件数: #{result[:all_urls].size} 个(包含之前已有的 #{result[:existing_urls].size} 个)" end puts "" return result end |
#start_upload(app_info_obj: nil, ipa_file_upload: nil, description: nil, workflow_info: nil) ⇒ Object
695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 |
# File 'lib/pindo/module/pgyer/pgyerhelper.rb', line 695 def start_upload(app_info_obj:nil, ipa_file_upload:nil, description:nil, workflow_info:nil) # 验证 workflow_info 必传 if workflow_info.nil? || workflow_info[:workflow_id].nil? raise Informative, "workflow_info 和 workflow_id 是必传参数,请确保调用 prepare_upload 时传入了 package_type" end if !ipa_file_upload.nil? && File.extname(ipa_file_upload).eql?(".app") mac_app_path = ipa_file_upload ipa_base_dir = File.dirname(ipa_file_upload) ipa_base_name = File.basename(ipa_file_upload, File.extname(ipa_file_upload)) ipa_file_upload = File.join(ipa_base_dir, ipa_base_name + ".zip") if File.exist?(ipa_file_upload) FileUtils.rm_rf(ipa_file_upload) end current_dir = Dir.pwd if File.exist?(ipa_base_dir) Dir.chdir(ipa_base_dir) base_name = File.basename(mac_app_path) command = "zip -qry \"#{ipa_file_upload}\" \"#{base_name}\"" puts command system command Dir.chdir(current_dir) end end if !ipa_file_upload.nil? && File.extname(ipa_file_upload).eql?(".html") web_res_path = File.dirname(ipa_file_upload) web_zip_dir = File.dirname(web_res_path) web_build_name = "webgl_build" web_build_version = "1.0.0" begin # web_build_info.json 应该和 index.html 在同一目录 if File.exist?(File.join(web_res_path, "web_build_info.json")) json_data = JSON.parse(File.read(File.join(web_res_path, "web_build_info.json"))) web_build_name = json_data["productName"] web_build_version = json_data["version"] end rescue StandardError => e end current_project_dir = Dir.pwd web_build_name = web_build_name.downcase.strip.gsub(/[\s\-_]/, '') web_res_zip_fullname = File.join(web_zip_dir, web_build_name + "_" + web_build_version + ".zip") if File.exist?(web_res_zip_fullname) FileUtils.rm_rf(web_res_zip_fullname) end Zip::File.open(web_res_zip_fullname, Zip::File::CREATE) do |zipfile| Dir.chdir web_res_path Dir.glob("**/*").reject {|fn| File.directory?(fn) }.each do |file| zipfile.add(file.sub(web_res_path + '/', ''), file) end end Dir.chdir(current_project_dir) ipa_file_upload = web_res_zip_fullname end if !ipa_file_upload.nil? && File.extname(ipa_file_upload).downcase.eql?(".exe") windows_exe_path = File.(ipa_file_upload) windows_build_dir = File.dirname(windows_exe_path) windows_zip_dir = File.dirname(windows_build_dir) windows_build_name = File.basename(windows_exe_path, File.extname(windows_exe_path)) windows_exe_name = File.basename(windows_exe_path) windows_zip_fullname = File.join(windows_zip_dir, windows_build_name + ".zip") if File.exist?(windows_zip_fullname) FileUtils.rm_rf(windows_zip_fullname) end current_project_dir = Dir.pwd Zip::File.open(windows_zip_fullname, Zip::File::CREATE) do |zipfile| Dir.chdir windows_build_dir zipfile.add(windows_exe_name, windows_exe_name) end Dir.chdir(current_project_dir) ipa_file_upload = windows_zip_fullname end unless !ipa_file_upload.nil? && File.exist?(ipa_file_upload) return end args_ipa_file_dir = File.(File::dirname(ipa_file_upload)) ipa_file_upload=File.join(args_ipa_file_dir, File.basename(ipa_file_upload)) current_project_dir = Dir.pwd # description = get_description_from_git(current_project_dir:current_project_dir) # get_description_from_git 现在会在失败时抛出异常,成功时返回有效的描述 # 所以不需要再检查 nil 或空值 addtach_file = nil if ipa_file_upload.include?(File.join(current_project_dir, "build")) && File.exist?(File.join(current_project_dir, "VMData")) server_file_directory = Dir.glob(File.join(current_project_dir, "VMData/Archives/*")).max_by {|f| File.mtime(f)} zip_base_name = File.basename(server_file_directory) server_zipfile_name = File.join(current_project_dir, "VMData", zip_base_name+".zip") if File.exist?(server_zipfile_name) FileUtils.rm_rf(server_zipfile_name) end Zip::File.open(server_zipfile_name, Zip::File::CREATE) do |zipfile| Dir.chdir server_file_directory Dir.glob("**/*").reject {|fn| File.directory?(fn) }.each do |file| zipfile.add(file.sub(server_file_directory + '/', ''), file) end end addtach_file = server_zipfile_name Dir.chdir current_project_dir end puts puts "上传项目: #{app_info_obj["projectName"]}" print "上传备注: " puts description # aws_client = AWSS3Client.new aws_client = JPSClient::UploadClient.new(@pgyer_client) # 开始上传主文件,记录开始时间 file_size_mb = File.size(ipa_file_upload) / (1024.0 * 1024.0) puts "\n开始上传文件 (#{file_size_mb.round(2)} MB)..." upload_start_time = Time.now upload_res = aws_client.upload_file(binary_file:ipa_file_upload) # 计算上传耗时 upload_duration = Time.now - upload_start_time upload_speed = file_size_mb / upload_duration puts "✅ 文件上传完成! 耗时: #{upload_duration.round(2)} 秒, 平均速度: #{upload_speed.round(2)} MB/s" attach_key_url = nil attachFileUrls = [] begin if !addtach_file.nil? && File.exist?(addtach_file) attach_size_mb = File.size(addtach_file) / (1024.0 * 1024.0) puts "\n存在附件, 继续上传附件 (#{attach_size_mb.round(2)} MB)..." attach_start_time = Time.now attach_key_url = aws_client.upload_file(binary_file:addtach_file, isAttach:true) # 计算附件上传耗时 attach_duration = Time.now - attach_start_time attach_speed = attach_size_mb / attach_duration puts "✅ 附件上传完成! 耗时: #{attach_duration.round(2)} 秒, 平均速度: #{attach_speed.round(2)} MB/s" end if !attach_key_url.nil? attachFileUrls << attach_key_url end rescue => error puts "附件上传失败".bold.red end if !upload_res.nil? && !app_info_obj.nil? puts attachFileUrls # 准备上传参数(workflowId 必传) upload_params = { description: description, packageUrl: upload_res, attachFileUrls: attachFileUrls, workflowId: workflow_info[:workflow_id] # workflowId 必传 } # 提交包信息到服务器 Funlog.instance.("正在提交包信息到服务器...") begin result_data = @pgyer_client.upload_project_package( projectId: app_info_obj["id"], params: upload_params, timeout: 300 ) # 验证上传结果 if ENV['JPS_CLIENT_DEBUG'] puts "[JPS_CLIENT_DEBUG] upload_project_package result_data: #{result_data.inspect}" end if result_data && result_data["data"] && result_data["data"]["id"] Funlog.instance.("提交包信息完成!") else error_msg = result_data&.dig('msg') || '未知错误' Funlog.instance.("提交包信息失败: #{error_msg}") raise Informative, "上传失败:未获取到有效的返回数据" end rescue Informative raise rescue => e Funlog.instance.("提交包信息失败: #{e.}") raise end return result_data else raise Informative, "上传失败!" end end |
#wildcard_android_bundle_name?(bundle_name) ⇒ Boolean
1398 1399 1400 1401 1402 1403 1404 |
# File 'lib/pindo/module/pgyer/pgyerhelper.rb', line 1398 def wildcard_android_bundle_name?(bundle_name) return false if bundle_name.nil? || bundle_name.empty? bundle_name.include?('*') || bundle_name.end_with?('.') || ['com.test', 'com.example', 'com.demo', 'com.heroneverdie101'].include?(bundle_name) end |