gitlab-customer-support-operations_gitlab 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.
Files changed (35) hide show
  1. checksums.yaml +7 -0
  2. data/lib/support_ops_gitlab/gitlab/badges.rb +229 -0
  3. data/lib/support_ops_gitlab/gitlab/base.rb +552 -0
  4. data/lib/support_ops_gitlab/gitlab/client.rb +51 -0
  5. data/lib/support_ops_gitlab/gitlab/commits.rb +198 -0
  6. data/lib/support_ops_gitlab/gitlab/configuration.rb +86 -0
  7. data/lib/support_ops_gitlab/gitlab/epics.rb +325 -0
  8. data/lib/support_ops_gitlab/gitlab/events.rb +167 -0
  9. data/lib/support_ops_gitlab/gitlab/gpg_keys.rb +64 -0
  10. data/lib/support_ops_gitlab/gitlab/group_memberships.rb +33 -0
  11. data/lib/support_ops_gitlab/gitlab/groups.rb +431 -0
  12. data/lib/support_ops_gitlab/gitlab/invitations.rb +72 -0
  13. data/lib/support_ops_gitlab/gitlab/issues.rb +606 -0
  14. data/lib/support_ops_gitlab/gitlab/jobs.rb +61 -0
  15. data/lib/support_ops_gitlab/gitlab/markdown.rb +54 -0
  16. data/lib/support_ops_gitlab/gitlab/merge_requests.rb +411 -0
  17. data/lib/support_ops_gitlab/gitlab/milestones.rb +195 -0
  18. data/lib/support_ops_gitlab/gitlab/namespaces.rb +184 -0
  19. data/lib/support_ops_gitlab/gitlab/notes.rb +182 -0
  20. data/lib/support_ops_gitlab/gitlab/pipelines.rb +258 -0
  21. data/lib/support_ops_gitlab/gitlab/project_access_tokens.rb +245 -0
  22. data/lib/support_ops_gitlab/gitlab/project_memberships.rb +33 -0
  23. data/lib/support_ops_gitlab/gitlab/project_webhook_events.rb +33 -0
  24. data/lib/support_ops_gitlab/gitlab/project_webhooks.rb +218 -0
  25. data/lib/support_ops_gitlab/gitlab/projects.rb +741 -0
  26. data/lib/support_ops_gitlab/gitlab/repository_files.rb +102 -0
  27. data/lib/support_ops_gitlab/gitlab/repository_submodules.rb +78 -0
  28. data/lib/support_ops_gitlab/gitlab/ssh_keys.rb +67 -0
  29. data/lib/support_ops_gitlab/gitlab/user_emails.rb +147 -0
  30. data/lib/support_ops_gitlab/gitlab/user_memberships.rb +21 -0
  31. data/lib/support_ops_gitlab/gitlab/user_tokens.rb +344 -0
  32. data/lib/support_ops_gitlab/gitlab/users.rb +1059 -0
  33. data/lib/support_ops_gitlab/gitlab.rb +45 -0
  34. data/lib/support_ops_gitlab.rb +28 -0
  35. metadata +251 -0
