ci_toolkit 1.5.16 → 1.5.19
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 +4 -4
- data/.rubocop.yml +6 -1
- data/Gemfile.lock +4 -1
- data/lib/ci_toolkit/seetest_bot.rb +37 -0
- data/lib/ci_toolkit/seetest_client.rb +134 -0
- data/lib/ci_toolkit.rb +2 -0
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0caae7232b53d65bcd7f5eb7103b3ce36d56d22120beee7534bdcfa3beb8d1c9
|
4
|
+
data.tar.gz: 5a1bf7389dec806379b9b0f6544950f026638c53e614481bd2d8b4dd3152a980
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dd550bfe914c50d9b3f21f691ee933d06f4048dbae2c430c7499f1b164757a5870bb51f561e789986bf35d6400c14b1ebcf90b6374a5135a3737a2fb1d4ad267
|
7
|
+
data.tar.gz: efc45ea4f35a27d452e56d43b51e32fe4cf1f407c692eeacaed5f438b3b808c58212200d5b87ae7c01a2672535d52ce8c0b9442b9a8cfd819e26d08f5232fd8c
|
data/.rubocop.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
ci_toolkit (1.5.
|
4
|
+
ci_toolkit (1.5.19)
|
5
5
|
faraday
|
6
|
+
faraday-multipart
|
6
7
|
faraday_middleware
|
7
8
|
gitlab
|
8
9
|
jwt
|
@@ -34,6 +35,8 @@ GEM
|
|
34
35
|
faraday-em_synchrony (1.0.0)
|
35
36
|
faraday-excon (1.1.0)
|
36
37
|
faraday-httpclient (1.0.1)
|
38
|
+
faraday-multipart (1.0.4)
|
39
|
+
multipart-post (~> 2)
|
37
40
|
faraday-net_http (1.0.1)
|
38
41
|
faraday-net_http_persistent (1.2.0)
|
39
42
|
faraday-patron (1.0.0)
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "gitlab"
|
4
|
+
|
5
|
+
module CiToolkit
|
6
|
+
# Utility class that provides an faraday connection
|
7
|
+
class SeeTestBot
|
8
|
+
attr_reader :faraday_conn
|
9
|
+
|
10
|
+
# Provides a base url, an endpoint and an access token that can be used to
|
11
|
+
# interact with the SeeTest web service
|
12
|
+
class Credentials
|
13
|
+
attr_reader :base_url, :access_token
|
14
|
+
|
15
|
+
def initialize(
|
16
|
+
base_url = ENV["SEETEST_BASE_URL"],
|
17
|
+
access_token = ENV["SEETEST_ACCESS_TOKEN"]
|
18
|
+
)
|
19
|
+
@base_url = base_url
|
20
|
+
@access_token = access_token
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def initialize(
|
25
|
+
credentials = CiToolkit::SeeTestBot::Credentials.new,
|
26
|
+
faraday_conn = Faraday.new(url: credentials.base_url) do |f|
|
27
|
+
f.request :authorization, "Bearer", credentials.access_token
|
28
|
+
f.request :multipart
|
29
|
+
f.request :url_encoded
|
30
|
+
f.response :json, parser_options: { object_class: OpenStruct }
|
31
|
+
f.adapter :net_http # A MUST for file upload to work with Faraday::Multipart::FilePart
|
32
|
+
end
|
33
|
+
)
|
34
|
+
@faraday_conn = faraday_conn
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,134 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "faraday"
|
4
|
+
require "faraday/net_http"
|
5
|
+
require "faraday/multipart"
|
6
|
+
|
7
|
+
module CiToolkit
|
8
|
+
# A client for Seetest webservice.
|
9
|
+
# See API doc for more info: https://docs.experitest.com/display/PM/How+To+Execute+Rest+API
|
10
|
+
# rubocop:disable Metrics/ClassLength
|
11
|
+
class SeeTestClient
|
12
|
+
SUCCESS = "SUCCESS"
|
13
|
+
OKAY = "OK"
|
14
|
+
ERROR = "ERROR"
|
15
|
+
API_VERSION = "v1"
|
16
|
+
attr_reader :faraday_conn
|
17
|
+
|
18
|
+
def initialize(bot = CiToolkit::SeeTestBot.new)
|
19
|
+
@faraday_conn = bot.faraday_conn
|
20
|
+
end
|
21
|
+
|
22
|
+
# rubocop:disable Metrics/AbcSize
|
23
|
+
# rubocop:disable Metrics/MethodLength
|
24
|
+
def upload_file(
|
25
|
+
project_name:,
|
26
|
+
unique_name:,
|
27
|
+
full_path_to_file:,
|
28
|
+
content_type: "application/octet-stream"
|
29
|
+
)
|
30
|
+
response = faraday_upload(
|
31
|
+
project_name,
|
32
|
+
unique_name,
|
33
|
+
full_path_to_file,
|
34
|
+
content_type
|
35
|
+
).body
|
36
|
+
|
37
|
+
# Application already exists. Replace it.
|
38
|
+
if response.status == SUCCESS && response.data.created == "false"
|
39
|
+
response = replace_existing_application(
|
40
|
+
response.data.id,
|
41
|
+
project_name,
|
42
|
+
unique_name,
|
43
|
+
full_path_to_file,
|
44
|
+
content_type
|
45
|
+
)
|
46
|
+
# Application with unique name already exist. Replace it.
|
47
|
+
elsif response.status == ERROR && !response.data.nil? && !response.data.uniqueName.nil?
|
48
|
+
application_info_response = faraday_get_application_info(unique_name)
|
49
|
+
application_id = application_info_response[0].id
|
50
|
+
response = replace_existing_application(
|
51
|
+
application_id,
|
52
|
+
project_name,
|
53
|
+
unique_name,
|
54
|
+
full_path_to_file,
|
55
|
+
content_type
|
56
|
+
)
|
57
|
+
end
|
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
|
65
|
+
end
|
66
|
+
# rubocop:enable Metrics/AbcSize Metrics/MethodLength
|
67
|
+
# rubocop:enable Metrics/MethodLength
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
def replace_existing_application(
|
72
|
+
application_id,
|
73
|
+
project_name,
|
74
|
+
unique_name,
|
75
|
+
full_path_to_file,
|
76
|
+
content_type
|
77
|
+
)
|
78
|
+
faraday_delete_application(application_id)
|
79
|
+
faraday_upload_file_with_error_handling(project_name, unique_name, full_path_to_file, content_type)
|
80
|
+
end
|
81
|
+
|
82
|
+
def faraday_upload_file_with_error_handling(
|
83
|
+
project_name,
|
84
|
+
unique_name,
|
85
|
+
full_path_to_file,
|
86
|
+
content_type
|
87
|
+
)
|
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
|
+
end
|
93
|
+
|
94
|
+
response
|
95
|
+
end
|
96
|
+
|
97
|
+
def faraday_upload(
|
98
|
+
project_name,
|
99
|
+
unique_name,
|
100
|
+
full_path_to_file,
|
101
|
+
content_type
|
102
|
+
)
|
103
|
+
file = Faraday::Multipart::FilePart.new(full_path_to_file, content_type)
|
104
|
+
params = {
|
105
|
+
file: file,
|
106
|
+
uniqueName: unique_name,
|
107
|
+
project: project_name
|
108
|
+
}
|
109
|
+
@faraday_conn.post("/api/#{API_VERSION}/applications/new", params)
|
110
|
+
end
|
111
|
+
|
112
|
+
def faraday_get_application_info(unique_name)
|
113
|
+
params = { uniqueName: unique_name }
|
114
|
+
response = @faraday_conn.get("/api/#{API_VERSION}/applications", params).body
|
115
|
+
if response.empty?
|
116
|
+
raise StandardError,
|
117
|
+
"Get application info for uniqueName: #{unique_name} from Seetest returned an error. "\
|
118
|
+
"Response body is: '#{response}'"
|
119
|
+
end
|
120
|
+
response
|
121
|
+
end
|
122
|
+
|
123
|
+
def faraday_delete_application(application_id)
|
124
|
+
response = @faraday_conn.post("/api/#{API_VERSION}/applications/#{application_id}/delete").body
|
125
|
+
unless response.status == SUCCESS && response.code == OKAY
|
126
|
+
raise StandardError,
|
127
|
+
"Delete application id: #{application_id} from Seetest returned an error. "\
|
128
|
+
"Response body is: '#{response.marshal_dump}'"
|
129
|
+
end
|
130
|
+
response
|
131
|
+
end
|
132
|
+
end
|
133
|
+
# rubocop:enable Metrics/ClassLength
|
134
|
+
end
|
data/lib/ci_toolkit.rb
CHANGED
@@ -10,6 +10,8 @@ require "ci_toolkit/github_pr"
|
|
10
10
|
require "ci_toolkit/gitlab_bot"
|
11
11
|
require "ci_toolkit/gitlab_pr"
|
12
12
|
require "ci_toolkit/gitlab_release"
|
13
|
+
require "ci_toolkit/seetest_bot"
|
14
|
+
require "ci_toolkit/seetest_client"
|
13
15
|
require "ci_toolkit/dvcs_pr_factory"
|
14
16
|
require "ci_toolkit/git"
|
15
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.
|
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-
|
11
|
+
date: 2022-10-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: faraday-multipart
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: gitlab
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -233,6 +247,8 @@ files:
|
|
233
247
|
- lib/ci_toolkit/jira.rb
|
234
248
|
- lib/ci_toolkit/pr_messenger.rb
|
235
249
|
- lib/ci_toolkit/pr_messenger_text.rb
|
250
|
+
- lib/ci_toolkit/seetest_bot.rb
|
251
|
+
- lib/ci_toolkit/seetest_client.rb
|
236
252
|
- transform_coverage_data.rb
|
237
253
|
homepage: https://github.com/crvshlab/ci_toolkit
|
238
254
|
licenses:
|