ci_toolkit 1.5.15 → 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 +4 -4
- data/Gemfile.lock +4 -1
- data/lib/ci_toolkit/dvcs_pr_factory.rb +1 -1
- data/lib/ci_toolkit/gitlab_bot.rb +30 -0
- data/lib/ci_toolkit/gitlab_pr.rb +4 -5
- data/lib/ci_toolkit/gitlab_release.rb +2 -3
- data/lib/ci_toolkit/seetest_bot.rb +36 -0
- data/lib/ci_toolkit/seetest_upload.rb +144 -0
- data/lib/ci_toolkit.rb +3 -0
- metadata +19 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 186f7a74ac19e0ff178758e757620f8c489bfbf0c93f815d999fd1eec6710344
|
4
|
+
data.tar.gz: fabfee8fc42a0d0dc016ca34ca1a24a43c9b620b525bf34429f935fb9830ed95
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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)
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module CiToolkit
|
4
4
|
# Use this to create an instance of Dvcs implementation based on the service type
|
5
|
-
# set in an environment value called DVCS_SERVICW with value of gitlab or github
|
5
|
+
# set in an environment value called DVCS_SERVICW with value of either gitlab or github
|
6
6
|
class DvcsPrFactory
|
7
7
|
SERVICES = {
|
8
8
|
"gitlab" => CiToolkit::GitlabPr,
|
@@ -0,0 +1,30 @@
|
|
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 GitlabBot
|
8
|
+
attr_reader :client
|
9
|
+
|
10
|
+
# Provides an endpoint and a private access token that can be used with the Gitlab client
|
11
|
+
class Credentials
|
12
|
+
attr_reader :endpoint, :project_access_token
|
13
|
+
|
14
|
+
def initialize(
|
15
|
+
endpoint = ENV["GITLAB_API_URL"],
|
16
|
+
project_access_token = ENV["GITLAB_PROJECT_ACCESS_TOKEN"]
|
17
|
+
)
|
18
|
+
@endpoint = endpoint
|
19
|
+
@project_access_token = project_access_token
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def initialize(
|
24
|
+
credentials = CiToolkit::GitlabBot::Credentials.new,
|
25
|
+
client = Gitlab.client(endpoint: credentials.endpoint, private_token: credentials.project_access_token)
|
26
|
+
)
|
27
|
+
@client = client
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/ci_toolkit/gitlab_pr.rb
CHANGED
@@ -10,16 +10,15 @@ module CiToolkit
|
|
10
10
|
build_types = ENV["BUILD_TYPES"]&.split(/,/) || ["BluetoothDemo", "Acceptance PreProd", "Acceptance Prod",
|
11
11
|
"Latest Prod", "Latest PreProd", "Mock", "Design System"],
|
12
12
|
|
13
|
-
|
14
|
-
private_token: ENV["GITLAB_USER_PRIVATE_TOKEN"] || "")
|
13
|
+
bot = CiToolkit::GitlabBot.new
|
15
14
|
)
|
16
15
|
super()
|
17
16
|
@pr_number = env.pull_request_number
|
18
17
|
@repo_slug = env.repository_path
|
19
18
|
@commit_sha = env.git_commit
|
20
|
-
@_client = client
|
19
|
+
@_client = bot.client
|
21
20
|
@build_types = build_types
|
22
|
-
@bot =
|
21
|
+
@bot = bot
|
23
22
|
end
|
24
23
|
|
25
24
|
def title
|
@@ -123,7 +122,7 @@ module CiToolkit
|
|
123
122
|
private
|
124
123
|
|
125
124
|
def client
|
126
|
-
@_client =
|
125
|
+
@_client = @bot.client if @_client.nil?
|
127
126
|
@_client
|
128
127
|
end
|
129
128
|
end
|
@@ -7,11 +7,10 @@ module CiToolkit
|
|
7
7
|
class GitlabRelease
|
8
8
|
def initialize(
|
9
9
|
env = CiToolkit::BitriseEnv.new,
|
10
|
-
|
11
|
-
private_token: ENV["GITLAB_USER_PRIVATE_TOKEN"] || "")
|
10
|
+
bot = CiToolkit::GitlabBot.new
|
12
11
|
)
|
13
12
|
@repo_slug = env.repository_slug
|
14
|
-
@client = client
|
13
|
+
@client = bot.client
|
15
14
|
end
|
16
15
|
|
17
16
|
# rubocop:disable Metrics/ParameterLists
|
@@ -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
@@ -7,8 +7,11 @@ require "ci_toolkit/duplicate_files_finder"
|
|
7
7
|
require "ci_toolkit/dvcs_pr"
|
8
8
|
require "ci_toolkit/github_bot"
|
9
9
|
require "ci_toolkit/github_pr"
|
10
|
+
require "ci_toolkit/gitlab_bot"
|
10
11
|
require "ci_toolkit/gitlab_pr"
|
11
12
|
require "ci_toolkit/gitlab_release"
|
13
|
+
require "ci_toolkit/seetest_bot"
|
14
|
+
require "ci_toolkit/seetest_upload"
|
12
15
|
require "ci_toolkit/dvcs_pr_factory"
|
13
16
|
require "ci_toolkit/git"
|
14
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.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-
|
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
|
@@ -227,11 +241,14 @@ files:
|
|
227
241
|
- lib/ci_toolkit/git.rb
|
228
242
|
- lib/ci_toolkit/github_bot.rb
|
229
243
|
- lib/ci_toolkit/github_pr.rb
|
244
|
+
- lib/ci_toolkit/gitlab_bot.rb
|
230
245
|
- lib/ci_toolkit/gitlab_pr.rb
|
231
246
|
- lib/ci_toolkit/gitlab_release.rb
|
232
247
|
- lib/ci_toolkit/jira.rb
|
233
248
|
- lib/ci_toolkit/pr_messenger.rb
|
234
249
|
- lib/ci_toolkit/pr_messenger_text.rb
|
250
|
+
- lib/ci_toolkit/seetest_bot.rb
|
251
|
+
- lib/ci_toolkit/seetest_upload.rb
|
235
252
|
- transform_coverage_data.rb
|
236
253
|
homepage: https://github.com/crvshlab/ci_toolkit
|
237
254
|
licenses:
|