jpsclient 2.7.2 → 2.7.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3b469c45fc263d9c573736eba519b34ae855058e47b77a01428e5da3330ce052
4
- data.tar.gz: cc4eb5ab5180c02022dff9df585d848cf51c1fab8914b0e129989b812501133b
3
+ metadata.gz: b7014fe7a27b5b18567a2026f0df7f02efc5cb41fd9756e031377f8d7af74d65
4
+ data.tar.gz: e0e02d786ede3bdb12b5d5f4d42f4a65d9414420835de19230b638be24f4bc66
5
5
  SHA512:
6
- metadata.gz: 0bfbf38a960e5b308f72b28e0962eebb0425fec3a15229c77f8a01b17353012fb988db35f47363cdea5ca57151a317c09b07e9ba999019fdff2ee7c940cb8aef
7
- data.tar.gz: e8952174c4e5921e3cb7dad0e98c0f72f466aac458b50342eefabf82fc4f87727610bb303dc4b6a4d454fd41cc64739455aafc2c2ace2bde5f68733bd9c5e7f9
6
+ metadata.gz: ed31e0a4b90af88a0a21596ea29aaa29442be00defb71bc90a05b750bc9d304cbf08aec40dab57d9fcbc20f50ddeabb013564cdfc0273ff3d009fc7ae44768e8
7
+ data.tar.gz: 7573c0e55b1be5fa61290621f678cfc038e617919407b0b4e1e0d81d31fea909fd6adb31b867ebf77f03d4bcf647bf4c269883716cae501a7344a1d55a6f3f4a
@@ -27,18 +27,21 @@ module JPSClient
27
27
  return request_with_auth(:post, path, body: body_params)
28
28
  end
29
29
 
30
- # 发送提交记录消息通知
30
+ # 发送提交记录消息通知(commit_log/send_message)
31
+ #
32
+ # 以线上真实请求为准:接口文档可能滞后。
31
33
  #
32
34
  # @param projectId [String] 项目ID(必需)
33
35
  # @param workflowId [Integer] 工作流ID(必需)
34
36
  # @param params [Hash] 其他参数
35
- # @option params [Boolean] :single 是否单个提交(默认 true)
36
- # @option params [Array<String>, String] :branches 分支名称数组,服务端 CommitLogSendMessageDto 的字段
37
- # @option params [String] :branch 分支名称(单数形式,调用方便利写法,内部归一化为 branches)
38
- # @option params [Array<String>] :commitIds 提交ID数组
39
- # @option params [Integer] :startTimestamp 开始时间戳
40
- # @option params [Integer] :endTimestamp 结束时间戳
41
- # @option params [Integer] :indexNo 索引号
37
+ # @option params [Boolean] :single 是否单条提交发送(默认 true)
38
+ # @option params [Array<Integer>] :ids commit_log 记录 ID 集合
39
+ # @option params [String] :branch 分支名称,空字符串也需要原样发送
40
+ # @option params [Array<String>] :commitIds 提交ID集合,single=true 时必传(取第一个)
41
+ # @option params [Integer] :startTimestamp 提交时间下界(epoch 毫秒,闭区间,仅 single=false)
42
+ # @option params [Integer] :endTimestamp 提交时间上界(epoch 毫秒,开区间,仅 single=false)
43
+ # @option params [Integer] :indexNo 项目包索引号
44
+ # @option params [Array<String>] :repoTypes 仓库类型过滤(仅 single=false)
42
45
  # @return [Hash] API响应
43
46
  def send_commit_log_message(projectId:, workflowId:, params: {})
44
47
  config = @request_config && @request_config["commit_log_send_message"]
@@ -51,16 +54,13 @@ module JPSClient
51
54
  single: params.fetch(:single, true)
52
55
  }
53
56
 
54
- # 添加可选参数
55
- # 服务端 CommitLogSendMessageDto 只有 branches 数组字段,branch 单数会被直接丢弃,
56
- # 因此单数写法在这里归一化为数组,不再原样透传
57
- branches = params[:branches] || params[:branch]
58
- body_params[:branches] = Array(branches).compact if branches
59
-
57
+ body_params[:ids] = params[:ids] if params[:ids]
60
58
  body_params[:commitIds] = params[:commitIds] if params[:commitIds]
59
+ body_params[:branch] = params[:branch] if params.key?(:branch)
61
60
  body_params[:startTimestamp] = params[:startTimestamp] if params[:startTimestamp]
62
61
  body_params[:endTimestamp] = params[:endTimestamp] if params[:endTimestamp]
63
62
  body_params[:indexNo] = params[:indexNo] if params[:indexNo]
63
+ body_params[:repoTypes] = params[:repoTypes] if params[:repoTypes]
64
64
 
65
65
  return request_with_auth(:post, path, body: body_params)
66
66
  end
@@ -6,7 +6,10 @@ module JPSClient
6
6
 
7
7
  # 初始化多部分上传
8
8
  def init_file_multipart(s3_key:, content_type: "", upload_config:)
9
- path = @request_config["file_init_multipart"]["url"]
9
+ config = @request_config && @request_config["file_init_multipart"]
10
+ raise JPSClient::ExceptionError, "Missing config for file_init_multipart" unless config && config["url"]
11
+
12
+ path = config["url"]
10
13
 
11
14
  body_params = {
12
15
  s3Key: s3_key,
@@ -24,7 +27,10 @@ module JPSClient
24
27
  # @param upload_config [UploadConfig] 上传配置
25
28
  # @return [Hash] 包含预签名URL的响应
26
29
  def get_simple_sign_url(s3_key:, upload_config:)
27
- path = @request_config["file_sign_url"]["url"]
30
+ config = @request_config && @request_config["file_sign_url"]
31
+ raise JPSClient::ExceptionError, "Missing config for file_sign_url" unless config && config["url"]
32
+
33
+ path = config["url"]
28
34
 
29
35
  body_params = {
30
36
  s3Key: s3_key,
@@ -38,7 +44,10 @@ module JPSClient
38
44
 
39
45
  # 获取分片预签名URL
40
46
  def get_file_sign_url(s3_key:, upload_id:, part_id:, upload_config:)
41
- path = @request_config["file_sign_url"]["url"]
47
+ config = @request_config && @request_config["file_sign_url"]
48
+ raise JPSClient::ExceptionError, "Missing config for file_sign_url" unless config && config["url"]
49
+
50
+ path = config["url"]
42
51
 
43
52
  body_params = {
44
53
  s3Key: s3_key,
@@ -54,7 +63,10 @@ module JPSClient
54
63
 
55
64
  # 完成多部分上传
56
65
  def complete_file_multipart(s3_key:, upload_id:, upload_config:)
57
- path = @request_config["file_complete_multipart"]["url"]
66
+ config = @request_config && @request_config["file_complete_multipart"]
67
+ raise JPSClient::ExceptionError, "Missing config for file_complete_multipart" unless config && config["url"]
68
+
69
+ path = config["url"]
58
70
 
59
71
  body_params = {
60
72
  s3Key: s3_key,
@@ -61,7 +61,6 @@ module JPSClient
61
61
  # @option params [String] :projectPackageId 项目包ID
62
62
  # @return [Hash] API响应
63
63
  def upload_nuget_package(projectId:nil, params:nil)
64
- puts "========1111 upload_nuget_package" if JPSClient.debug?
65
64
  config = @request_config && @request_config["project_package_upload_nuget"]
66
65
  raise JPSClient::ExceptionError, "Missing config for project_package_upload_nuget" unless config && config["url"]
67
66
  path = config["url"]
@@ -79,6 +79,8 @@ module JPSClient
79
79
  puts "文件路径: #{@upload_binary_file}"
80
80
  puts "文件大小: #{total_mb}M"
81
81
  puts "上传路径: #{s3_key}"
82
+ puts "存储桶: #{@upload_config.bucket_name}"
83
+ puts "区域: #{@upload_config.region}"
82
84
  puts
83
85
  puts "切片大小: #{@upload_config.chunk_size_mb}MB"
84
86
 
@@ -98,12 +100,11 @@ module JPSClient
98
100
  puts "[JPS_DEBUG] init_file_multipart 返回: #{init_result.inspect}"
99
101
  end
100
102
 
101
- if init_result.nil? || !init_result.dig("data", "upload_id")
103
+ upload_id = multipart_upload_id(init_result)
104
+ if init_result.nil? || upload_id.nil?
102
105
  raise ExceptionError, init_multipart_error_message(init_result)
103
106
  end
104
107
 
105
- upload_id = init_result["data"]["upload_id"]
106
-
107
108
  # 准备分片任务队列
108
109
  @tasks_queue = Queue.new
109
110
  @worker_threads = []
@@ -150,7 +151,7 @@ module JPSClient
150
151
 
151
152
  if complete_result && (complete_result["code"] == 0 || complete_result["code"] == 200)
152
153
  # 返回 URL 字符串以保持向后兼容
153
- upload_result = complete_result.dig("data", "url") || s3_key
154
+ upload_result = uploaded_file_url(complete_result, s3_key)
154
155
  Logger.instance.fancyinfo_success("文件#{@upload_binary_file} 上传成功! 😎😎😎")
155
156
  else
156
157
  upload_result = nil
@@ -323,13 +324,13 @@ module JPSClient
323
324
  upload_config: @upload_config
324
325
  )
325
326
 
326
- if sign_result.nil? || !sign_result.dig("data", "url")
327
+ original_url = signed_upload_url(sign_result)
328
+ if original_url.nil?
327
329
  # Logger.instance.info("分片 ##{part_no} 获取上传URL失败") # 避免打断进度条
328
330
  handle_retry(upload_params_item, "获取上传URL失败")
329
331
  return
330
332
  end
331
333
 
332
- original_url = sign_result["data"]["url"]
333
334
  upload_url = original_url
334
335
 
335
336
  # 如果启用 Cloudflare 加速,转换 URL
@@ -431,13 +432,34 @@ module JPSClient
431
432
  end
432
433
  end
433
434
 
434
- def calculate_chunk_timeout(chunk_size)
435
- # 使用配置的 timeout_seconds 作为单个分片的超时时间
436
- # 默认600秒(10分钟)
437
- @upload_config.timeout_seconds || 600
438
- end
435
+ def calculate_chunk_timeout(chunk_size)
436
+ # 使用配置的 timeout_seconds 作为单个分片的超时时间
437
+ # 默认600秒(10分钟)
438
+ @upload_config.timeout_seconds || 600
439
+ end
440
+
441
+ def multipart_upload_id(init_result)
442
+ init_result&.dig("data", "upload_id") || init_result&.dig("data", "uploadId")
443
+ end
444
+
445
+ def signed_upload_url(sign_result)
446
+ data = sign_result&.dig("data")
447
+ return nil unless data.is_a?(Hash)
448
+
449
+ data["url"] || data["signUrl"] || data["sign_url"] ||
450
+ data["apiGatewayUrl"] || data["api_gateway_url"]
451
+ end
452
+
453
+ def uploaded_file_url(complete_result, s3_key)
454
+ data = complete_result&.dig("data")
455
+ return s3_key unless data.is_a?(Hash)
456
+
457
+ data["url"] || data["httpUrl"] || data["http_url"] ||
458
+ data["apiGatewayUrl"] || data["api_gateway_url"] ||
459
+ data["s3Url"] || data["s3_url"] || s3_key
460
+ end
439
461
 
440
- def handle_retry(upload_params_item, error_reason)
462
+ def handle_retry(upload_params_item, error_reason)
441
463
  part_no = upload_params_item["partNo"]
442
464
  @progress_bar.delete_upload_index(upload_part:part_no)
443
465
 
@@ -241,13 +241,12 @@ module JPSClient
241
241
  upload_config: @upload_config
242
242
  )
243
243
 
244
- unless sign_result && sign_result.dig("data", "url")
244
+ upload_url = signed_upload_url(sign_result)
245
+ unless upload_url
245
246
  handle_retry(task_item, "获取预签名 URL 失败")
246
247
  return
247
248
  end
248
249
 
249
- upload_url = sign_result["data"]["url"]
250
-
251
250
  # 读取文件
252
251
  begin
253
252
  file_content = File.binread(file_path)
@@ -276,8 +275,7 @@ module JPSClient
276
275
  response = request.run
277
276
 
278
277
  if response.success?
279
- # 构建文件访问 URL
280
- file_url = "https://#{@upload_config.media_bucket_name}.s3.#{@upload_config.media_region}.amazonaws.com/#{s3_key}"
278
+ file_url = uploaded_media_url(sign_result, s3_key)
281
279
 
282
280
  # 记录成功结果
283
281
  @results_mutex.synchronize do
@@ -348,6 +346,34 @@ module JPSClient
348
346
  [[calculated, 30].max, 300].min
349
347
  end
350
348
 
349
+ def signed_upload_url(sign_result)
350
+ data = sign_result&.dig("data")
351
+ return nil unless data.is_a?(Hash)
352
+
353
+ data["url"] || data["signUrl"] || data["sign_url"] ||
354
+ data["apiGatewayUrl"] || data["api_gateway_url"]
355
+ end
356
+
357
+ def uploaded_media_url(sign_result, s3_key)
358
+ data = sign_result&.dig("data")
359
+ if data.is_a?(Hash)
360
+ url = data["fileUrl"] || data["file_url"] ||
361
+ data["staticUrl"] || data["static_url"] ||
362
+ data["httpUrl"] || data["http_url"] ||
363
+ data["url"]
364
+ return url unless url.to_s.empty?
365
+ end
366
+
367
+ "#{static_base_url}/#{s3_key}"
368
+ end
369
+
370
+ def static_base_url
371
+ bucket_name = @upload_config.media_bucket_name.to_s
372
+ return "https://jps-static.devtestapp.com" if bucket_name == "jps-resource"
373
+
374
+ "https://pgy-static.devtestapp.com"
375
+ end
376
+
351
377
  # 检查是否上传失败
352
378
  def upload_failed?
353
379
  @upload_failed_mutex.synchronize { @upload_failed }
@@ -1,3 +1,3 @@
1
1
  module JPSClient
2
- VERSION = '2.7.2'
2
+ VERSION = '2.7.5'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jpsclient
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.7.2
4
+ version: 2.7.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Your Name