Class: Pindo::PgyerHelper
- Inherits:
-
Object
- Object
- Pindo::PgyerHelper
show all
- Includes:
- Githelper
- Defined in:
- lib/pindo/module/pgyer/pgyerhelper.rb
Class Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
-
#find_app_info_with_obj_list(proj_name: nil) ⇒ Object
-
#get_app_list_in_pgyer ⇒ Object
-
#get_app_version(appId: nil, app_version_index: nil, latest_version: true) ⇒ Object
-
#get_cert_list ⇒ Object
-
#get_description_from_git(current_project_dir: nil) ⇒ Object
-
#get_user_local_wechat_url ⇒ Object
-
#get_versioon_history_item(app_info_obj: nil, list_select_flat: false) ⇒ Object
-
#initialize ⇒ PgyerHelper
constructor
A new instance of PgyerHelper.
-
#login ⇒ Object
-
#make_msg_data(app_info_obj: nil, app_version_info_obj: nil) ⇒ Object
-
#modify_coment(app_info_obj: nil, version_item_obj: nil) ⇒ Object
-
#prepare_upload(working_directory: nil, proj_name: nil) ⇒ Object
-
#print_app_version_info(msg_data: nil) ⇒ Object
-
#resign(version_id: nil, cert_id: nil) ⇒ Object
-
#send_apptest_msg(appId: nil, appVersionId: nil, chatEnv: nil, receiveType: nil) ⇒ Object
-
#send_apptest_wechat_msg(msg_data: nil, wechat_url: nil) ⇒ Object
-
#setForeLogin(beforeLogin: nil) ⇒ Object
-
#start_upload(app_info_obj: nil, ipa_file_upload: nil, description: nil) ⇒ Object
Methods included from Githelper
#add_branch, #add_tag, #add_tag_with_check, #clone_clang_repo, #clone_devclang_repo, #clone_pindo_common_config_repo, #clone_pindo_env_config_repo, #clong_buildconfig_repo, #get_repo_base_name, #getcode_to_dir, #git_addpush_repo, #git_latest_commit_id, #git_root_directory, #is_git_directory?, #local_branch_exists?, #local_tag_exists?, #prepare_gitenv, #process_need_add_files, #remote_branch_exists?, #remote_tag_exists?, #remove_branch, #remove_tag
Methods included from Executable
capture_command, #executable, execute_command, which, which!
Constructor Details
Returns a new instance of PgyerHelper.
28
29
30
31
|
# File 'lib/pindo/module/pgyer/pgyerhelper.rb', line 28
def initialize()
@force_login = false
@has_login = false
end
|
Class Attribute Details
.instance=(value) ⇒ Object
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
#find_app_info_with_obj_list(proj_name: nil) ⇒ Object
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
|
# File 'lib/pindo/module/pgyer/pgyerhelper.rb', line 429
def find_app_info_with_obj_list(proj_name:nil)
if proj_name.nil?
return nil
end
Funlog.instance.fancyinfo_start("正在拉取app信息列表,查找app信息...")
get_app_list_in_pgyer()
key_proj_name = proj_name.downcase.strip.gsub(/[\s\-_]/, '')
app_info_list = Pindoconfig.instance.get_pgyerapps_info_list()
app_info_obj = app_info_list&.find do |app_info_item|
app_info_item_name = app_info_item["appName"].to_s.downcase.strip.gsub(/[\s\-_]/, '')
app_info_item_name.eql?(key_proj_name)
end
Funlog.instance.fancyinfo_success("拉取app信息列表完成,app信息获取成功!")
app_info_obj
end
|
#get_app_list_in_pgyer ⇒ Object
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
|
# File 'lib/pindo/module/pgyer/pgyerhelper.rb', line 470
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_app_list_req(params:params)
if !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)
end
end
if app_info_list.nil?
res_data = @pgyer_client.get_app_list_req(params:params)
if !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)
end
end
if app_info_list.nil?
Funlog.instance.fancyinfo_error("拉取app信息列表失败!")
raise Informative, "Pgyer网络数据异常!!!"
end
return app_info_list
end
|
#get_app_version(appId: nil, app_version_index: nil, latest_version: true) ⇒ Object
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
|
# File 'lib/pindo/module/pgyer/pgyerhelper.rb', line 452
def get_app_version(appId:nil, app_version_index:nil, latest_version:true)
version_data = @pgyer_client.get_app_version_list_req(appId:appId)
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
return version_item_obj
end
|
#get_cert_list ⇒ Object
607
608
609
610
611
612
613
614
615
|
# File 'lib/pindo/module/pgyer/pgyerhelper.rb', line 607
def get_cert_list( )
Funlog.instance.fancyinfo_start("正在获取可用证书...")
result = @pgyer_client.get_cert_list()
Funlog.instance.fancyinfo_success("获取可用证书完成!")
return result["data"]
end
|
#get_description_from_git(current_project_dir: nil) ⇒ Object
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
|
# File 'lib/pindo/module/pgyer/pgyerhelper.rb', line 557
def get_description_from_git(current_project_dir:nil)
description = nil
if !current_project_dir.nil? && is_git_directory?(local_repo_dir: current_project_dir)
current_git_root_path = git_root_directory(local_repo_dir: current_project_dir)
cliff_toml_path = File.join(current_git_root_path, "cliff.toml")
if File.exist?(cliff_toml_path)
begin
`git-cliff --version`
git_cliff_installed = $?.success?
if git_cliff_installed
temp_dir = Dir.pwd
Dir.chdir(current_git_root_path)
`git-cliff -c #{cliff_toml_path} --latest -o -`
description = `git-cliff -c #{cliff_toml_path} --latest -o -`.strip
Dir.chdir(temp_dir)
end
rescue StandardError => e
end
end
end
return description
end
|
#get_user_local_wechat_url ⇒ Object
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
|
# File 'lib/pindo/module/pgyer/pgyerhelper.rb', line 286
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) ⇒ Object
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
|
# File 'lib/pindo/module/pgyer/pgyerhelper.rb', line 506
def get_versioon_history_item(app_info_obj:nil, list_select_flat:false)
Funlog.instance.fancyinfo_start("正在拉取app上传记录...")
appId = app_info_obj["appId"]
version_data = @pgyer_client.get_app_version_list_req(appId:appId) || {}
Funlog.instance.fancyinfo_success("拉取app上传记录完成!")
if version_data["data"].nil? || version_data["data"].size <=0
raise Informative, "#{proj_name} 错误, 没有找到上传记录"
end
app_incId_index = nil
if list_select_flat
list_num = [version_data["data"].size, 10].min
version_array_temp = version_data["data"].take(list_num).map do |item|
{
"appVersion" => item["appVersion"] + "(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
|
#login ⇒ Object
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/pindo/module/pgyer/pgyerhelper.rb', line 37
def login
@pgyer_client = PgyerClient.new
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
|
#make_msg_data(app_info_obj: nil, app_version_info_obj: nil) ⇒ Object
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
|
# File 'lib/pindo/module/pgyer/pgyerhelper.rb', line 633
def make_msg_data(app_info_obj:nil, app_version_info_obj:nil)
msg_from = @pgyer_client.token["username"]
app_name = app_info_obj["appName"]
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["appVersion"]
index_num = app_version_info_obj["incId"]
time = app_version_info_obj["updateTime"]
description = app_version_info_obj["description"]
msg_from = msg_from || " "
msg_data ={
app_name: app_name,
download_password: download_password,
download_url: download_url,
bundle_id: bundle_id,
app_version: app_version,
index_num: index_num,
time: time,
description: description,
msg_from:msg_from
}
return msg_data
end
|
#modify_coment(app_info_obj: nil, version_item_obj: nil) ⇒ Object
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
|
# File 'lib/pindo/module/pgyer/pgyerhelper.rb', line 582
def modify_coment(app_info_obj:nil, version_item_obj:nil)
current_project_dir = Dir.pwd
= get_description_from_git(current_project_dir:current_project_dir)
puts "=========================================="
puts
puts "#{comment_str}"
puts
puts "=========================================="
puts
if .nil? || .empty?
Funlog.instance.fancyinfo_error("没有找到git备注信息,无法修改pgyer备注!")
else
Funlog.instance.fancyinfo_start("开始修复pgyer备注...")
@pgyer_client.(appId:app_info_obj["appId"], id:version_item_obj["id"], comment:.strip)
Funlog.instance.fancyinfo_start("pgyer备注已经修改!")
end
puts "备注信息修改成功!!"
end
|
#prepare_upload(working_directory: nil, proj_name: nil) ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
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
|
# File 'lib/pindo/module/pgyer/pgyerhelper.rb', line 48
def prepare_upload(working_directory:nil, proj_name:nil)
upload_proj_name = proj_name
if upload_proj_name.nil? || upload_proj_name.empty?
upload_proj_name = @proj_name
end
app_info_obj = nil
if login
if !upload_proj_name.nil?
app_info_obj = PgyerHelper.share_instace.find_app_info_with_obj_list(proj_name:upload_proj_name)
end
if !app_info_obj.nil?
return app_info_obj
end
proj_name_array = []
proj_name_array = proj_name_array + PindoUserLocalConfig.instance.get_last_work_project_array()
proj_name_array_append = []
if File.exist?(File.join(working_directory, "config.json"))
config_json = JSON.parse(File.read(File.join(working_directory, "config.json")))
new_proj_string = config_json["project_info"]["project_name"]
if !new_proj_string.nil? && !new_proj_string.empty?
proj_name_array_append << config_json["project_info"]["project_name"]
end
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 << "自定义输入Pyger上的App代号"
if proj_name_array.size > 1
cli = HighLine.new
upload_proj_name = cli.choose do ||
.prompt = "请选择Pgyer上的App代号:"
.choices(*proj_name_array)
end
if upload_proj_name.include?("自定义输入")
upload_proj_name = ask('请输入Pyger上的App代号(大小写空格忽略):') || nil
upload_proj_name = upload_proj_name.strip
end
else
upload_proj_name = ask('请输入Pyger上的App代号(大小写空格忽略):') || nil
upload_proj_name = upload_proj_name.strip
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('没有找到结果,请重新输入Pyger上的App代号(大小写空格忽略):') || nil
upload_proj_name = upload_proj_name.strip
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} 名称错误, 请输入正确的App代号,Pgyer网站没有该App!!!"
else
PindoUserLocalConfig.instance.write_last_work_project(proj_name:app_info_obj["appName"])
end
else
raise Informative, "请先登录Pgyer网站"
end
@proj_name = upload_proj_name
app_info_obj
end
|
#print_app_version_info(msg_data: nil) ⇒ Object
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
|
# File 'lib/pindo/module/pgyer/pgyerhelper.rb', line 406
def print_app_version_info(msg_data:nil)
qrcode = RQRCode::QRCode.new(msg_data[: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 "#{msg_data[:app_name]} 测试"
puts "Bundle Id: #{msg_data[:bundle_id]}"
puts "版本号: #{msg_data[:app_version]} build: #{msg_data[:index_num]}"
puts "安装密码: #{msg_data[:download_password]}"
puts "上传时间: #{msg_data[:time]}"
puts "链接: #{msg_data[:download_url]}"
puts "说明: #{msg_data[:description]}"
puts "\r\n\r\n\r\n\r\n"
end
|
#resign(version_id: nil, cert_id: nil) ⇒ Object
617
618
619
620
621
622
623
624
625
626
627
628
629
|
# File 'lib/pindo/module/pgyer/pgyerhelper.rb', line 617
def resign(version_id:nil, cert_id:nil)
Funlog.instance.fancyinfo_start("正在重签名...")
result = @pgyer_client.post_resign(appVersionId:version_id, certId:cert_id)
if !result.nil? && result["code"] == 200 && result["data"] == "success"
Funlog.instance.fancyinfo_success("重签名成功!")
return true
else
Funlog.instance.fancyinfo_error("重签名失败!")
return false
end
end
|
#send_apptest_msg(appId: nil, appVersionId: nil, chatEnv: nil, receiveType: nil) ⇒ Object
302
303
304
305
306
307
308
309
310
311
312
313
314
315
|
# File 'lib/pindo/module/pgyer/pgyerhelper.rb', line 302
def send_apptest_msg(appId:nil, appVersionId:nil, chatEnv: nil, receiveType:nil)
Funlog.instance.fancyinfo_start("正在发送飞书消息...")
result = @pgyer_client.post_message(appId:appId, appVersionId:appVersionId, chatEnv: chatEnv, receiveType:receiveType)
if !result.nil? && result["code"] == 200 && result["data"] == "success"
Funlog.instance.fancyinfo_success("测试信息已经发送飞书!")
return true
else
Funlog.instance.fancyinfo_error("未发送飞书测试信息!")
return false
end
end
|
#send_apptest_wechat_msg(msg_data: nil, wechat_url: nil) ⇒ Object
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
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
|
# File 'lib/pindo/module/pgyer/pgyerhelper.rb', line 317
def send_apptest_wechat_msg(msg_data:nil, wechat_url: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.length >1
else
puts "企业微信Wechat Url无效"
end
begin
download_url = msg_data[:download_url]
app_name = msg_data[:app_name]
download_password = msg_data[:download_password]
bundle_id = msg_data[:bundle_id]
app_version = msg_data[:app_version]
index_num = msg_data[:index_num]
upload_time = msg_data[:time]
description = msg_data[:description]
msg_from = msg_data[:msg_from]
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.['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.['Content-Type'] = 'application/json'
req.body = body_data.to_json
end
puts
puts "发送企业微信成功 !!!"
puts
rescue StandardError => e
puts
puts "发送企业微信失败 !!!"
puts
end
end
|
#setForeLogin(beforeLogin: nil) ⇒ Object
33
34
35
|
# File 'lib/pindo/module/pgyer/pgyerhelper.rb', line 33
def setForeLogin(beforeLogin:nil)
@force_login = beforeLogin
end
|
#start_upload(app_info_obj: nil, ipa_file_upload: nil, description: nil) ⇒ Object
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
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
|
# File 'lib/pindo/module/pgyer/pgyerhelper.rb', line 147
def start_upload(app_info_obj:nil, ipa_file_upload:nil, description:nil)
if !ipa_file_upload.nil? &&
File.extname(ipa_file_upload).eql?(".app") &&
File.extname(ipa_file_upload).eql?(".apk")
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
puts "ipa_file_upload: ++++1"
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"
begin
if File.exist?(File.join(web_zip_dir, "web_build_info.json"))
json_data = JSON.parse(File.read(File.join(web_zip_dir, "web_build_info.json")))
web_build_name = json_data["productName"]
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 + ".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
puts "ipa_file_upload: ++++2"
unless !ipa_file_upload.nil? && File.exist?(ipa_file_upload)
return
end
args_ipa_file_dir = File.expand_path(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)
description = " " if description.nil? || description.empty?
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
if description.nil? || description.length <= 0
description = " "
end
puts
puts "上传项目: #{app_info_obj["appName"]}"
print "上传备注: "
puts description
aws_client = PgyerUploadClient.new
upload_res = aws_client.upload_file(binary_file:ipa_file_upload)
puts upload_res
attach_key_url = nil
attachFileUrls = []
begin
if !addtach_file.nil? && File.exist?(addtach_file)
puts "存在附件, 继续上传附件..."
attach_key_url = aws_client.upload_file(binary_file:addtach_file, isAttach:true)
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
result_data = @pgyer_client.post_app_update_binary(appId:app_info_obj["appId"], params:{
description: description,
s3Url: upload_res,
attachFileUrls:attachFileUrls
})
return result_data
else
raise Informative, "上传失败!"
end
end
|