gitlab_support_readiness 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/support_readiness/client.rb +108 -0
- data/lib/support_readiness/gitlab/client.rb +64 -0
- data/lib/support_readiness/gitlab/configuration.rb +46 -0
- data/lib/support_readiness/gitlab/groups.rb +180 -0
- data/lib/support_readiness/gitlab/issues.rb +410 -0
- data/lib/support_readiness/gitlab/namespaces.rb +190 -0
- data/lib/support_readiness/gitlab/projects.rb +510 -0
- data/lib/support_readiness/gitlab/repositories.rb +267 -0
- data/lib/support_readiness/gitlab/users.rb +488 -0
- data/lib/support_readiness/gitlab.rb +19 -0
- data/lib/support_readiness/pagerduty/client.rb +66 -0
- data/lib/support_readiness/pagerduty/configuration.rb +43 -0
- data/lib/support_readiness/pagerduty/escalation_policies.rb +123 -0
- data/lib/support_readiness/pagerduty/schedules.rb +223 -0
- data/lib/support_readiness/pagerduty/services.rb +132 -0
- data/lib/support_readiness/pagerduty.rb +16 -0
- data/lib/support_readiness/redis.rb +90 -0
- data/lib/support_readiness/zendesk/articles.rb +210 -0
- data/lib/support_readiness/zendesk/automations.rb +304 -0
- data/lib/support_readiness/zendesk/client.rb +84 -0
- data/lib/support_readiness/zendesk/configuration.rb +49 -0
- data/lib/support_readiness/zendesk/group_memberships.rb +256 -0
- data/lib/support_readiness/zendesk/groups.rb +249 -0
- data/lib/support_readiness/zendesk/job_statuses.rb +188 -0
- data/lib/support_readiness/zendesk/macros.rb +267 -0
- data/lib/support_readiness/zendesk/organization_fields.rb +233 -0
- data/lib/support_readiness/zendesk/organization_memberships.rb +257 -0
- data/lib/support_readiness/zendesk/organizations.rb +515 -0
- data/lib/support_readiness/zendesk/roles.rb +194 -0
- data/lib/support_readiness/zendesk/search.rb +159 -0
- data/lib/support_readiness/zendesk/sla_policies.rb +232 -0
- data/lib/support_readiness/zendesk/ticket_fields.rb +222 -0
- data/lib/support_readiness/zendesk/ticket_forms.rb +290 -0
- data/lib/support_readiness/zendesk/tickets.rb +854 -0
- data/lib/support_readiness/zendesk/triggers.rb +269 -0
- data/lib/support_readiness/zendesk/users.rb +946 -0
- data/lib/support_readiness/zendesk/views.rb +469 -0
- data/lib/support_readiness/zendesk.rb +31 -0
- data/lib/support_readiness.rb +29 -0
- metadata +215 -0
@@ -0,0 +1,267 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Defines the module Readiness.
|
4
|
+
module Readiness
|
5
|
+
# Defines the module GitLab
|
6
|
+
module GitLab
|
7
|
+
##
|
8
|
+
# Defines the class Repositories within the module {Readiness::GitLab}.
|
9
|
+
#
|
10
|
+
# @author Jason Colyer
|
11
|
+
# @since 1.0.0
|
12
|
+
# @todo Anything listed on https://docs.gitlab.com/ee/api/repositories.html not currently here
|
13
|
+
class Repositories < Readiness::Client
|
14
|
+
##
|
15
|
+
# Lists a repository's file tree.
|
16
|
+
# This method can take a long time to run depending on the parameters used.
|
17
|
+
#
|
18
|
+
# @author Jason Colyer
|
19
|
+
# @since 1.0.0
|
20
|
+
# @param client [Object] An instance of {Readiness::GitLab::Client}
|
21
|
+
# @param project [Object] An instance of {Readiness::GitLab::Projects}
|
22
|
+
# @param filters [Array] An array of filter Strings to use. Should be in the format of key=value
|
23
|
+
# @return [Array]
|
24
|
+
# @see https://docs.gitlab.com/ee/api/repositories.html#list-repository-tree GitLab API > Repositories > List repository tree
|
25
|
+
# @example
|
26
|
+
# require 'support_readiness'
|
27
|
+
# config = Readiness::GitLab::Configuration.new
|
28
|
+
# config.token = 'test123abc'
|
29
|
+
# client = Readiness::GitLab::Client.new(config)
|
30
|
+
# project = Readiness::GitLab::Projects.find!(client, 1083469)
|
31
|
+
# tree = Readiness::GitLab::Repositories.tree(client, project)
|
32
|
+
# pp tree.first['path']
|
33
|
+
# # => ".gitlab/CODEOWNERS"
|
34
|
+
def self.tree(client, project, filters = [])
|
35
|
+
array = []
|
36
|
+
url = "projects/#{project.id}/repository/tree?per_page=100&pagination=keyset&order_by=id&sort=asc&id_after=0&#{to_param_string(filters)}"
|
37
|
+
loop do
|
38
|
+
response = client.connection.get url
|
39
|
+
handle_request_error(0, 'GitLab', response.status) unless response.status == 200
|
40
|
+
body = Oj.load(response.body)
|
41
|
+
array += body
|
42
|
+
break if body.count < 100
|
43
|
+
|
44
|
+
url = "projects/#{project.id}/repository/tree?per_page=100&pagination=keyset&order_by=id&sort=asc&id_after=0&#{to_param_string(filters)}"
|
45
|
+
end
|
46
|
+
array
|
47
|
+
end
|
48
|
+
|
49
|
+
##
|
50
|
+
# Get information about a file in a repository.
|
51
|
+
#
|
52
|
+
# @author Jason Colyer
|
53
|
+
# @since 1.0.0
|
54
|
+
# @param client [Object] An instance of {Readiness::GitLab::Client}
|
55
|
+
# @param project [Object] An instance of {Readiness::GitLab::Projects}
|
56
|
+
# @param path [String] The full file path. Ex: lib/support_readiness/gitlab/repositories.rb
|
57
|
+
# @param ref [String] The name of branch, tag or commit
|
58
|
+
# @return [Array]
|
59
|
+
# @see https://docs.gitlab.com/ee/api/repository_files.html GitLab API > Repository files > Get file from repository
|
60
|
+
# @example
|
61
|
+
# require 'support_readiness'
|
62
|
+
# config = Readiness::GitLab::Configuration.new
|
63
|
+
# config.token = 'test123abc'
|
64
|
+
# client = Readiness::GitLab::Client.new(config)
|
65
|
+
# project = Readiness::GitLab::Projects.find!(client, 1083469)
|
66
|
+
# file = Readiness::GitLab::Repositories.file(client, project, ".gitlab/CODEOWNERS", "main")
|
67
|
+
# pp file['size']
|
68
|
+
# # => 88
|
69
|
+
def self.file(client, project, path, ref)
|
70
|
+
response = client.connection.get "projects/#{project.id}/repository/files/#{CGI.escape(path)}?ref=#{ref}"
|
71
|
+
handle_request_error(0, 'GitLab', response.status) unless response.status == 200
|
72
|
+
Oj.load(response.body)
|
73
|
+
end
|
74
|
+
|
75
|
+
##
|
76
|
+
# Get raw information about a file in a repository.
|
77
|
+
#
|
78
|
+
# @author Jason Colyer
|
79
|
+
# @since 1.0.0
|
80
|
+
# @param client [Object] An instance of {Readiness::GitLab::Client}
|
81
|
+
# @param project [Object] An instance of {Readiness::GitLab::Projects}
|
82
|
+
# @param path [String] The full file path. Ex: lib/support_readiness/gitlab/repositories.rb
|
83
|
+
# @param ref [String] The name of branch, tag or commit
|
84
|
+
# @return [Array]
|
85
|
+
# @see https://docs.gitlab.com/ee/api/repository_files.html#get-raw-file-from-repository GitLab API > Repository files > Get raw file from repository
|
86
|
+
# @example
|
87
|
+
# require 'support_readiness'
|
88
|
+
# config = Readiness::GitLab::Configuration.new
|
89
|
+
# config.token = 'test123abc'
|
90
|
+
# client = Readiness::GitLab::Client.new(config)
|
91
|
+
# project = Readiness::GitLab::Projects.find!(client, 1083469)
|
92
|
+
# file = Readiness::GitLab::Repositories.raw_file(client, project, ".gitlab/CODEOWNERS", "main")
|
93
|
+
# pp file['size']
|
94
|
+
# # => 88
|
95
|
+
def self.raw_file(client, project, path, ref)
|
96
|
+
response = client.connection.get "projects/#{project.id}/repository/files/#{CGI.escape(path)}/raw?ref=#{ref}"
|
97
|
+
handle_request_error(0, 'GitLab', response.status) unless response.status == 200
|
98
|
+
Oj.load(response.body)
|
99
|
+
end
|
100
|
+
|
101
|
+
##
|
102
|
+
# Create a single file in a repository. This will exit on error.
|
103
|
+
# You might want to instead use {create_commit!}
|
104
|
+
#
|
105
|
+
# @author Jason Colyer
|
106
|
+
# @since 1.0.0
|
107
|
+
# @param client [Object] An instance of {Readiness::GitLab::Client}
|
108
|
+
# @param project [Object] An instance of {Readiness::GitLab::Projects}
|
109
|
+
# @param path [String] The full file path. Ex: lib/support_readiness/gitlab/repositories.rb
|
110
|
+
# @param params [Hash] The parameters to use for the request
|
111
|
+
# @return [Array]
|
112
|
+
# @see https://docs.gitlab.com/ee/api/repository_files.html#update-existing-file-in-repository GitLab API > Repository files > Create new file in repository
|
113
|
+
# @example
|
114
|
+
# require 'support_readiness'
|
115
|
+
# config = Readiness::GitLab::Configuration.new
|
116
|
+
# config.token = 'test123abc'
|
117
|
+
# client = Readiness::GitLab::Client.new(config)
|
118
|
+
# project = Readiness::GitLab::Projects.find!(client, 1083469)
|
119
|
+
# file_params = {
|
120
|
+
# branch: 'master',
|
121
|
+
# commit_message: 'Created test.file',
|
122
|
+
# content: 'This is a test fi',
|
123
|
+
# execute_filemode: false
|
124
|
+
# }
|
125
|
+
# file = Readiness::GitLab::Repositories.create_file!(client, project, "spec/test.file", file_params)
|
126
|
+
# pp file['path']
|
127
|
+
# # => "spec/test.file"
|
128
|
+
def self.create_file!(client, project, path, params)
|
129
|
+
response = client.connection.post "projects/#{project.id}/repository/files/#{CGI.escape(path)}", to_clean_json(params)
|
130
|
+
handle_request_error(1, 'GitLab', response.status, { action: 'Create file in repo', id: "#{project.id}" }) unless response.status == 200
|
131
|
+
Oj.load(response.body)
|
132
|
+
end
|
133
|
+
|
134
|
+
##
|
135
|
+
# Updates a single file in a repository. This will exit on error.
|
136
|
+
# You might want to instead use {create_commit!}
|
137
|
+
#
|
138
|
+
# @author Jason Colyer
|
139
|
+
# @since 1.0.0
|
140
|
+
# @param client [Object] An instance of {Readiness::GitLab::Client}
|
141
|
+
# @param project [Object] An instance of {Readiness::GitLab::Projects}
|
142
|
+
# @param path [String] The full file path. Ex: lib/support_readiness/gitlab/repositories.rb
|
143
|
+
# @param params [Hash] The parameters to use for the request
|
144
|
+
# @return [Array]
|
145
|
+
# @see https://docs.gitlab.com/ee/api/repository_files.html#update-existing-file-in-repository GitLab API > Repository files > Update existing file in repository
|
146
|
+
# @example
|
147
|
+
# require 'support_readiness'
|
148
|
+
# config = Readiness::GitLab::Configuration.new
|
149
|
+
# config.token = 'test123abc'
|
150
|
+
# client = Readiness::GitLab::Client.new(config)
|
151
|
+
# project = Readiness::GitLab::Projects.find!(client, 1083469)
|
152
|
+
# file_params = {
|
153
|
+
# branch: 'master',
|
154
|
+
# commit_message: 'Fixing typo within test.file',
|
155
|
+
# content: 'This is a test file',
|
156
|
+
# execute_filemode: false
|
157
|
+
# }
|
158
|
+
# file = Readiness::GitLab::Repositories.update_file!(client, project, "spec/test.file", file_params)
|
159
|
+
# pp file['path']
|
160
|
+
# # => "spec/test.file"
|
161
|
+
def self.update_file!(client, project, path, params)
|
162
|
+
response = client.connection.put "projects/#{project.id}/repository/files/#{CGI.escape(path)}", to_clean_json(params)
|
163
|
+
handle_request_error(1, 'GitLab', response.status, { action: 'Update file in repo', id: "#{project.id}" }) unless response.status == 200
|
164
|
+
Oj.load(response.body)
|
165
|
+
end
|
166
|
+
|
167
|
+
##
|
168
|
+
# Deletes a single file in a repository. This will exit on error.
|
169
|
+
# You might want to instead use {create_commit!}
|
170
|
+
#
|
171
|
+
# @author Jason Colyer
|
172
|
+
# @since 1.0.0
|
173
|
+
# @param client [Object] An instance of {Readiness::GitLab::Client}
|
174
|
+
# @param project [Object] An instance of {Readiness::GitLab::Projects}
|
175
|
+
# @param path [String] The full file path. Ex: lib/support_readiness/gitlab/repositories.rb
|
176
|
+
# @param params [Hash] The parameters to use for the request
|
177
|
+
# @return [Boolean]
|
178
|
+
# @see https://docs.gitlab.com/ee/api/repository_files.html#delete-existing-file-in-repository GitLab API > Repository files > Delete existing file in repository
|
179
|
+
# @example
|
180
|
+
# require 'support_readiness'
|
181
|
+
# config = Readiness::GitLab::Configuration.new
|
182
|
+
# config.token = 'test123abc'
|
183
|
+
# client = Readiness::GitLab::Client.new(config)
|
184
|
+
# project = Readiness::GitLab::Projects.find!(client, 1083469)
|
185
|
+
# file_params = {
|
186
|
+
# branch: 'master',
|
187
|
+
# commit_message: 'Deleting test.file'
|
188
|
+
# }
|
189
|
+
# file = Readiness::GitLab::Repositories.delete_file!(client, project, "spec/test.file", file_params)
|
190
|
+
# pp file
|
191
|
+
# # => true
|
192
|
+
def self.delete_file!(client, project, path, params)
|
193
|
+
response = client.connection.delete "projects/#{project.id}/repository/files/#{CGI.escape(path)}", to_clean_json(params)
|
194
|
+
handle_request_error(1, 'GitLab', response.status, { action: 'Delete file in repo', id: "#{project.id}" }) unless response.status == 204
|
195
|
+
true
|
196
|
+
end
|
197
|
+
|
198
|
+
##
|
199
|
+
# Create a commit on a repository within GitLab. This will exit on error.
|
200
|
+
#
|
201
|
+
# @author Jason Colyer
|
202
|
+
# @since 1.0.0
|
203
|
+
# @param client [Object] An instance of {Readiness::GitLab::Client}
|
204
|
+
# @param project [Object] An instance of {Readiness::GitLab::Projects}
|
205
|
+
# @param params [Hash] The parameters to use for the request
|
206
|
+
# @return [Hash]
|
207
|
+
# @see https://docs.gitlab.com/ee/api/commits.html#create-a-commit-with-multiple-files-and-actions GitLab API > Commits > Create a commit with multiple files and actions
|
208
|
+
# @example
|
209
|
+
# require 'support_readiness'
|
210
|
+
# config = Readiness::GitLab::Configuration.new
|
211
|
+
# config.token = 'test123abc'
|
212
|
+
# client = Readiness::GitLab::Client.new(config)
|
213
|
+
# project = Readiness::GitLab::Projects.find!(client, 1083469)
|
214
|
+
# commit_params = {
|
215
|
+
# branch: 'master',
|
216
|
+
# commit_message: 'Notify via slack for failed pipelines',
|
217
|
+
# actions: [
|
218
|
+
# {
|
219
|
+
# execute_filemode: true,
|
220
|
+
# file_path: 'bin/post_to_slack.sh',
|
221
|
+
# content: 'curl -ss -X POST $SLACK_URL -H "Content-Type=application/json" --data...',
|
222
|
+
# action: 'create'
|
223
|
+
# }
|
224
|
+
# ]
|
225
|
+
# }
|
226
|
+
# commit = Readiness::GitLab::Repositories.create_commit!(client, project, commit_params)
|
227
|
+
# pp commit['title']
|
228
|
+
# # => "Notify via slack for failed pipelines"
|
229
|
+
def self.create_commit!(client, project, params)
|
230
|
+
response = client.connection.post "projects/#{project.id}/repository/commits", to_clean_json(params)
|
231
|
+
handle_request_error(1, 'GitLab', response.status, { action: 'Create commit', id: "#{project.id}" }) unless response.status == 200
|
232
|
+
Oj.load(response.body)
|
233
|
+
end
|
234
|
+
|
235
|
+
##
|
236
|
+
# Updates a submodule's reference in a project. This will exit on error.
|
237
|
+
#
|
238
|
+
# @author Jason Colyer
|
239
|
+
# @since 1.0.0
|
240
|
+
# @param client [Object] An instance of {Readiness::GitLab::Client}
|
241
|
+
# @param project [Object] An instance of {Readiness::GitLab::Projects}
|
242
|
+
# @param path [String] The full file path. Ex: lib/support_readiness/gitlab/repositories.rb
|
243
|
+
# @param params [Hash] The parameters to use for the request
|
244
|
+
# @return [Hash]
|
245
|
+
# @see https://docs.gitlab.com/ee/api/repository_submodules.html#update-existing-submodule-reference-in-repository GitLab API > Repository submodules > Update existing submodule reference in repository
|
246
|
+
# @example
|
247
|
+
# require 'support_readiness'
|
248
|
+
# config = Readiness::GitLab::Configuration.new
|
249
|
+
# config.token = 'test123abc'
|
250
|
+
# client = Readiness::GitLab::Client.new(config)
|
251
|
+
# project = Readiness::GitLab::Projects.find!(client, 5)
|
252
|
+
# update_params = {
|
253
|
+
# branch: 'main',
|
254
|
+
# commit_sha: '3ddec28ea23acc5caa5d8331a6ecb2a65fc03e88',
|
255
|
+
# commit_message: 'Update submodule reference'
|
256
|
+
# }
|
257
|
+
# update = Readiness::GitLab::Repositories.update_submodule!(client, project, "lib/modules/example", update_params)
|
258
|
+
# pp update['parent_ids']
|
259
|
+
# # => ["ae1d9fb46aa2b07ee9836d49862ec4e2c46fbbba"]
|
260
|
+
def self.update_submodule!(client, project, path, params)
|
261
|
+
response = clinet.connection.put "projects/#{project.id}/repository/submodules/#{CGI.escape(path)}", to_clean_json(params)
|
262
|
+
handle_request_error(1, 'GitLab', response.status, { action: 'Update submodule in repo', id: "#{project.id}" }) unless response.status == 200
|
263
|
+
Oj.load(response.body)
|
264
|
+
end
|
265
|
+
end
|
266
|
+
end
|
267
|
+
end
|