ci_toolkit 1.5.17 → 1.5.19

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 186f7a74ac19e0ff178758e757620f8c489bfbf0c93f815d999fd1eec6710344
4
- data.tar.gz: fabfee8fc42a0d0dc016ca34ca1a24a43c9b620b525bf34429f935fb9830ed95
3
+ metadata.gz: 0caae7232b53d65bcd7f5eb7103b3ce36d56d22120beee7534bdcfa3beb8d1c9
4
+ data.tar.gz: 5a1bf7389dec806379b9b0f6544950f026638c53e614481bd2d8b4dd3152a980
5
5
  SHA512:
6
- metadata.gz: d45d3bfd1604ef09b32f56336b1917b8738fd2e6ebef06da5d29f82ff5b3f8f26e52dadf238d3aa552a13d9a746363d9e0256934efc66c479c3b648bcb1149b9
7
- data.tar.gz: d9801923984198b34ec572e9b103079693c3f1701fd331453e66f6abb09e62f8ab0d59a6e25104d87921f4041471f86cfa4b4d2d50fc2ed7ab3f77921c233f86
6
+ metadata.gz: dd550bfe914c50d9b3f21f691ee933d06f4048dbae2c430c7499f1b164757a5870bb51f561e789986bf35d6400c14b1ebcf90b6374a5135a3737a2fb1d4ad267
7
+ data.tar.gz: efc45ea4f35a27d452e56d43b51e32fe4cf1f407c692eeacaed5f438b3b808c58212200d5b87ae7c01a2672535d52ce8c0b9442b9a8cfd819e26d08f5232fd8c
data/.rubocop.yml CHANGED
@@ -16,4 +16,9 @@ Layout/LineLength:
16
16
  Max: 120
17
17
 
18
18
  Metrics/BlockLength:
19
- IgnoredMethods: ['describe']
19
+ IgnoredMethods: ['describe']
20
+
21
+ RSpec/MultipleExpectations:
22
+ Max: 5
23
+ RSpec/ExampleLength:
24
+ Max: 20
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ci_toolkit (1.5.17)
4
+ ci_toolkit (1.5.19)
5
5
  faraday
6
6
  faraday-multipart
7
7
  faraday_middleware
@@ -3,7 +3,7 @@
3
3
  require "gitlab"
4
4
 
5
5
  module CiToolkit
6
- # Utility class that provides an instance of a Gitlab Client
6
+ # Utility class that provides an faraday connection
7
7
  class SeeTestBot
8
8
  attr_reader :faraday_conn
9
9
 
@@ -27,6 +27,7 @@ module CiToolkit
27
27
  f.request :authorization, "Bearer", credentials.access_token
28
28
  f.request :multipart
29
29
  f.request :url_encoded
30
+ f.response :json, parser_options: { object_class: OpenStruct }
30
31
  f.adapter :net_http # A MUST for file upload to work with Faraday::Multipart::FilePart
31
32
  end
32
33
  )
@@ -5,19 +5,18 @@ require "faraday/net_http"
5
5
  require "faraday/multipart"
6
6
 
7
7
  module CiToolkit
8
- # Can be used to upload files to Seetest.
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
10
  # rubocop:disable Metrics/ClassLength
11
- class SeeTestUpload
11
+ class SeeTestClient
12
12
  SUCCESS = "SUCCESS"
13
- BAD_REQUEST = "BAD_REQUEST"
14
13
  OKAY = "OK"
15
14
  ERROR = "ERROR"
15
+ API_VERSION = "v1"
16
+ attr_reader :faraday_conn
16
17
 
17
- def initialize(
18
- bot = CiToolkit::SeeTestBot.new
19
- )
20
- @bot = bot
18
+ def initialize(bot = CiToolkit::SeeTestBot.new)
19
+ @faraday_conn = bot.faraday_conn
21
20
  end
22
21
 
23
22
  # rubocop:disable Metrics/AbcSize
@@ -28,39 +27,41 @@ module CiToolkit
28
27
  full_path_to_file:,
29
28
  content_type: "application/octet-stream"
30
29
  )
31
- uploaded = ""
32
-
33
30
  response = faraday_upload(
34
31
  project_name,
35
32
  unique_name,
36
33
  full_path_to_file,
37
34
  content_type
38
- )
39
- response_obj = get_response_body(response.body)
35
+ ).body
40
36
 