@@ -0,0 +1,552 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Defines the module SupportOps.
4
+ module SupportOps
5
+ # Defines the module GitLab
6
+ module GitLab
7
+ ##
8
+ # Defines the class Base within the module {SupportOps::GitLab}.
9
+ #
10
+ # @author Jason Colyer
11
+ # @since 1.0.0
12
+ class Base
13
+ class << self
14
+ def client
15
+ Configuration.config.client
16
+ end
17
+
18
+ def configure
19
+ yield Configuration.config
20
+ end
21
+
22
+ def define_attributes(*attrs)
23
+ @attributes = attrs
24
+ attrs.each do |attr|
25
+ attr_accessor attr
26
+ end
27
+ end
28
+
29
+ def attributes
30
+ @attributes || []
31
+ end
32
+
33
+ def readonly_attributes(*attrs)
34
+ return @readonly_attributes || [] if attrs.empty?
35
+
36
+ @readonly_attributes = attrs
37
+ end
38
+ end
39
+
40
+ def initialize(attributes = {}, client = nil)
41
+ @client = client
42
+ @original_attributes = {}
43
+ set_attributes(attributes)
44
+ store_original_attributes
45
+ end
46
+
47
+ def store_original_attributes
48
+ @original_attributes = {}
49
+ self.class.attributes.each do |attr|
50
+ @original_attributes[attr] = instance_variable_get("@#{attr}")
51
+ end
52
+ end
53
+
54
+ ##
55
+ # Converts an Object to a Hash
56
+ #
57
+ # @author Jason Colyer
58
+ # @since 1.0.0
59
+ # @param object [Object]
60
+ # @return [Hash]
61
+ def self.to_hash(object)
62
+ Hash[object.instance_variables.map { |name| [name.to_s[1..-1], object.instance_variable_get(name)] }]
63
+ end
64
+
65
+ def find
66
+ ensure_client_present!
67
+ set_attributes(get_record)
68
+ store_original_attributes
69
+ self
70
+ end
71
+
72
+ def find!
73
+ ensure_client_present!
74
+ attrs = get_record
75
+ if attrs == nil
76
+ raise "Unable to locate #{self.class.name.demodulize.singularize.downcase} '#{self.id}'"
77
+ end
78
+ set_attributes(attrs)
79
+ store_original_attributes
80
+ self
81
+ end
82
+
83
+ def save!
84
+ ensure_client_present!
85
+ new_data = if id.nil?
86
+ create_record
87
+ else
88
+ update_record
89
+ end
90
+ new_data.each do |key, value|
91
+ self.instance_variable_set("@#{key}", value) if self.respond_to?("#{key}=")
92
+ end
93
+ store_original_attributes
94
+ self
95
+ end
96
+
97
+ def delete!
98
+ ensure_client_present!
99
+ delete_record
100
+ end
101
+
102
+ def hard_delete!
103
+ ensure_client_present!
104
+ hard_delete_record
105
+ end
106
+
107
+ def status
108
+ ensure_client_present!
109
+ status_record
110
+ end
111
+
112
+ def preferences
113
+ ensure_client_present!
114
+ preferences_record
115
+ end
116
+
117
+ def projects
118
+ ensure_client_present!
119
+ projects_record
120
+ end
121
+
122
+ def memberships
123
+ ensure_client_present!
124
+ memberships_record
125
+ end
126
+
127
+ def ssh_keys
128
+ ensure_client_present!
129
+ ssh_keys_record
130
+ end
131
+
132
+ def gpg_keys
133
+ ensure_client_present!
134
+ gpg_keys_record
135
+ end
136
+
137
+ def tokens
138
+ ensure_client_present!
139
+ tokens_record
140
+ end
141
+
142
+ def pats
143
+ ensure_client_present!
144
+ pats_records
145
+ end
146
+
147
+ def impersonations
148
+ ensure_client_present!
149
+ impersonations_record
150
+ end
151
+
152
+ def block!
153
+ ensure_client_present!
154
+ block_record
155
+ end
156
+
157
+ def unblock!
158
+ ensure_client_present!
159
+ unblock_record
160
+ end
161
+
162
+ def ban!
163
+ ensure_client_present!
164
+ ban_record
165
+ end
166
+
167
+ def unban!
168
+ ensure_client_present!
169
+ unban_record
170
+ end
171
+
172
+ def approve!
173
+ ensure_client_present!
174
+ approve_record
175
+ end
176
+
177
+ def reject!
178
+ ensure_client_present!
179
+ reject_record
180
+ end
181
+
182
+ def deactivate!
183
+ re_client_present!
184
+ deactivate_record
185
+ end
186
+
187
+ def activate!
188
+ re_client_present!
189
+ activate_record
190
+ end
191
+
192
+ def emails
193
+ ensure_client_present!
194
+ emails_record
195
+ end
196
+
197
+ def support_pin
198
+ ensure_client_present!
199
+ support_pin_record
200
+ end
201
+
202
+ def create_support_pin!
203
+ ensure_client_present!
204
+ create_support_pin_record
205
+ end
206
+
207
+ def disable_2fa!
208
+ ensure_client_present!
209
+ disable_2fa_record
210
+ end
211
+
212
+ def rotate!
213
+ ensure_client_present!
214
+ rotate_record
215
+ end
216
+
217
+ def revoke!
218
+ ensure_client_present!
219
+ revoke_record
220
+ end
221
+
222
+ def members(**args)
223
+ ensure_client_present!
224
+ members_record(**args)
225
+ end
226
+
227
+ def encoded_path
228
+ encoded_path_record
229
+ end
230
+
231
+ def paid?
232
+ is_paid_record
233
+ end
234
+
235
+ def badges
236
+ ensure_client_present!
237
+ badges_record
238
+ end
239
+
240
+ def issues
241
+ ensure_client_present!
242
+ issues_record
243
+ end
244
+
245
+ def merge_requests
246
+ ensure_client_present!
247
+ merge_requests_record
248
+ end
249
+
250
+ def move!
251
+ ensure_client_present!
252
+ move_record
253
+ end
254
+
255
+ def subscribe!
256
+ ensure_client_present!
257
+ subscribe_record
258
+ end
259
+
260
+ def unsubscribe!
261
+ ensure_client_present!
262
+ unsubscribe_record
263
+ end
264
+
265
+ def notes
266
+ ensure_client_present!
267
+ notes_record
268
+ end
269
+
270
+ def discussions
271
+ ensure_client_present!
272
+ discussions_record
273
+ end
274
+
275
+ def pipelines
276
+ ensure_client_present!
277
+ pipelines_record
278
+ end
279
+
280
+ def latest_pipeline
281
+ ensure_client_present!
282
+ latest_pipeline_record
283
+ end
284
+
285
+ def pipeline_variables
286
+ ensure_client_present!
287
+ pipeline_variables_record
288
+ end
289
+
290
+ def jobs
291
+ ensure_client_present!
292
+ jobs_record
293
+ end
294
+
295
+ def events
296
+ ensure_client_present!
297
+ events_record
298
+ end
299
+
300
+ def webhooks
301
+ ensure_client_present!
302
+ webhooks_record
303
+ end
304
+
305
+ def commits
306
+ ensure_client_present!
307
+ commits_record
308
+ end
309
+
310
+ def contributors
311
+ ensure_client_present!
312
+ contributors_record
313
+ end
314
+
315
+ def client=(new_client)
316
+ @client = new_client
317
+ end
318
+
319
+ protected
320
+
321
+ attr_reader :attributes, :original_attributes
322
+
323
+ def set_attributes(attributes)
324
+ return unless attributes
325
+
326
+ attrs = attributes.transform_keys(&:to_sym)
327
+
328
+ self.class.attributes.each do |attr|
329
+ instance_variable_set("@#{attr}", attrs[attr])
330
+ end
331
+ end
332
+
333
+ def attributes_for_save
334
+ if send(:id) == nil
335
+ self.class.attributes
336
+ .reject { |attr| self.class.readonly_attributes.include?(attr) }
337
+ .each_with_object({}) do |attr, hash|
338
+ hash[attr] = send(attr)
339
+ end
340
+ else
341
+ self.class.attributes
342
+ .reject { |attr| self.class.readonly_attributes.include?(attr) }
343
+ .each_with_object({}) do |attr, hash|
344
+ current_value = send(attr)
345
+ original_value = @original_attributes[attr]
346
+
347
+ hash[attr] = current_value if attr == :id
348
+ if original_value != current_value
349
+ hash[attr] = current_value
350
+ end
351
+ end
352
+ end
353
+ end
354
+
355
+ def client
356
+ @client ||= self.class.client
357
+ end
358
+
359
+ def ensure_client_present!
360
+ raise 'No client configured. Use SupportOps::GitLab.configure to set up the client.' unless client
361
+ end
362
+
363
+ def get_record(**args)
364
+ raise NotImplementedError
365
+ end
366
+
367
+ def create_record
368
+ raise NotImplementedError
369
+ end
370
+
371
+ def update_record
372
+ raise NotImplementedError
373
+ end
374
+
375
+ def delete_record
376
+ raise NotImplementedError
377
+ end
378
+
379
+ def hard_delete_record
380
+ raise NotImplementedError
381
+ end
382
+
383
+ def status_record
384
+ raise NotImplementedError
385
+ end
386
+
387
+ def preferences_record
388
+ raise NotImplementedError
389
+ end
390
+
391
+ def projects_record
392
+ raise NotImplementedError
393
+ end
394
+
395
+ def memberships_record
396
+ raise NotImplementedError
397
+ end
398
+
399
+ def ssh_keys_record
400
+ raise NotImplementedError
401
+ end
402
+
403
+ def gpg_keys_record
404
+ raise NotImplementedError
405
+ end
406
+
407
+ def tokens_record
408
+ raise NotImplementedError
409
+ end
410
+
411
+ def pats_records
412
+ raise NotImplementedError
413
+ end
414
+
415
+ def impersonations_record
416
+ raise NotImplementedError
417
+ end
418
+
419
+ def block_record
420
+ raise NotImplementedError
421
+ end
422
+
423
+ def unblock_record
424
+ raise NotImplementedError
425
+ end
426
+
427
+ def ban_record
428
+ raise NotImplementedError
429
+ end
430
+
431
+ def unban_record
432
+ raise NotImplementedError
433
+ end
434
+
435
+ def approve_record
436
+ raise NotImplementedError
437
+ end
438
+
439
+ def reject_record
440
+ raise NotImplementedError
441
+ end
442
+
443
+ def deactivate_record
444
+ raise NotImplementedError
445
+ end
446
+
447
+ def activate_record
448
+ raise NotImplementedError
449
+ end
450
+
451
+ def emails_record
452
+ raise NotImplementedError
453
+ end
454
+
455
+ def support_pin_record
456
+ raise NotImplementedError
457
+ end
458
+
459
+ def create_support_pin_record
460
+ raise NotImplementedError
461
+ end
462
+
463
+ def disable_2fa_record
464
+ raise NotImplementedError
465
+ end
466
+
467
+ def rotate_record
468
+ raise NotImplementedError
469
+ end
470
+
471
+ def revoke_record
472
+ raise NotImplementedError
473
+ end
474
+
475
+ def members_record
476
+ raise NotImplementedError
477
+ end
478
+
479
+ def encoded_path_record
480
+ raise NotImplementedError
481
+ end
482
+
483
+ def is_paid_record
484
+ raise NotImplementedError
485
+ end
486
+
487
+ def badges_record
488
+ raise NotImplementedError
489
+ end
490
+
491
+ def issues_record
492
+ raise NotImplementedError
493
+ end
494
+
495
+ def merge_requests_record
496
+ raise NotImplementedError
497
+ end
498
+
499
+ def move_record
500
+ raise NotImplementedError
501
+ end
502
+
503
+ def subscribe_record
504
+ raise NotImplementedError
505
+ end
506
+
507
+ def unsubscribe_record
508
+ raise NotImplementedError
509
+ end
510
+
511
+ def notes_record
512
+ raise NotImplementedError
513
+ end
514
+
515
+ def discussions_record
516
+ raise NotImplementedError
517
+ end
518
+
519
+ def pipelines_record
520
+ raise NotImplementedError
521
+ end
522
+
523
+ def latest_pipeline_record
524
+ raise NotImplementedError
525
+ end
526
+
527
+ def pipeline_variables_record
528
+ raise NotImplementedError
529
+ end
530
+
531
+ def jobs_record
532
+ raise NotImplementedError
533
+ end
534
+
535
+ def events_record
536
+ raise NotImplementedError
537
+ end
538
+
539
+ def webhooks_record
540
+ raise NotImplementedError
541
+ end
542
+
543
+ def commits_record
544
+ raise NotImplementedError
545
+ end
546
+
547
+ def contributors_record
548
+ raise NotImplementedError
549
+ end
550
+ end
551
+ end
552
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Defines the module SupportOps.
4
+ module SupportOps
5
+ # Defines the module GitLab
6
+ module GitLab
7
+ ##
8
+ # Defines the class Client within the module {SupportOps::GitLab}.
9
+ #
10
+ # @author Jason Colyer
11
+ # @since 1.0.0
12
+ class Client
13
+ class Error < StandardError; end
14
+ class RequestError < Error; end
15
+ class ResourceNotFound < Error; end
16
+
17
+ attr_reader :connection
18
+
19
+ def initialize(config = SupportOps::GitLab::Configuration.new)
20
+ if config[:token].nil? && config[:job_token].nil?
21
+ raise 'No authentication token provided'
22
+ end
23
+ @connection = generate_connection(config)
24
+ end
25
+
26
+ def retry_options(config)
27
+ {
28
+ max: config[:retry_max],
29
+ interval: config[:retry_interval],
30
+ interval_randomness: config[:retry_randomness],
31
+ backoff_factor: config[:retry_backoff],
32
+ exceptions: config[:retry_exceptions]
33
+ }
34
+ end
35
+
36
+ def generate_connection(config)
37
+ Faraday.new(config[:url]) do |c|
38
+ c.request :retry, retry_options(config)
39
+ c.adapter Faraday.default_adapter
40
+ c.headers['Content-Type'] = 'application/json'
41
+ unless config[:token].nil?
42
+ c.headers['Authorization'] = "Bearer #{config[:token]}"
43
+ end
44
+ unless config[:job_token].nil?
45
+ c.headers['JOB-TOKEN'] = config[:job_token]
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end