ci_toolkit 1.6.0 → 1.6.1

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: 86cd888726c86a779288d7e4a7d04bea4a1d1a52c479dcb862812f40ffa4f509
4
- data.tar.gz: 75833b08101042e0d7d9b3dae759d5ff505525f95bc547295eb2eaa734381ffb
3
+ metadata.gz: e72169e62cce70b95ff7872f841a40721103289b06792dc18863d08f5d5aa535
4
+ data.tar.gz: fba0e495ebd1c8e69efa917a1fb159078e42df29dc2a805fda7175bcb0992269
5
5
  SHA512:
6
- metadata.gz: 83eed0a9c51b4b4266648a505ba5cb1b861903631eca68ddc8bcb8ca8ade51e15727d882bde644f88f11ed2d2eb6375f5c990f98f2c112fc9b0971f98ddc9e80
7
- data.tar.gz: d05f1b050e19d31291d570132deb5c3898fc1616629f7a4887813fec95e128bed07a08b38c5cfea82de491c375541a4b17a04bb5c7488f35bc41ff2c9e3a96b8
6
+ metadata.gz: 1ea49531735be387235cb0481ba039ae6f964e21055e0769b788e05c1417a6406386226b2f304edaee1a45d753f4793b7701c705152db8f2e88e485ca9957495
7
+ data.tar.gz: c4210324b27bf7b0b591627fd29bdd8790f3b0ae1acae963c02da0e1745e3485fd544ead1448d4c30c81a9ea8fb2f51d9cb5d375fa7a811bfa2c4ad5e85cee57
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ci_toolkit (1.6.0)
4
+ ci_toolkit (1.6.1)
5
5
  faraday
6
6
  faraday-multipart
7
7
  faraday_middleware
data/ci_toolkit.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "ci_toolkit"
5
- spec.version = "1.6.0"
5
+ spec.version = "1.6.1"
6
6
  spec.authors = ["Gero Keller"]
7
7
  spec.email = ["gero.f.keller@gmail.com"]
8
8
 
@@ -7,7 +7,6 @@ require "faraday/multipart"
7
7
  module CiToolkit
8
8
  # A client for Seetest webservice.
9
9
  # See API doc for more info: https://docs.experitest.com/display/PM/How+To+Execute+Rest+API
10
- # rubocop:disable Metrics/ClassLength
11
10
  class SeeTestClient
12
11
  SUCCESS = "SUCCESS"
13
12
  OKAY = "OK"
@@ -19,30 +18,14 @@ module CiToolkit
19
18
  @faraday_conn = bot.faraday_conn
20
19
  end
21
20
 
22
- # rubocop:disable Metrics/MethodLength
23
21
  def upload_file(
24
22
  project_name:,
25
23
  unique_name:,
26
24
  full_path_to_file:,
27
25
  content_type: "application/octet-stream"
28
26
  )
29
- response = faraday_upload(
30
- project_name,
31
- unique_name,
32
- full_path_to_file,
33
- content_type
34
- ).body
35
-
36
- # Application already exists. Replace it.
37
- if (response["status"] == SUCCESS && response["data"]["created"] == "false") ||
38
- (response["status"] == ERROR && response.dig("data", "uniqueName"))
39
- response = replace_existing_application_by_unique_name(
40
- project_name,
41
- unique_name,
42
- full_path_to_file,
43
- content_type
44
- )
45
- end
27
+
28
+ response = upload_or_replace(project_name, unique_name, full_path_to_file, content_type)
46
29
 
47
30
  unless response["status"] == SUCCESS
48
31
  raise StandardError,
@@ -51,10 +34,24 @@ module CiToolkit
51
34
 
52
35
  response["status"]
53
36
  end
54
- # rubocop:enable Metrics/MethodLength
55
37
 
56
38
  private
57
39
 
40
+ def upload_or_replace(project_name, unique_name, full_path_to_file, content_type)
41
+ application_info_response = faraday_get_application_info(unique_name)
42
+ if application_info_response.empty?
43
+ return faraday_upload(project_name, unique_name, full_path_to_file, content_type).body
44
+ end
45
+
46
+ application_info_response.each do |app_response|
47
+ next unless app_response["uniqueName"] == unique_name
48
+
49
+ response = replace_existing_application(app_response["id"], project_name, unique_name, full_path_to_file,
50
+ content_type)
51
+ return response if response["status"] == SUCCESS
52
+ end
53
+ end
54
+
58
55
  def replace_existing_application(
59
56
  application_id,
60
57
  project_name,
@@ -63,24 +60,12 @@ module CiToolkit
63
60
  content_type
64
61
  )
65
62
  response = faraday_delete_application(application_id)
66
-
67
63
  if response["status"] == SUCCESS && response["code"] == OKAY
68
64
  response = faraday_upload_file_with_error_handling(project_name, unique_name, full_path_to_file, content_type)
69
65
  end
70
66
  response
71
67
  end
72
68
 
73
- def replace_existing_application_by_unique_name(project_name, unique_name, full_path_to_file, content_type)
74
- application_info_response = faraday_get_application_info(unique_name)
75
- application_info_response.each do |app_response|
76
- next unless app_response["uniqueName"] == unique_name
77
-
78
- response = replace_existing_application(app_response["id"], project_name, unique_name, full_path_to_file,
79
- content_type)
80
- return response if response["status"] == SUCCESS
81
- end
82
- end
83
-
84
69
  def faraday_upload_file_with_error_handling(
85
70
  project_name,
86
71
  unique_name,
@@ -113,13 +98,7 @@ module CiToolkit
113
98
 
114
99
  def faraday_get_application_info(unique_name)
115
100
  params = { uniqueName: unique_name }
116
- response = @faraday_conn.get("/api/#{API_VERSION}/applications", params).body
117
- if response.empty?
118
- raise StandardError,
119
- "Get application info for uniqueName: #{unique_name} from Seetest returned an error. " \
120
- "Response body is: '#{response}'"
121
- end
122
- response
101
+ @faraday_conn.get("/api/#{API_VERSION}/applications", params).body
123
102
  end
124
103
 
125
104
  def faraday_delete_application(application_id)
@@ -132,5 +111,4 @@ module CiToolkit
132
111
  response
133
112
  end
134
113
  end
135
- # rubocop:enable Metrics/ClassLength
136
114
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ci_toolkit
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.0
4
+ version: 1.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gero Keller
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-05-26 00:00:00.000000000 Z
11
+ date: 2023-05-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday