Class: Pindo::Command::Jps::Apptest

Inherits:
Pindo::Command::Jps show all
Defined in:
lib/pindo/command/jps/apptest.rb

Constant Summary

Constants inherited from Pindo::Command

DEFAULT_OPTIONS, DEFAULT_ROOT_OPTIONS

Instance Attribute Summary

Attributes inherited from Pindo::Command

#args_help_flag

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Pindo::Command

command_name, #initialize_options, run, use_cache?

Methods included from Funlog::Mixin

#pindo_log_instance

Methods included from Pindoconfig::Mixin

#pindo_single_config

Constructor Details

#initialize(argv) ⇒ Apptest

Returns a new instance of Apptest.



48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/pindo/command/jps/apptest.rb', line 48

def initialize(argv)
    # 使用 Options 系统解析参数
    @options = initialize_options(argv)

    # JPS 参数
    @args_conf = @options[:conf]
    @args_list_flag = @options[:list] || false
    @args_send_flag = @options[:send] || false
    @args_group_flag = @options[:group] || false

    super(argv)
end

Class Method Details

.option_itemsObject

定义此命令使用的参数项



38
39
40
41
42
# File 'lib/pindo/command/jps/apptest.rb', line 38

def self.option_items
  @option_items ||= Pindo::Options::OptionGroup.merge(
    Pindo::Options::JPSOptions.select(:conf, :send, :list, :group)
  )
end

.optionsObject



44
45
46
# File 'lib/pindo/command/jps/apptest.rb', line 44

def self.options
  option_items.map(&:to_claide_option).concat(super)
end

Instance Method Details

#runObject



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
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/pindo/command/jps/apptest.rb', line 65

def run
    project_path = Dir.pwd

    # 1. 登录并获取 JPS 配置
    pgyer_helper = PgyerHelper.share_instace
    pgyer_helper.

    app_info_obj, workflow_info = pgyer_helper.prepare_upload(
        working_directory: project_path,
        conf: @args_conf,
        package_type: 'ipa'  # 获取 IPA 工作流信息
    )

    if app_info_obj.nil?
        raise Informative, "未找到 JPS 项目,请检查配置文件或重新选择"
    end

    # 2. 获取版本信息
    version_item_obj = pgyer_helper.get_versioon_history_item(
        app_info_obj: app_info_obj,
        list_select_flat: @args_list_flag
    )

    if version_item_obj.nil?
        raise Informative, "没有找到上传记录"
    end

    # 3. 打印版本信息
    pgyer_helper.print_app_version_info(
        app_info_obj: app_info_obj,
        app_version_info_obj: version_item_obj
    )

    # 4. 创建任务
    tasks = []

    # 4.1 始终创建 JPSMessageTask(根据 --group 参数决定发送给自己还是组)
    message_type = @args_group_flag ? 'group' : 'self'
    message_task = Pindo::TaskSystem::JPSMessageTask.new(
        version_item_obj,  # app_version_info
        app_info_obj: app_info_obj,
        project_name: nil,
        send_message_type: message_type
    )
    tasks << message_task

    # 4.2 如果有 --send 参数,创建 JPSWorkFlowMessageTask(发送到工作流群组)
    if @args_send_flag
        # 获取 Git 工作流信息
        git_app_info_obj, git_workflow_info = pgyer_helper.prepare_upload(
            working_directory: project_path,
            conf: @args_conf,
            package_type: nil,
            manage_type: "git"
        )

        # 获取 git_commit_id
        git_commit_id = nil
        git_commit_time = nil
        git_commit_desc = nil

        # 1. 检测是否在 Git 仓库中
        git_root = Pindo::GitHandler.git_root_directory(local_repo_dir: project_path)

        if git_root
            # 2. 在 Git 仓库中,获取当前的 commit 信息
            puts "  📍 检测到 Git 仓库,使用当前 commit..."
            git_info = Pindo::GitHandler.get_latest_conventional_commit(project_dir: git_root)
            git_commit_id = git_info[:commit_id]
            git_commit_time = git_info[:commit_time]
            git_commit_desc = git_info[:commit_desc]

            if git_commit_id
                puts "     └─ Commit: #{git_commit_id[0..7]}"
                puts "     └─ Desc: #{git_commit_desc}" if git_commit_desc
            end
        else
            # 3. 不在 Git 仓库中,获取工作流中最新的 commit id
            puts "  📡 未检测到 Git 仓库,从工作流获取最新 commit..."
            git_commit_id = pgyer_helper.get_workflow_latest_commit_id(
                workflow_id: git_workflow_info["id"]
            )

            if git_commit_id
                puts "     └─ Commit: #{git_commit_id[0..7]}"
            else
                puts "     └─ ⚠️  未能获取工作流中的 commit,将尝试使用空 commit"
            end
        end

        workflow_message_task = Pindo::TaskSystem::JPSWorkFlowMessageTask.new(
            project_id: git_app_info_obj["id"],
            workflow_id: git_workflow_info["id"],
            git_commit_id: git_commit_id,
            git_commit_time: git_commit_time,
            git_commit_desc: git_commit_desc,
            branch: 'master',
            single: true,
            app_info_obj: git_app_info_obj,
            workflow_info: git_workflow_info
        )
        tasks << workflow_message_task
    end

    # 5. 执行任务
    task_manager = Pindo::TaskSystem::TaskManager.instance
    task_manager.clear_all
    tasks.each { |task| task_manager.add_task(task) }
    task_manager.start

    # 6. 输出结果(任务失败时 start 会自动抛出异常;这里仍要求至少成功一个任务)
    report = task_manager.execution_report
    if report[:success] > 0
        puts "\n✅ 消息发送完成!"
    else
        raise Informative, "消息发送失败"
    end
end

#validate!Object



61
62
63
# File 'lib/pindo/command/jps/apptest.rb', line 61

def validate!
    super
end