41
- # Application with unique name already exist. Replace it
42
- if response_obj.status == SUCCESS && response_obj.data.created == "false"
43
- uploaded = replace_existing_application(
44
- response_obj.data.id,
37
+ # Application already exists. Replace it.
38
+ if response.status == SUCCESS && response.data.created == "false"
39
+ response = replace_existing_application(
40
+ response.data.id,
45
41
  project_name,
46
42
  unique_name,
47
43
  full_path_to_file,
48
44
  content_type
49
45
  )
50
- elsif response_obj.status == ERROR && response_obj.data?.uniqueName.empty?
46
+ # Application with unique name already exist. Replace it.
47
+ elsif response.status == ERROR && !response.data.nil? && !response.data.uniqueName.nil?
51
48
  application_info_response = faraday_get_application_info(unique_name)
52
49
  application_id = application_info_response[0].id
53
- uploaded = replace_existing_application(
50
+ response = replace_existing_application(
54
51
  application_id,
55
52
  project_name,
56
53
  unique_name,
57
54
  full_path_to_file,
58
55
  content_type
59
56
  )
60
- else
61
- uploaded = response_obj
62
57
  end
63
- uploaded.status
58
+
59
+ unless response.status == SUCCESS
60
+ raise StandardError,
61
+ "Upload response from Seetest returned an error. Response body is: '#{response.marshal_dump}'"
62
+ end
63
+
64
+ response.status
64
65
  end
65
66
  # rubocop:enable Metrics/AbcSize Metrics/MethodLength
66
67
  # rubocop:enable Metrics/MethodLength
@@ -84,14 +85,13 @@ module CiToolkit
84
85
  full_path_to_file,
85
86
  content_type
86
87
  )
87
- response = faraday_upload(project_name, unique_name, full_path_to_file, content_type)
88
-
89
- body_obj = get_response_body(response.body)
90
- unless body_obj.status == SUCCESS && body_obj.data.created == "true"
91
- raise StandardError, "Upload response from Seetest returned an error. Response body is: '#{response.body}'"
88
+ response = faraday_upload(project_name, unique_name, full_path_to_file, content_type).body
89
+ unless response.status == SUCCESS && response.data.created == "true"
90
+ raise StandardError,
91
+ "Upload response from Seetest returned an error. Response body is: '#{response.marshal_dump}'"
92
92
  end
93
93
 
94
- body_obj
94
+ response
95
95
  end
96
96
 
97
97
  def faraday_upload(
@@ -106,38 +106,28 @@ module CiToolkit
106
106
  uniqueName: unique_name,
107
107
  project: project_name
108
108
  }
109
- @bot.faraday_conn.post("/api/v1/applications/new", params)
109
+ @faraday_conn.post("/api/#{API_VERSION}/applications/new", params)
110
110
  end
111
111
 
112
112
  def faraday_get_application_info(unique_name)
113
113
  params = { uniqueName: unique_name }
114
- response = @bot.faraday_conn.get("/api/v1/applications", params)
115
- response_obj = get_response_body(response.body)
116
- if response_obj.empty?
114
+ response = @faraday_conn.get("/api/#{API_VERSION}/applications", params).body
115
+ if response.empty?
117
116
  raise StandardError,
118
117
  "Get application info for uniqueName: #{unique_name} from Seetest returned an error. "\
119
- "Response body is: '#{response.body}'"
118
+ "Response body is: '#{response}'"
120
119
  end
121
-
122
- response_obj
120
+ response
123
121
  end
124
122
 
125
123
  def faraday_delete_application(application_id)
126
- response = @bot.faraday_conn.post("/api/v1/applications/#{application_id}/delete")
127
-
128
- response_obj = get_response_body(response.body)
129
-
130
- unless response_obj.status == SUCCESS && response_obj.code == OKAY
124
+ response = @faraday_conn.post("/api/#{API_VERSION}/applications/#{application_id}/delete").body
125
+ unless response.status == SUCCESS && response.code == OKAY
131
126
  raise StandardError,
132
127
  "Delete application id: #{application_id} from Seetest returned an error. "\
133
- "Response body is: '#{response.body}'"
128
+ "Response body is: '#{response.marshal_dump}'"
134
129
  end
135
-
136
- response_obj
137
- end
138
-
139
- def get_response_body(response)
140
- JSON.parse(response, object_class: OpenStruct)
130
+ response
141
131
  end
142
132
  end
143
133
  # rubocop:enable Metrics/ClassLength
data/lib/ci_toolkit.rb CHANGED
@@ -11,7 +11,7 @@ require "ci_toolkit/gitlab_bot"
11
11
  require "ci_toolkit/gitlab_pr"
12
12
  require "ci_toolkit/gitlab_release"
13
13
  require "ci_toolkit/seetest_bot"
14
- require "ci_toolkit/seetest_upload"
14
+ require "ci_toolkit/seetest_client"
15
15
  require "ci_toolkit/dvcs_pr_factory"
16
16
  require "ci_toolkit/git"
17
17
  require "ci_toolkit/jira"
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.5.17
4
+ version: 1.5.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gero Keller
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-09-30 00:00:00.000000000 Z
11
+ date: 2022-10-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -248,7 +248,7 @@ files:
248
248
  - lib/ci_toolkit/pr_messenger.rb
249
249
  - lib/ci_toolkit/pr_messenger_text.rb
250
250
  - lib/ci_toolkit/seetest_bot.rb
251
- - lib/ci_toolkit/seetest_upload.rb
251
+ - lib/ci_toolkit/seetest_client.rb
252
252
  - transform_coverage_data.rb
253
253
  homepage: https://github.com/crvshlab/ci_toolkit
254
254
  licenses: