ci_toolkit 1.5.16 → 1.5.17

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: 8bd3020f481c44b5a3aa5338f2642db5ad6616ed580be930532182e83ef4f434
4
- data.tar.gz: 5bddb92459c6e5e9219e5fb2ddaf5d9c07a62674396b776d37e6b0e3769ceb85
3
+ metadata.gz: 186f7a74ac19e0ff178758e757620f8c489bfbf0c93f815d999fd1eec6710344
4
+ data.tar.gz: fabfee8fc42a0d0dc016ca34ca1a24a43c9b620b525bf34429f935fb9830ed95
5
5
  SHA512:
6
- metadata.gz: d45f01faa0ecd50030c092e9bbe373bdbf78c22c74c7f95d2f54ddc9448839683598b0445654d491e48a469dd73712b4898fdc9771d7f3da4d38d97a9d88b298
7
- data.tar.gz: 3b75f18b57b521e91f235e4efe280c9c5ca77cbe968b08984eca33d16eb3d21a098495f4eef688b2806d1999eec0abe603f57700ca6178687f88400486bd08cb
6
+ metadata.gz: d45d3bfd1604ef09b32f56336b1917b8738fd2e6ebef06da5d29f82ff5b3f8f26e52dadf238d3aa552a13d9a746363d9e0256934efc66c479c3b648bcb1149b9
7
+ data.tar.gz: d9801923984198b34ec572e9b103079693c3f1701fd331453e66f6abb09e62f8ab0d59a6e25104d87921f4041471f86cfa4b4d2d50fc2ed7ab3f77921c233f86
data/Gemfile.lock CHANGED
@@ -1,8 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ci_toolkit (1.5.16)
4
+ ci_toolkit (1.5.17)
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,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "gitlab"
4
+
5
+ module CiToolkit
6
+ # Utility class that provides an instance of a Gitlab Client
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.adapter :net_http # A MUST for file upload to work with Faraday::Multipart::FilePart
31
+ end
32
+ )
33
+ @faraday_conn = faraday_conn
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,144 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "faraday"
4
+ require "faraday/net_http"
5
+ require "faraday/multipart"
6
+
7
+ module CiToolkit
8
+ # Can be used to upload files to Seetest.
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 SeeTestUpload
12
+ SUCCESS = "SUCCESS"
13
+ BAD_REQUEST = "BAD_REQUEST"
14
+ OKAY = "OK"
15
+ ERROR = "ERROR"
16
+
17
+ def initialize(
18
+ bot = CiToolkit::SeeTestBot.new
19
+ )
20
+ @bot = bot
21
+ end
22
+
23
+ # rubocop:disable Metrics/AbcSize
24
+ # rubocop:disable Metrics/MethodLength
25
+ def upload_file(
26
+ project_name:,
27
+ unique_name:,
28
+ full_path_to_file:,
29
+ content_type: "application/octet-stream"
30
+ )
31
+ uploaded = ""
32
+
33
+ response = faraday_upload(
34
+ project_name,
35
+ unique_name,
36
+ full_path_to_file,
37
+ content_type
38
+ )
39
+ response_obj = get_response_body(response.body)
40
+
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,
45
+ project_name,
46
+ unique_name,
47
+ full_path_to_file,
48
+ content_type
49
+ )
50
+ elsif response_obj.status == ERROR && response_obj.data?.uniqueName.empty?
51
+ application_info_response = faraday_get_application_info(unique_name)
52
+ application_id = application_info_response[0].id
53
+ uploaded = replace_existing_application(
54
+ application_id,
55
+ project_name,
56
+ unique_name,
57
+ full_path_to_file,
58
+ content_type
59
+ )
60
+ else
61
+ uploaded = response_obj
62
+ end
63
+ uploaded.status
64
+ end
65
+ # rubocop:enable Metrics/AbcSize Metrics/MethodLength
66
+ # rubocop:enable Metrics/MethodLength
67
+
68
+ private
69
+
70
+ def replace_existing_application(
71
+ application_id,
72
+ project_name,
73
+ unique_name,
74
+ full_path_to_file,
75
+ content_type
76
+ )
77
+ faraday_delete_application(application_id)
78
+ faraday_upload_file_with_error_handling(project_name, unique_name, full_path_to_file, content_type)
79
+ end
80
+
81
+ def faraday_upload_file_with_error_handling(
82
+ project_name,
83
+ unique_name,
84
+ full_path_to_file,
85
+ content_type
86
+ )
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}'"
92
+ end
93
+
94
+ body_obj
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
+ @bot.faraday_conn.post("/api/v1/applications/new", params)
110
+ end
111
+
112
+ def faraday_get_application_info(unique_name)
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?
117
+ raise StandardError,
118
+ "Get application info for uniqueName: #{unique_name} from Seetest returned an error. "\
119
+ "Response body is: '#{response.body}'"
120
+ end
121
+
122
+ response_obj
123
+ end
124
+
125
+ 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
131
+ raise StandardError,
132
+ "Delete application id: #{application_id} from Seetest returned an error. "\
133
+ "Response body is: '#{response.body}'"
134
+ end
135
+
136
+ response_obj
137
+ end
138
+
139
+ def get_response_body(response)
140
+ JSON.parse(response, object_class: OpenStruct)
141
+ end
142
+ end
143
+ # rubocop:enable Metrics/ClassLength
144
+ 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_upload"
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.16
4
+ version: 1.5.17
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-08-04 00:00:00.000000000 Z
11
+ date: 2022-09-30 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_upload.rb
236
252
  - transform_coverage_data.rb
237
253
  homepage: https://github.com/crvshlab/ci_toolkit
238
254
  licenses: