gitlab_support_readiness 1.0.0
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 +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,410 @@
|
|
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 Issues 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/issues.html not currently here
|
13
|
+
class Issues < Readiness::Client
|
14
|
+
attr_accessor :assignee_id, :assignee_ids, :assignees, :author, :blocking_issues_count, :closed_at, :closed_by, :confidential, :created_at, :description, :discussion_locked, :downvotes, :due_date, :epic, :has_tasks, :health_status, :id, :iid, :imported, :imported_from, :issue_type, :iteration, :labels, :_links, :merge_requests_count, :milestone, :moved_to_id, :project_id, :references, :service_desk_reply_to, :severity, :state, :state_event, :task_completion_status, :task_status, :time_stats, :title, :type, :updated_at, :upvotes, :user_notes_count, :web_url, :weight
|
15
|
+
|
16
|
+
##
|
17
|
+
# Creates a new {Readiness::GitLab::Issues} instance
|
18
|
+
#
|
19
|
+
# @author Jason Colyer
|
20
|
+
# @since 1.0.0
|
21
|
+
# @param object [Object] An instance of {Readiness::GitLab::Issues}
|
22
|
+
# @example
|
23
|
+
# require 'support_readiness'
|
24
|
+
# Readiness::GitLab::Issues.new
|
25
|
+
def initialize(object = {})
|
26
|
+
@assignee_id = object['assignee_id']
|
27
|
+
@assignee_ids = object['assignee_ids']
|
28
|
+
@assignees = object['assignees']
|
29
|
+
@author = object['author']
|
30
|
+
@blocking_issues_count = object['blocking_issues_count']
|
31
|
+
@closed_at = object['closed_at']
|
32
|
+
@closed_by = object['closed_by']
|
33
|
+
@confidential = object['confidential']
|
34
|
+
@created_at = object['created_at']
|
35
|
+
@description = object['description']
|
36
|
+
@discussion_locked = object['discussion_locked']
|
37
|
+
@downvotes = object['downvotes']
|
38
|
+
@due_date = object['due_date']
|
39
|
+
@epic = object['epic']
|
40
|
+
@has_tasks = object['has_tasks']
|
41
|
+
@health_status = object['health_status']
|
42
|
+
@id = object['id']
|
43
|
+
@iid = object['iid']
|
44
|
+
@imported = object['imported']
|
45
|
+
@imported_from = object['imported_from']
|
46
|
+
@issue_type = object['issue_type']
|
47
|
+
@iteration = object['iteration']
|
48
|
+
@labels = object['labels']
|
49
|
+
@_links = object['_links']
|
50
|
+
@merge_requests_count = object['merge_requests_count']
|
51
|
+
@milestone = object['milestone']
|
52
|
+
@moved_to_id = object['moved_to_id']
|
53
|
+
@project_id = object['project_id']
|
54
|
+
@references = object['references']
|
55
|
+
@service_desk_reply_to = object['service_desk_reply_to']
|
56
|
+
@severity = object['severity']
|
57
|
+
@state = object['state']
|
58
|
+
@state_event = object['state_event']
|
59
|
+
@task_completion_status = object['task_completion_status']
|
60
|
+
@task_status = object['task_status']
|
61
|
+
@time_stats = object['time_stats']
|
62
|
+
@title = object['title']
|
63
|
+
@type = object['type']
|
64
|
+
@updated_at = object['updated_at']
|
65
|
+
@upvotes = object['upvotes']
|
66
|
+
@user_notes_count = object['user_notes_count']
|
67
|
+
@web_url = object['web_url']
|
68
|
+
@weight = object['weight']
|
69
|
+
end
|
70
|
+
|
71
|
+
##
|
72
|
+
# Lists all issues. Does not stop until it ends or the page limit is hit.
|
73
|
+
# This method can take a long time to run depending on the parameters used.
|
74
|
+
#
|
75
|
+
# @author Jason Colyer
|
76
|
+
# @since 1.0.0
|
77
|
+
# @param client [Object] An instance of {Readiness::GitLab::Client}
|
78
|
+
# @param limit [Integer] The number of pages to stop at. Using 0 means to list all.
|
79
|
+
# @param filters [Array] An array of filter Strings to use. Should be in the format of key=value
|
80
|
+
# @return [Array]
|
81
|
+
# @see https://docs.gitlab.com/ee/api/issues.html#list-issues GitLab API > Issues > List issues
|
82
|
+
# @example
|
83
|
+
# require 'support_readiness'
|
84
|
+
# config = Readiness::GitLab::Configuration.new
|
85
|
+
# config.token = 'test123abc'
|
86
|
+
# client = Readiness::GitLab::Client.new(config)
|
87
|
+
# issues = Readiness::GitLab::Issues.list_all(client, 2, ["assignee_id=5", "state=opened"])
|
88
|
+
# puts issues.first.web_url
|
89
|
+
# # => "https://gitlab.com/gitlab-com/support/support-team-meta/-/issues/1"
|
90
|
+
def self.list_all(client, limit = 0, filters = [])
|
91
|
+
array = []
|
92
|
+
page = 1
|
93
|
+
loop do
|
94
|
+
response = client.connection.get "issues?per_page=100&page=#{page}&#{to_param_string(filters)}"
|
95
|
+
handle_request_error(0, 'GitLab', response.status) unless response.status == 200
|
96
|
+
body = Oj.load(response.body)
|
97
|
+
array += body.map { |p| Issues.new(p) }
|
98
|
+
break if body.count < 100
|
99
|
+
break if limit != 0 && array.count >= (limit * 100)
|
100
|
+
|
101
|
+
page += 1
|
102
|
+
end
|
103
|
+
array
|
104
|
+
end
|
105
|
+
|
106
|
+
##
|
107
|
+
# Lists all issues for an object. Does not stop until it ends or the page limit is hit.
|
108
|
+
# This method can take a long time to run depending on the parameters used.
|
109
|
+
#
|
110
|
+
# @author Jason Colyer
|
111
|
+
# @since 1.0.0
|
112
|
+
# @param client [Object] An instance of {Readiness::GitLab::Client}
|
113
|
+
# @param object [Object] An instance of {Readiness::GitLab::Projects} or {Readiness::GitLab::Groups}
|
114
|
+
# @param limit [Integer] The number of pages to stop at. Using 0 means to list all.
|
115
|
+
# @param filters [Array] An array of filter Strings to use. Should be in the format of key=value
|
116
|
+
# @return [Array]
|
117
|
+
# @see https://docs.gitlab.com/ee/api/issues.html#list-issues GitLab API > Issues > List issues
|
118
|
+
# @example
|
119
|
+
# require 'support_readiness'
|
120
|
+
# config = Readiness::GitLab::Configuration.new
|
121
|
+
# config.token = 'test123abc'
|
122
|
+
# client = Readiness::GitLab::Client.new(config)
|
123
|
+
# project = Readiness::GitLab::Projects.find!(client, 1083469)
|
124
|
+
# issues = Readiness::GitLab::Issues.list(client, project, 2, ["assignee_id=5", "state=opened"])
|
125
|
+
# puts issues.first.web_url
|
126
|
+
# # => "https://gitlab.com/gitlab-com/support/support-team-meta/-/issues/2"
|
127
|
+
# @example
|
128
|
+
# require 'support_readiness'
|
129
|
+
# config = Readiness::GitLab::Configuration.new
|
130
|
+
# config.token = 'test123abc'
|
131
|
+
# client = Readiness::GitLab::Client.new(config)
|
132
|
+
# group = Readiness::GitLab::Groups.find!(client, 2573511)
|
133
|
+
# issues = Readiness::GitLab::Issues.list(client, group, 2, ["assignee_id=5", "state=opened"])
|
134
|
+
# puts issues.first.web_url
|
135
|
+
# # => "https://gitlab.com/gitlab-com/support/support-team-meta/-/issues/3"
|
136
|
+
def self.list(client, object, limit = 0, filters = [])
|
137
|
+
array = []
|
138
|
+
page = 1
|
139
|
+
loop do
|
140
|
+
response = client.connection.get "#{object.class.name.split('::').last.downcase}/#{object.id}/issues?per_page=100&page=#{page}&#{to_param_string(filters)}"
|
141
|
+
handle_request_error(0, 'GitLab', response.status) unless response.status == 200
|
142
|
+
body = Oj.load(response.body)
|
143
|
+
array += body.map { |p| Issues.new(p) }
|
144
|
+
break if body.count < 100
|
145
|
+
break if limit != 0 && array.count >= (limit * 100)
|
146
|
+
|
147
|
+
page += 1
|
148
|
+
end
|
149
|
+
array
|
150
|
+
end
|
151
|
+
|
152
|
+
##
|
153
|
+
# Locates a project issue within GitLab. This will not exit on error (except Authentication errors)
|
154
|
+
#
|
155
|
+
# @author Jason Colyer
|
156
|
+
# @since 1.0.0
|
157
|
+
# @param client [Object] An instance of {Readiness::GitLab::Client}
|
158
|
+
# @param project [Object] An instance of {Readiness::GitLab::Projects}
|
159
|
+
# @param iid [Integer] The issue ID to find
|
160
|
+
# @return [Hash]
|
161
|
+
# @see https://docs.gitlab.com/ee/api/issues.html#single-project-issue GitLab API > Issues > Single project issue
|
162
|
+
# @example
|
163
|
+
# require 'support_readiness'
|
164
|
+
# config = Readiness::GitLab::Configuration.new
|
165
|
+
# config.token = 'test123abc'
|
166
|
+
# client = Readiness::GitLab::Client.new(config)
|
167
|
+
# project = Readiness::GitLab::Projects.find!(client, 1083469)
|
168
|
+
# issue = Readiness::GitLab::Issues.find(client, project, 5)
|
169
|
+
# puts issues.web_url
|
170
|
+
# # => "https://gitlab.com/gitlab-com/support/support-team-meta/-/issues/5"
|
171
|
+
def self.find(client, project, iid)
|
172
|
+
response = client.connection.get "projects/#{project.id}/issues/#{iid}"
|
173
|
+
handle_request_error(0, 'GitLab', response.status, { action: 'get', id: iid }) unless response.status == 200
|
174
|
+
return Issues.new(Oj.load(response.body)) if response.status == 200
|
175
|
+
|
176
|
+
Oj.load(response.body)
|
177
|
+
end
|
178
|
+
|
179
|
+
##
|
180
|
+
# Locates a project issue within GitLab. This will exit on error
|
181
|
+
#
|
182
|
+
# @author Jason Colyer
|
183
|
+
# @since 1.0.0
|
184
|
+
# @param client [Object] An instance of {Readiness::GitLab::Client}
|
185
|
+
# @param project [Object] An instance of {Readiness::GitLab::Projects}
|
186
|
+
# @param iid [Integer] The issue ID to find
|
187
|
+
# @return [Object] An instance of {Readiness::GitLab::Issues}
|
188
|
+
# @see https://docs.gitlab.com/ee/api/issues.html#single-project-issue GitLab API > Issues > Single project issue
|
189
|
+
# @example
|
190
|
+
# require 'support_readiness'
|
191
|
+
# config = Readiness::GitLab::Configuration.new
|
192
|
+
# config.token = 'test123abc'
|
193
|
+
# client = Readiness::GitLab::Client.new(config)
|
194
|
+
# project = Readiness::GitLab::Projects.find!(client, 1083469)
|
195
|
+
# issue = Readiness::GitLab::Issues.find!(client, project, 5)
|
196
|
+
# puts issues.web_url
|
197
|
+
# # => "https://gitlab.com/gitlab-com/support/support-team-meta/-/issues/5"
|
198
|
+
def self.find!(client, project, iid)
|
199
|
+
response = client.connection.get "projects/#{project.id}/issues/#{iid}"
|
200
|
+
handle_request_error(1, 'GitLab', response.status, { action: 'Find issue', id: iid }) unless response.status == 200
|
201
|
+
Issues.new(Oj.load(response.body))
|
202
|
+
end
|
203
|
+
|
204
|
+
##
|
205
|
+
# Creates a project issue within GitLab. This will exit on error
|
206
|
+
#
|
207
|
+
# @author Jason Colyer
|
208
|
+
# @since 1.0.0
|
209
|
+
# @param client [Object] An instance of {Readiness::GitLab::Client}
|
210
|
+
# @param project [Object] An instance of {Readiness::GitLab::Projects}
|
211
|
+
# @param issue [Object] An instance of {Readiness::GitLab::Issues}
|
212
|
+
# @return [Object] An instance of {Readiness::GitLab::Issues}
|
213
|
+
# @see https://docs.gitlab.com/ee/api/issues.html#new-issue GitLab API > Issues > New issue
|
214
|
+
# @example
|
215
|
+
# require 'support_readiness'
|
216
|
+
# config = Readiness::GitLab::Configuration.new
|
217
|
+
# config.token = 'test123abc'
|
218
|
+
# client = Readiness::GitLab::Client.new(config)
|
219
|
+
# project = Readiness::GitLab::Projects.find!(client, 1083469)
|
220
|
+
# issue = Readiness::GitLab::Issues.new
|
221
|
+
# issue.title = 'Important issue!'
|
222
|
+
# issue.description = 'This is totally important!'
|
223
|
+
# issue.assignee_ids = [1, 3, 4]
|
224
|
+
# new_issue = Readiness::GitLab::Issues.create!(client, project, issue)
|
225
|
+
# puts new_issue.web_url
|
226
|
+
# # => "https://gitlab.com/gitlab-com/support/support-team-meta/-/issues/8"
|
227
|
+
def self.create!(client, project, issue)
|
228
|
+
response = client.connection.post "projects/#{project.id}/issues", to_clean_json(issue)
|
229
|
+
handle_request_error(1, 'GitLab', response.status, { action: 'Create issue', id: project.id }) unless response.status == 200
|
230
|
+
Issues.new(Oj.load(response.body))
|
231
|
+
end
|
232
|
+
|
233
|
+
##
|
234
|
+
# Updates a project issue within GitLab. This will exit on error
|
235
|
+
#
|
236
|
+
# @author Jason Colyer
|
237
|
+
# @since 1.0.0
|
238
|
+
# @param client [Object] An instance of {Readiness::GitLab::Client}
|
239
|
+
# @param project [Object] An instance of {Readiness::GitLab::Projects}
|
240
|
+
# @param issue [Object] An instance of {Readiness::GitLab::Issues}
|
241
|
+
# @return [Object] An instance of {Readiness::GitLab::Issues}
|
242
|
+
# @see https://docs.gitlab.com/ee/api/issues.html#edit-an-issue GitLab API > Issues > Edit an issue
|
243
|
+
# @example
|
244
|
+
# require 'support_readiness'
|
245
|
+
# config = Readiness::GitLab::Configuration.new
|
246
|
+
# config.token = 'test123abc'
|
247
|
+
# client = Readiness::GitLab::Client.new(config)
|
248
|
+
# project = Readiness::GitLab::Projects.find!(client, 1083469)
|
249
|
+
# issue = Readiness::GitLab::Issues.find!(client, project, 8)
|
250
|
+
# issue.title = 'Important issue v2!'
|
251
|
+
# new_issue = Readiness::GitLab::Issues.update!(client, project, issue)
|
252
|
+
# puts new_issue.title
|
253
|
+
# # => "Important issue v2!"
|
254
|
+
def self.update!(client, project, issue)
|
255
|
+
response = client.connection.put "projects/#{project.id}/issues/#{issue.iid}", to_clean_json(issue)
|
256
|
+
handle_request_error(1, 'GitLab', response.status, { action: 'Update an issue', id: "#{project.id}/issues/#{issue.iid}" }) unless response.status == 200
|
257
|
+
Issues.new(Oj.load(response.body))
|
258
|
+
end
|
259
|
+
|
260
|
+
##
|
261
|
+
# Deletes a project issue within GitLab. This will exit on error
|
262
|
+
#
|
263
|
+
# @author Jason Colyer
|
264
|
+
# @since 1.0.0
|
265
|
+
# @param client [Object] An instance of {Readiness::GitLab::Client}
|
266
|
+
# @param project [Object] An instance of {Readiness::GitLab::Projects}
|
267
|
+
# @param issue [Object] An instance of {Readiness::GitLab::Issues}
|
268
|
+
# @return [Boolean]
|
269
|
+
# @see https://docs.gitlab.com/ee/api/issues.html#delete-an-issue GitLab API > Issues > Delete an issue
|
270
|
+
# @example
|
271
|
+
# require 'support_readiness'
|
272
|
+
# config = Readiness::GitLab::Configuration.new
|
273
|
+
# config.token = 'test123abc'
|
274
|
+
# client = Readiness::GitLab::Client.new(config)
|
275
|
+
# project = Readiness::GitLab::Projects.find!(client, 1083469)
|
276
|
+
# issue = Readiness::GitLab::Issues.find!(client, project, 8)
|
277
|
+
# pp Readiness::GitLab::Issues.delete!(client, project, issue)
|
278
|
+
# # => true
|
279
|
+
def self.delete!(client, project, issue)
|
280
|
+
response = client.connection.delete "projects/#{project.id}/issues/#{issue.iid}"
|
281
|
+
handle_request_error(1, 'GitLab', response.status, { action: 'Delete an issue', id: "#{project.id}/issues/#{issue.iid}" }) unless response.status == 204
|
282
|
+
true
|
283
|
+
end
|
284
|
+
|
285
|
+
##
|
286
|
+
# Get all comments on a project issue within GitLab.
|
287
|
+
#
|
288
|
+
# @author Jason Colyer
|
289
|
+
# @since 1.0.0
|
290
|
+
# @param client [Object] An instance of {Readiness::GitLab::Client}
|
291
|
+
# @param project [Object] An instance of {Readiness::GitLab::Projects}
|
292
|
+
# @param issue [Object] An instance of {Readiness::GitLab::Issues}
|
293
|
+
# @return [Array]
|
294
|
+
# @see https://docs.gitlab.com/ee/api/notes.html#list-project-issue-notese GitLab API > Notes (comments) > List project issue notes
|
295
|
+
# @example
|
296
|
+
# require 'support_readiness'
|
297
|
+
# config = Readiness::GitLab::Configuration.new
|
298
|
+
# config.token = 'test123abc'
|
299
|
+
# client = Readiness::GitLab::Client.new(config)
|
300
|
+
# project = Readiness::GitLab::Projects.find!(client, 5)
|
301
|
+
# issue = Readiness::GitLab::Issues.find!(client, project, 11)
|
302
|
+
# comments = Readiness::GitLab::Issues.comments(client, project, issue)
|
303
|
+
# pp comments.first['updated_at']
|
304
|
+
# # => "2013-10-02T09:56:03Z"
|
305
|
+
def self.comments(client, project, issue)
|
306
|
+
array = []
|
307
|
+
page = 0
|
308
|
+
loop do
|
309
|
+
response = client.connection.get "projects/#{project.id}/issues/#{issues.id}/notes?per_page=100&page=#{page}"
|
310
|
+
handle_request_error(0, 'GitLab', response.status) unless response.status == 200
|
311
|
+
body = Oj.load(response.body)
|
312
|
+
array += body
|
313
|
+
break if body.count < 100
|
314
|
+
|
315
|
+
page += 1
|
316
|
+
end
|
317
|
+
array
|
318
|
+
end
|
319
|
+
|
320
|
+
##
|
321
|
+
# Create a comment on a project issue within GitLab.
|
322
|
+
#
|
323
|
+
# @author Jason Colyer
|
324
|
+
# @since 1.0.0
|
325
|
+
# @param client [Object] An instance of {Readiness::GitLab::Client}
|
326
|
+
# @param project [Object] An instance of {Readiness::GitLab::Projects}
|
327
|
+
# @param issue [Object] An instance of {Readiness::GitLab::Issues}
|
328
|
+
# @param params [Hash] The parameters to use in creating the comment
|
329
|
+
# @return [Hash]
|
330
|
+
# @see https://docs.gitlab.com/ee/api/notes.html#create-new-issue-note GitLab API > Notes (comments) > Create new issue note
|
331
|
+
# @example
|
332
|
+
# require 'support_readiness'
|
333
|
+
# config = Readiness::GitLab::Configuration.new
|
334
|
+
# config.token = 'test123abc'
|
335
|
+
# client = Readiness::GitLab::Client.new(config)
|
336
|
+
# project = Readiness::GitLab::Projects.find!(client, 5)
|
337
|
+
# issue = Readiness::GitLab::Issues.find!(client, project, 11)
|
338
|
+
# comment_params = {
|
339
|
+
# body: 'My name is Jason and I approve this comment',
|
340
|
+
# internal: true
|
341
|
+
# }
|
342
|
+
# comment = Readiness::GitLab::Issues.create_comment(client, project, issue, comment_params)
|
343
|
+
# pp comment['updated_at']
|
344
|
+
# # => "2024-09-23T15:42:13Z"
|
345
|
+
def self.create_comment!(client, project, issue, params)
|
346
|
+
response = client.connection.post "projects/#{project.id}/issues/#{issue.id}/notes", to_clean_json(params)
|
347
|
+
handle_request_error(1, 'GitLab', response.status, { action: 'Create issue comment', id: issue.id }) unless response.status == 200
|
348
|
+
Oj.load(response.body)
|
349
|
+
end
|
350
|
+
|
351
|
+
##
|
352
|
+
# Updates a comment on a project issue within GitLab.
|
353
|
+
#
|
354
|
+
# @author Jason Colyer
|
355
|
+
# @since 1.0.0
|
356
|
+
# @param client [Object] An instance of {Readiness::GitLab::Client}
|
357
|
+
# @param project [Object] An instance of {Readiness::GitLab::Projects}
|
358
|
+
# @param issue [Object] An instance of {Readiness::GitLab::Issues}
|
359
|
+
# @param cid [Integer] The comment ID to modify
|
360
|
+
# @param params [Hash] The parameters to use for the update
|
361
|
+
# @return [Hash]
|
362
|
+
# @see https://docs.gitlab.com/ee/api/notes.html#modify-existing-issue-note GitLab API > Notes (comments) > Modify an existing issue note
|
363
|
+
# @example
|
364
|
+
# require 'support_readiness'
|
365
|
+
# config = Readiness::GitLab::Configuration.new
|
366
|
+
# config.token = 'test123abc'
|
367
|
+
# client = Readiness::GitLab::Client.new(config)
|
368
|
+
# project = Readiness::GitLab::Projects.find!(client, 5)
|
369
|
+
# issue = Readiness::GitLab::Issues.find!(client, project, 11)
|
370
|
+
# comment_params = {
|
371
|
+
# internal: false
|
372
|
+
# }
|
373
|
+
# comment = Readiness::GitLab::Issues.update_comment!(client, project, issue, 15, comment_params)
|
374
|
+
# pp comment['updated_at']
|
375
|
+
# # => "2024-09-23T16:47:36Z"
|
376
|
+
def self.update_comment!(client, project, issue, cid, params)
|
377
|
+
response = client.connection.put "projects/#{project.id}/issues/#{issue.id}/notes/#{cid}", to_clean_json(params)
|
378
|
+
handle_request_error(1, 'GitLab', response.status, { action: 'Update issue comment', id: issue.id }) unless response.status == 200
|
379
|
+
Oj.load(response.body)
|
380
|
+
end
|
381
|
+
|
382
|
+
##
|
383
|
+
# Deletes a comment on a project issue within GitLab.
|
384
|
+
#
|
385
|
+
# @author Jason Colyer
|
386
|
+
# @since 1.0.0
|
387
|
+
# @param client [Object] An instance of {Readiness::GitLab::Client}
|
388
|
+
# @param project [Object] An instance of {Readiness::GitLab::Projects}
|
389
|
+
# @param issue [Object] An instance of {Readiness::GitLab::Issues}
|
390
|
+
# @param cid [Integer] The comment ID to modify
|
391
|
+
# @return [Boolean]
|
392
|
+
# @see https://docs.gitlab.com/ee/api/notes.html#delete-an-issue-note GitLab API > Notes (comments) > Delete an issue note
|
393
|
+
# @example
|
394
|
+
# require 'support_readiness'
|
395
|
+
# config = Readiness::GitLab::Configuration.new
|
396
|
+
# config.token = 'test123abc'
|
397
|
+
# client = Readiness::GitLab::Client.new(config)
|
398
|
+
# project = Readiness::GitLab::Projects.find!(client, 5)
|
399
|
+
# issue = Readiness::GitLab::Issues.find!(client, project, 11)
|
400
|
+
# comment = Readiness::GitLab::Issues.delete_comment!(client, project, issue, 15)
|
401
|
+
# pp comment
|
402
|
+
# # => true
|
403
|
+
def self.delete_comment!(client, project, issue, cid)
|
404
|
+
response = client.connection.delete "projects/#{project.id}/issues/#{issue.id}/notes/#{cid}"
|
405
|
+
handle_request_error(1, 'GitLab', response.status, { action: 'Delete issue comment', id: issue.id }) unless response.status == 204
|
406
|
+
true
|
407
|
+
end
|
408
|
+
end
|
409
|
+
end
|
410
|
+
end
|
@@ -0,0 +1,190 @@
|
|
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 Namespaces within the module {Readiness::GitLab}.
|
9
|
+
#
|
10
|
+
# @author Jason Colyer
|
11
|
+
# @since 1.0.0
|
12
|
+
class Namespaces < Readiness::Client
|
13
|
+
attr_accessor :avatar_url, :billable_members_count, :end_date, :full_path, :id, :kind, :max_seats_used, :members_count_with_descendants, :name, :parent_id, :path, :plan, :root_repository_size, :seats_in_use, :trial_ends_on, :trial, :web_url
|
14
|
+
|
15
|
+
##
|
16
|
+
# Creates a new {Readiness::GitLab::Namespaces} instance
|
17
|
+
#
|
18
|
+
# @author Jason Colyer
|
19
|
+
# @since 1.0.0
|
20
|
+
# @param object [Object] An instance of {Readiness::GitLab::Namespaces}
|
21
|
+
# @example
|
22
|
+
# require 'support_readiness'
|
23
|
+
# Readiness::GitLab::Namespaces.new
|
24
|
+
def initialize(object = {})
|
25
|
+
@avatar_url = object['avatar_url']
|
26
|
+
@billable_members_count = object['billable_members_count']
|
27
|
+
@end_date = object['end_date']
|
28
|
+
@full_path = object['full_path']
|
29
|
+
@id = object['id']
|
30
|
+
@kind = object['kind']
|
31
|
+
@max_seats_used = object['max_seats_used']
|
32
|
+
@members_count_with_descendants = object['members_count_with_descendants']
|
33
|
+
@name = object['name']
|
34
|
+
@parent_id = object['parent_id']
|
35
|
+
@path = object['path']
|
36
|
+
@plan = object['plan']
|
37
|
+
@root_repository_size = object['root_repository_size']
|
38
|
+
@seats_in_use = object['seats_in_use']
|
39
|
+
@trial_ends_on = object['trial_ends_on']
|
40
|
+
@trial = object['trial']
|
41
|
+
@web_url = object['web_url']
|
42
|
+
end
|
43
|
+
|
44
|
+
##
|
45
|
+
# Search for a namespace by name.
|
46
|
+
# This method can take a long time to run depending on the number of results found or permission level used.
|
47
|
+
#
|
48
|
+
# @author Jason Colyer
|
49
|
+
# @since 1.0.0
|
50
|
+
# @param client [Object] An instance of {Readiness::GitLab::Client}
|
51
|
+
# @param query [String] The name to search for
|
52
|
+
# @param filters [Array] An array of filter Strings to use. Should be in the format of key=value
|
53
|
+
# @return [Array]
|
54
|
+
# @see https://docs.gitlab.com/ee/api/namespaces.html#list-namespaces GitLab API > Namespaces > List namespaces
|
55
|
+
# @example
|
56
|
+
# require 'support_readiness'
|
57
|
+
# config = Readiness::GitLab::Configuration.new
|
58
|
+
# config.token = 'test123abc'
|
59
|
+
# client = Readiness::GitLab::Client.new(config)
|
60
|
+
# namespaces = Readiness::GitLab::Namespaces.search(client, 'jason_rocks', ["owned_only=true"])
|
61
|
+
# pp namespaces.first.full_path
|
62
|
+
# # => "jason-group/jason-rocks"
|
63
|
+
def self.search(client, query, filters = [])
|
64
|
+
response = client.connection.get "namespaces?search=#{query}&#{to_param_string(filters)}"
|
65
|
+
handle_request_error(0, 'GitLab', response.status) unless response.status == 200
|
66
|
+
Oj.load(response.body).map { |n| Namespaces.new(n) }
|
67
|
+
end
|
68
|
+
|
69
|
+
##
|
70
|
+
# Checks if a namespace exists
|
71
|
+
#
|
72
|
+
# @author Jason Colyer
|
73
|
+
# @since 1.0.0
|
74
|
+
# @param client [Object] An instance of {Readiness::GitLab::Client}
|
75
|
+
# @param name [String] The namespace to check for
|
76
|
+
# @return [Boolean]
|
77
|
+
# @see https://docs.gitlab.com/ee/api/namespaces.html#get-existence-of-a-namespace GitLab API > Namespaces > Get existence of a namespace
|
78
|
+
# @example
|
79
|
+
# require 'support_readiness'
|
80
|
+
# config = Readiness::GitLab::Configuration.new
|
81
|
+
# config.token = 'test123abc'
|
82
|
+
# client = Readiness::GitLab::Client.new(config)
|
83
|
+
# pp Readiness::GitLab::Namespaces.exists?(client, 'jason_rocks')
|
84
|
+
# # => true
|
85
|
+
# pp Readiness::GitLab::Namespaces.exists?(client, 'jason_does_not_rock')
|
86
|
+
# # => false
|
87
|
+
def self.exists?(client, name)
|
88
|
+
response = client.connection.get "namespaces/#{name}/exists"
|
89
|
+
handle_request_error(0, 'GitLab', response.status) unless response.status == 200
|
90
|
+
Oj.load(response.body)['exists']
|
91
|
+
end
|
92
|
+
|
93
|
+
##
|
94
|
+
# Locates a namespace within GitLab. This will not exit on error (except Authentication errors)
|
95
|
+
#
|
96
|
+
# @author Jason Colyer
|
97
|
+
# @since 1.0.0
|
98
|
+
# @param client [Object] An instance of {Readiness::GitLab::Client}
|
99
|
+
# @param nid [Integer] The namespace ID to find
|
100
|
+
# @return [Hash]
|
101
|
+
# @see https://docs.gitlab.com/ee/api/namespaces.html#get-namespace-by-id GitLab API > Namespaces > Get namespace by ID
|
102
|
+
# @example
|
103
|
+
# require 'support_readiness'
|
104
|
+
# config = Readiness::GitLab::Configuration.new
|
105
|
+
# config.token = 'test123abc'
|
106
|
+
# client = Readiness::GitLab::Client.new(config)
|
107
|
+
# namespace = Readiness::GitLab::Namespaces.find(client, 123)
|
108
|
+
# pp namespace.web_url
|
109
|
+
# # => "https://gitlab.com/groups/group123"
|
110
|
+
def self.find(client, nid)
|
111
|
+
response = client.connection.get "namespaces/#{nid}"
|
112
|
+
handle_request_error(0, 'GitLab', response.status, { action: 'get', id: nid }) unless response.status == 200
|
113
|
+
return Namespaces.new(Oj.load(response.body)) if response.status == 200
|
114
|
+
|
115
|
+
Oj.load(response.body)
|
116
|
+
end
|
117
|
+
|
118
|
+
##
|
119
|
+
# Locates a namespace within GitLab. This will exit on error
|
120
|
+
#
|
121
|
+
# @author Jason Colyer
|
122
|
+
# @since 1.0.0
|
123
|
+
# @param client [Object] An instance of {Readiness::GitLab::Client}
|
124
|
+
# @param nid [Integer] The namespace ID to find
|
125
|
+
# @return [Object] An instance of {Readiness::GitLab::Namespaces}
|
126
|
+
# @see https://docs.gitlab.com/ee/api/namespaces.html#get-namespace-by-id GitLab API > Namespaces > Get namespace by ID
|
127
|
+
# @example
|
128
|
+
# require 'support_readiness'
|
129
|
+
# config = Readiness::GitLab::Configuration.new
|
130
|
+
# config.token = 'test123abc'
|
131
|
+
# client = Readiness::GitLab::Client.new(config)
|
132
|
+
# namespace = Readiness::GitLab::Namespaces.find!(client, 123)
|
133
|
+
# pp namespace.web_url
|
134
|
+
# # => "https://gitlab.com/groups/group123"
|
135
|
+
def self.find!(client, nid)
|
136
|
+
response = client.connection.get "namespaces/#{nid}"
|
137
|
+
handle_request_error(1, 'GitLab', response.status, { action: 'Find namespace', id: nid }) unless response.status == 200
|
138
|
+
Namespaces.new(Oj.load(response.body))
|
139
|
+
end
|
140
|
+
|
141
|
+
##
|
142
|
+
# Locates the group owners for a namespace within GitLab
|
143
|
+
#
|
144
|
+
# @author Jason Colyer
|
145
|
+
# @since 1.0.0
|
146
|
+
# @param client [Object] An instance of {Readiness::GitLab::Client}
|
147
|
+
# @param namespace [Object] An instance of {Readiness::GitLab::Namespaces}
|
148
|
+
# @return [Array]
|
149
|
+
# @see https://docs.gitlab.com/ee/development/internal_api/gitlab_subscriptions.html#fetch-group-owners GitLab API > Internal API > GitLab Subscriptions > Fetch group owners
|
150
|
+
# @example
|
151
|
+
# require 'support_readiness'
|
152
|
+
# config = Readiness::GitLab::Configuration.new
|
153
|
+
# config.token = 'test123abc'
|
154
|
+
# client = Readiness::GitLab::Client.new(config)
|
155
|
+
# namespace = Readiness::GitLab::Namespaces.find!(client, 123)
|
156
|
+
# owners = Readiness::GitLab::Namespaces.owners(client, namespace)
|
157
|
+
# pp owners.last['user']['name']
|
158
|
+
# # => "John Smith"
|
159
|
+
def self.owners(client, namespace)
|
160
|
+
response = client.connection.get "internal/gitlab_subscriptions/namespaces/#{namespace.id}/owners"
|
161
|
+
handle_request_error(0, 'GitLab', response.status, { action: 'get', id: namespace.id }) unless response.status == 200
|
162
|
+
Oj.load(response.body)
|
163
|
+
end
|
164
|
+
|
165
|
+
##
|
166
|
+
# Locates the subscription for a namespace within GitLab
|
167
|
+
#
|
168
|
+
# @author Jason Colyer
|
169
|
+
# @since 1.0.0
|
170
|
+
# @param client [Object] An instance of {Readiness::GitLab::Client}
|
171
|
+
# @param namespace [Object] An instance of {Readiness::GitLab::Namespaces}
|
172
|
+
# @return [Array]
|
173
|
+
# @see https://docs.gitlab.com/ee/development/internal_api/gitlab_subscriptions.html#fetch-a-subscription GitLab API > Internal API > GitLab Subscriptions > Fetch a subscription
|
174
|
+
# @example
|
175
|
+
# require 'support_readiness'
|
176
|
+
# config = Readiness::GitLab::Configuration.new
|
177
|
+
# config.token = 'test123abc'
|
178
|
+
# client = Readiness::GitLab::Client.new(config)
|
179
|
+
# namespace = Readiness::GitLab::Namespaces.find!(client, 123)
|
180
|
+
# sub = Readiness::GitLab::Namespaces.subscription(client, namespace)
|
181
|
+
# pp sub['plan']['code']
|
182
|
+
# # => "ultimate"
|
183
|
+
def self.subscription(client, namespace)
|
184
|
+
response = client.connection.get "internal/gitlab_subscriptions/namespaces/#{namespace.id}/gitlab_subscription"
|
185
|
+
handle_request_error(0, 'GitLab', response.status, { action: 'get', id: namespace.id }) unless response.status == 200
|
186
|
+
Oj.load(response.body)
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|