Class: Pindo::Command::Jps::Bind

Inherits:
Pindo::Command::Jps show all
Defined in:
lib/pindo/command/jps/bind.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) ⇒ Bind

Returns a new instance of Bind.



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/pindo/command/jps/bind.rb', line 50

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

    # JPS 参数
    @args_conf = @options[:conf]

    # Task 参数
    @args_select_flag = @options[:select] || false

    # Git 参数
    @args_git_commit = Pindo::Options::GitOptions.parse_git_commit_type(@options[:git_commit])

    super(argv)
end

Class Method Details

.option_itemsObject

定义此命令使用的参数项



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

def self.option_items
  @option_items ||= Pindo::Options::OptionGroup.merge(
    Pindo::Options::JPSOptions.select(:conf),
    Pindo::Options::TaskOptions.select(:select),
    Pindo::Options::GitOptions.all
  )
end

.optionsObject



46
47
48
# File 'lib/pindo/command/jps/bind.rb', line 46

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

Instance Method Details

#runObject



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
# File 'lib/pindo/command/jps/bind.rb', line 70

def run
    project_path = Dir.pwd

    # 1. 如果启用 --select 参数,获取用户选择的 commit
    selected_commit_info = nil
    if @args_select_flag
        selected_commit_info = select_git_commit(project_path)

        if selected_commit_info.nil?
            puts "未选择任何提交,已取消操作"
            return
        end

        puts "\n已选择提交:"
        puts "  Commit ID: #{selected_commit_info[:commit_id][0..7]}"
        puts "  时间: #{selected_commit_info[:commit_time]}"
        puts "  描述: #{selected_commit_info[:commit_desc]}"
        puts ""
    end

    # 2. 获取 JPS 配置(git workflow 信息)
    pgyer_helper = PgyerHelper.share_instace
    pgyer_helper.

    app_info_obj, git_workflow_info = pgyer_helper.prepare_upload(
        working_directory: project_path,
        conf: @args_conf,
        package_type: nil,
        manage_type: "git"
    )

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

    project_id = app_info_obj["id"]

    # 3. 让用户选择要绑定的包类型
    selected_package_types = select_package_types
    if selected_package_types.empty?
        puts "未选择任何包类型,已取消操作"
        return
    end

    # 4. 获取对应类型的最新包
    app_version_list = get_latest_packages_by_types(pgyer_helper, project_id, selected_package_types)

    if app_version_list.empty?
        raise Informative, "未找到可绑定的项目包,请先上传包"
    end

    puts "\n找到以下项目包:"
    app_version_list.each do |pkg|
        puts "  [#{pkg['nativePackageType']}] ID: #{pkg['id']}, Version: #{pkg['projectVersion']}, Build: #{pkg['build']}"
    end
    puts ""

    # 5. 创建任务链
    tasks = []

    # Git 提交任务
    process_type = Pindo::GitHandler.get_uncommitted_files_process_type(
        project_dir: project_path,
        interactive: @args_git_commit.nil?,
        default_process_type: @args_git_commit
    )

    git_commit_task = Pindo::TaskSystem::GitCommitTask.new(
        project_path,
        {
            process_type: process_type,
            commit_message: "build: jps bind 绑定前提交"
        }
    )
    tasks << git_commit_task

    # 创建绑定任务(一次绑定所有包)
    bind_task = Pindo::TaskSystem::JPSBindPackageTask.new(
        app_version_list,  # 传入包列表
        {
            git_commit_id: selected_commit_info&.dig(:commit_id),
            git_commit_time: selected_commit_info&.dig(:commit_time),
            git_commit_desc: selected_commit_info&.dig(:commit_desc),
            project_dir: project_path,
            app_info_obj: app_info_obj,
            workflow_info: git_workflow_info,
            project_name: nil
        }
    )
    bind_task.dependencies << git_commit_task.id
    tasks << bind_task

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

    # 7. 输出结果(任务失败时 start 会自动抛出异常;这里仍要求至少成功一个任务)
    report = task_manager.execution_report
    if report[:success] > 0
        puts "\n✅ 绑定完成! 成功绑定 #{app_version_list.size} 个包到 Git Workflow"
    else
        raise Informative, "绑定失败"
    end
end

#validate!Object



66
67
68
# File 'lib/pindo/command/jps/bind.rb', line 66

def validate!
    super
end