gitlab_support_readiness 1.0.11 → 1.0.12

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 (72) hide show
  1. checksums.yaml +4 -4
  2. data/lib/support_readiness/calendly/client.rb +64 -0
  3. data/lib/support_readiness/calendly/configuration.rb +45 -0
  4. data/lib/support_readiness/calendly/organization_memberships.rb +67 -0
  5. data/lib/support_readiness/calendly/organizations.rb +123 -0
  6. data/lib/support_readiness/calendly/users.rb +105 -0
  7. data/lib/support_readiness/calendly.rb +16 -0
  8. data/lib/support_readiness/client.rb +88 -1
  9. data/lib/support_readiness/dates.rb +90 -0
  10. data/lib/support_readiness/gitlab/configuration.rb +0 -1
  11. data/lib/support_readiness/gitlab/groups.rb +35 -0
  12. data/lib/support_readiness/gitlab/markdown.rb +37 -0
  13. data/lib/support_readiness/gitlab/merge_requests.rb +127 -0
  14. data/lib/support_readiness/gitlab/namespaces.rb +22 -0
  15. data/lib/support_readiness/gitlab/projects.rb +36 -1
  16. data/lib/support_readiness/gitlab/repositories.rb +174 -0
  17. data/lib/support_readiness/gitlab/users.rb +24 -0
  18. data/lib/support_readiness/gitlab.rb +2 -0
  19. data/lib/support_readiness/google_calendar/client.rb +59 -0
  20. data/lib/support_readiness/google_calendar/configuration.rb +39 -0
  21. data/lib/support_readiness/google_calendar/events.rb +169 -0
  22. data/lib/support_readiness/google_calendar.rb +14 -0
  23. data/lib/support_readiness/mailgun/bounces.rb +103 -0
  24. data/lib/support_readiness/mailgun/client.rb +65 -0
  25. data/lib/support_readiness/mailgun/configuration.rb +46 -0
  26. data/lib/support_readiness/mailgun/emails.rb +95 -0
  27. data/lib/support_readiness/mailgun.rb +15 -0
  28. data/lib/support_readiness/pagerduty/escalation_policies.rb +1 -1
  29. data/lib/support_readiness/pagerduty/schedules.rb +27 -3
  30. data/lib/support_readiness/pagerduty/services.rb +1 -1
  31. data/lib/support_readiness/pagerduty/users.rb +197 -0
  32. data/lib/support_readiness/pagerduty.rb +1 -0
  33. data/lib/support_readiness/repos/articles.rb +335 -0
  34. data/lib/support_readiness/repos/automations.rb +247 -0
  35. data/lib/support_readiness/repos/groups.rb +188 -0
  36. data/lib/support_readiness/repos/macros.rb +224 -0
  37. data/lib/support_readiness/repos/organization_fields.rb +193 -0
  38. data/lib/support_readiness/repos/sla_policies.rb +192 -0
  39. data/lib/support_readiness/repos/ticket_fields.rb +200 -0
  40. data/lib/support_readiness/repos/ticket_forms.rb +200 -0
  41. data/lib/support_readiness/repos/triggers.rb +255 -0
  42. data/lib/support_readiness/repos/user_fields.rb +201 -0
  43. data/lib/support_readiness/repos/views.rb +362 -0
  44. data/lib/support_readiness/repos.rb +22 -0
  45. data/lib/support_readiness/salesforce/accounts.rb +109 -0
  46. data/lib/support_readiness/salesforce/cases.rb +109 -0
  47. data/lib/support_readiness/salesforce/client.rb +64 -0
  48. data/lib/support_readiness/salesforce/configuration.rb +49 -0
  49. data/lib/support_readiness/salesforce/queries.rb +62 -0
  50. data/lib/support_readiness/salesforce.rb +16 -0
  51. data/lib/support_readiness/slack/client.rb +63 -0
  52. data/lib/support_readiness/slack/configuration.rb +43 -0
  53. data/lib/support_readiness/slack/messages.rb +37 -0
  54. data/lib/support_readiness/slack.rb +14 -0
  55. data/lib/support_readiness/zendesk/app_job_statuses.rb +140 -0
  56. data/lib/support_readiness/zendesk/apps.rb +209 -0
  57. data/lib/support_readiness/zendesk/automations.rb +1 -2
  58. data/lib/support_readiness/zendesk/macros.rb +1 -3
  59. data/lib/support_readiness/zendesk/organization_fields.rb +1 -1
  60. data/lib/support_readiness/zendesk/theme_job_statuses.rb +136 -0
  61. data/lib/support_readiness/zendesk/themes.rb +303 -0
  62. data/lib/support_readiness/zendesk/ticket_field_options.rb +110 -0
  63. data/lib/support_readiness/zendesk/ticket_fields.rb +85 -16
  64. data/lib/support_readiness/zendesk/ticket_forms.rb +65 -2
  65. data/lib/support_readiness/zendesk/tickets.rb +77 -0
  66. data/lib/support_readiness/zendesk/triggers.rb +1 -2
  67. data/lib/support_readiness/zendesk/user_field_options.rb +110 -0
  68. data/lib/support_readiness/zendesk/user_fields.rb +257 -0
  69. data/lib/support_readiness/zendesk/views.rb +49 -2
  70. data/lib/support_readiness/zendesk.rb +7 -0
  71. data/lib/support_readiness.rb +16 -0
  72. metadata +120 -2
@@ -0,0 +1,37 @@
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 Markdown within the module {Readiness::GitLab}.
9
+ #
10
+ # @author Jason Colyer
11
+ # @since 1.0.12
12
+ class Markdown < Readiness::Client
13
+ ##
14
+ # Renders text using Markdown
15
+ #
16
+ # @author Jason Colyer
17
+ # @since 1.0.12
18
+ # @param client [Object] An instance of {Readiness::GitLab::Client}
19
+ # @param text [String] The text to render
20
+ # @param gfm [Boolean] If this should render as GitLab Flavored Markdown or not
21
+ # @param project [String] The project slug to use as a template
22
+ # @return [String]
23
+ # @see https://docs.gitlab.com/ee/api/markdown.html#render-an-arbitrary-markdown-document GitLab API > Markdown > Render an arbitrary Markdown document
24
+ # @example
25
+ # require 'support_readiness'
26
+ # config = Readiness::GitLab::Configuration.new
27
+ # config.token = ENV.fetch('GL_TOKEN')
28
+ # client = Readiness::GitLab::Client.new(config)
29
+ # pp Readiness::GitLab::Markdown.convert(client, 'This is a test')
30
+ # # => "<p data-sourcepos=\"1:1-1:14\">This is a test</p>"
31
+ def self.convert(client, text, gfm = false, project = 'gitlab-org/gitlab')
32
+ response = client.connection.post 'markdown', { text: text, gfm: gfm, project: project }.to_json
33
+ Oj.load(response.body)['html']
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,127 @@
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 MergeRequests within the module {Readiness::GitLab}.
9
+ #
10
+ # @author Jason Colyer
11
+ # @since 1.0.12
12
+ class MergeRequests < Readiness::Client
13
+ ##
14
+ # Locates a project merge request within GitLab. This will not exit on error (except Authentication errors)
15
+ #
16
+ # @author Jason Colyer
17
+ # @since 1.0.12
18
+ # @param client [Object] An instance of {Readiness::GitLab::Client}
19
+ # @param project [Object] An instance of {Readiness::GitLab::Projects}
20
+ # @param iid [Integer] The issue ID to find
21
+ # @return [Hash]
22
+ # @see https://docs.gitlab.com/ee/api/merge_requests.html#get-single-mr GitLab API > Merge requests > Get single MR
23
+ # @example
24
+ # require 'support_readiness'
25
+ # config = Readiness::GitLab::Configuration.new
26
+ # config.token = 'test123abc'
27
+ # client = Readiness::GitLab::Client.new(config)
28
+ # project = Readiness::GitLab::Projects.find!(client, 1083469)
29
+ # issue = Readiness::GitLab::MergeRequests.find(client, project, 5)
30
+ # puts issues.web_url
31
+ # # => "https://gitlab.com/gitlab-com/support/support-team-meta/-/merge_requests/5"
32
+ def self.find(client, project, iid)
33
+ response = client.connection.get "projects/#{project.id}/merge_requests/#{iid}"
34
+ Oj.load(response.body)
35
+ end
36
+
37
+ ##
38
+ # Locates a project merge request within GitLab. This will exit on error
39
+ #
40
+ # @author Jason Colyer
41
+ # @since 1.0.12
42
+ # @param client [Object] An instance of {Readiness::GitLab::Client}
43
+ # @param project [Object] An instance of {Readiness::GitLab::Projects}
44
+ # @param iid [Integer] The issue ID to find
45
+ # @return [Hash]
46
+ # @see https://docs.gitlab.com/ee/api/merge_requests.html#get-single-mr GitLab API > Merge requests > Get single MR
47
+ # @example
48
+ # require 'support_readiness'
49
+ # config = Readiness::GitLab::Configuration.new
50
+ # config.token = 'test123abc'
51
+ # client = Readiness::GitLab::Client.new(config)
52
+ # project = Readiness::GitLab::Projects.find!(client, 1083469)
53
+ # issue = Readiness::GitLab::MergeRequests.find!(client, project, 5)
54
+ # puts issues.web_url
55
+ # # => "https://gitlab.com/gitlab-com/support/support-team-meta/-/merge_requests/5"
56
+ def self.find!(client, project, iid)
57
+ response = client.connection.get "projects/#{project.id}/merge_requests/#{iid}"
58
+ handle_request_error(1, 'GitLab', response.status, { action: 'Find MR', id: "projects/#{project.id}/merge_requests/#{iid}" }) unless response.status == 200
59
+ Oj.load(response.body)
60
+ end
61
+
62
+ ##
63
+ # Get all comments on a project merge request within GitLab.
64
+ #
65
+ # @author Jason Colyer
66
+ # @since 1.0.12
67
+ # @param client [Object] An instance of {Readiness::GitLab::Client}
68
+ # @param project [Object] An instance of {Readiness::GitLab::Projects}
69
+ # @param iid [Integer] The IID of the merge request
70
+ # @return [Array]
71
+ # @see https://docs.gitlab.com/ee/api/notes.html#list-all-merge-request-notes GitLab API > Notes (comments) > List all merge request notes
72
+ # @example
73
+ # require 'support_readiness'
74
+ # config = Readiness::GitLab::Configuration.new
75
+ # config.token = 'test123abc'
76
+ # client = Readiness::GitLab::Client.new(config)
77
+ # project = Readiness::GitLab::Projects.find!(client, 5)
78
+ # comments = Readiness::GitLab::MergeRequests.comments(client, project, 123)
79
+ # pp comments.first['updated_at']
80
+ # # => "2013-10-02T09:56:03Z"
81
+ def self.comments(client, project, iid)
82
+ array = []
83
+ page = 0
84
+ loop do
85
+ response = client.connection.get "projects/#{project.id}/merge_requests/#{iid}/notes?per_page=100&page=#{page}"
86
+ handle_request_error(0, 'GitLab', response.status) unless response.status == 200
87
+ body = Oj.load(response.body)
88
+ array += body
89
+ break if body.count < 100
90
+
91
+ page += 1
92
+ end
93
+ array
94
+ end
95
+
96
+ ##
97
+ # Create a comment on a project merge request within GitLab.
98
+ #
99
+ # @author Jason Colyer
100
+ # @since 1.0.12
101
+ # @param client [Object] An instance of {Readiness::GitLab::Client}
102
+ # @param project [Object] An instance of {Readiness::GitLab::Projects}
103
+ # @param iid [Integer] The IID of the merge request
104
+ # @param params [Hash] The parameters to use in creating the comment
105
+ # @return [Hash]
106
+ # @see https://docs.gitlab.com/ee/api/notes.html#create-new-merge-request-note GitLab API > Notes (comments) > Create new merge request note
107
+ # @example
108
+ # require 'support_readiness'
109
+ # config = Readiness::GitLab::Configuration.new
110
+ # config.token = 'test123abc'
111
+ # client = Readiness::GitLab::Client.new(config)
112
+ # project = Readiness::GitLab::Projects.find!(client, 5)
113
+ # comment_params = {
114
+ # body: 'My name is Jason and I approve this comment',
115
+ # internal: true
116
+ # }
117
+ # comment = Readiness::GitLab::MergeRequests.create_comment(client, project, 123, comment_params)
118
+ # pp comment['updated_at']
119
+ # # => "2024-09-23T15:42:13Z"
120
+ def self.create_comment!(client, project, iid, params)
121
+ response = client.connection.post "projects/#{project.id}/merge_requests/#{iid}/notes", params.to_json
122
+ handle_request_error(1, 'GitLab', response.status, { action: 'Create MR comment', id: "projects/#{project.id}/merge_requests/#{iid}" }) unless response.status == 200
123
+ Oj.load(response.body)
124
+ end
125
+ end
126
+ end
127
+ end
@@ -185,6 +185,28 @@ module Readiness
185
185
  handle_request_error(0, 'GitLab', response.status, { action: 'get', id: namespace.id }) unless response.status == 200
186
186
  Oj.load(response.body)
187
187
  end
188
+
189
+ ##
190
+ # Determines if a given namespace is paid or not
191
+ #
192
+ # @author Jason Colyer
193
+ # @since 1.0.12
194
+ # @param client [Object] An instance of {Readiness::GitLab::Client}
195
+ # @param namespace [Object] An instance of {Readiness::GitLab::Namespaces}
196
+ # @return [Boolean]
197
+ # @example
198
+ # require 'support_readiness'
199
+ # config = Readiness::GitLab::Configuration.new
200
+ # config.token = 'test123abc'
201
+ # client = Readiness::GitLab::Client.new(config)
202
+ # namespace = Readiness::GitLab::Namespaces.find!(client, 123)
203
+ # pp Readiness::GitLab::Namespaces.is_paid?(client, namespace)
204
+ # # => true
205
+ def self.is_paid?(client, namespace)
206
+ return true if %w[bronze silver gold premium ultimate].include? namespace.plan
207
+
208
+ false
209
+ end
188
210
  end
189
211
  end
190
212
  end
@@ -385,7 +385,7 @@ module Readiness
385
385
  # # => "alice_one"
386
386
  def self.all_members(client, project, filters = [])
387
387
  array = []
388
- page = 1
388
+ page = 0
389
389
  loop do
390
390
  response = client.connection.get "projects/#{project.id}/members/all?per_page=100&page=#{page}&#{to_param_string(filters)}"
391
391
  handle_request_error(0, 'GitLab', response.status) unless response.status == 200
@@ -505,6 +505,41 @@ module Readiness
505
505
  handle_request_error(1, 'GitLab', response.status, { action: 'Delete badge', id: project.id }) unless response.status == 200
506
506
  true
507
507
  end
508
+
509
+ ##
510
+ # Lists all milestones in a project.
511
+ # This method can take a long time to run depending on the parameters used.
512
+ #
513
+ # @author Jason Colyer
514
+ # @since 1.0.12
515
+ # @param client [Object] An instance of {Readiness::GitLab::Client}
516
+ # @param project [Object] An instance of {Readiness::GitLab::Projects}
517
+ # @param filters [Array] An array of filter Strings to use. Should be in the format of key=value
518
+ # @return [Array]
519
+ # @see https://docs.gitlab.com/ee/api/milestones.html#list-project-milestones GitLab API > Projects > Milestones > List project milestones
520
+ # @example
521
+ # require 'support_readiness'
522
+ # config = Readiness::GitLab::Configuration.new
523
+ # config.token = 'test123abc'
524
+ # client = Readiness::GitLab::Client.new(config)
525
+ # project = Readiness::GitLab::Projects.find!(client, 1083469)
526
+ # milestones = Readiness::GitLab::Projects.milestones(client, project)
527
+ # pp milestones.count
528
+ # # => 25
529
+ def self.milestones(client, project, filters = [])
530
+ array = []
531
+ page = 0
532
+ loop do
533
+ response = client.connection.get "projects/#{project.id}/milestones?per_page=100&page=#{page}&#{to_param_string(filters)}"
534
+ handle_request_error(0, 'GitLab', response.status) unless response.status == 200
535
+ body = Oj.load(response.body)
536
+ array += body
537
+ break if body.count < 100
538
+
539
+ page += 1
540
+ end
541
+ array
542
+ end
508
543
  end
509
544
  end
510
545
  end
@@ -262,6 +262,180 @@ module Readiness
262
262
  handle_request_error(1, 'GitLab', response.status, { action: 'Update submodule in repo', id: "#{project.id}" }) unless response.status == 200
263
263
  Oj.load(response.body)
264
264
  end
265
+
266
+ ##
267
+ # Lists a repository's commits.
268
+ # This method can take a long time to run depending on the parameters used.
269
+ #
270
+ # @author Jason Colyer
271
+ # @since 1.0.12
272
+ # @param client [Object] An instance of {Readiness::GitLab::Client}
273
+ # @param project [Object] An instance of {Readiness::GitLab::Projects}
274
+ # @param filters [Array] An array of filter Strings to use. Should be in the format of key=value
275
+ # @return [Array]
276
+ # @see https://docs.gitlab.com/ee/api/commits.html#list-repository-commits GitLab API > Repositories > List repository commits
277
+ # @example
278
+ # require 'support_readiness'
279
+ # config = Readiness::GitLab::Configuration.new
280
+ # config.token = 'test123abc'
281
+ # client = Readiness::GitLab::Client.new(config)
282
+ # project = Readiness::GitLab::Projects.find!(client, 1083469)
283
+ # commits = Readiness::GitLab::Repositories.commits(client, project)
284
+ # pp commits.first['title']
285
+ # # => "Replace sanitize with escape once"
286
+ def self.commits(client, project, filters)
287
+ array = []
288
+ page = 0
289
+ loop do
290
+ response = client.connection.get "projects/#{project.id}/repository/commits?per_page=100&page=#{page}&#{to_param_string(filters)}"
291
+ handle_request_error(0, 'GitLab', response.status) unless response.status == 200
292
+ body = Oj.load(response.body)
293
+ array += body
294
+ break if body.count < 100
295
+
296
+ page += 1
297
+ end
298
+ array
299
+ end
300
+
301
+ ##
302
+ # Lists a repository's tags.
303
+ # This method can take a long time to run depending on the parameters used.
304
+ #
305
+ # @author Jason Colyer
306
+ # @since 1.0.12
307
+ # @param client [Object] An instance of {Readiness::GitLab::Client}
308
+ # @param project [Object] An instance of {Readiness::GitLab::Projects}
309
+ # @param filters [Array] An array of filter Strings to use. Should be in the format of key=value
310
+ # @return [Array]
311
+ # @see https://docs.gitlab.com/ee/api/tags.html#list-project-repository-tags GitLab API > Tags > List project repository tags
312
+ # @example
313
+ # require 'support_readiness'
314
+ # config = Readiness::GitLab::Configuration.new
315
+ # config.token = 'test123abc'
316
+ # client = Readiness::GitLab::Client.new(config)
317
+ # project = Readiness::GitLab::Projects.find!(client, 5)
318
+ # tags = Readiness::GitLab::Repositories.tags(client, project)
319
+ # pp tags.first['commit']['id']
320
+ # # => "2695effb5807a22ff3d138d593fd856244e155e7"
321
+ def self.tags(client, project, filters = [])
322
+ array = []
323
+ page = 1
324
+ loop do
325
+ response = client.connection.get "projects/#{project.id}/repository/tags?per_page=100&page=#{page}&#{to_param_string(filters)}"
326
+ handle_request_error(0, 'GitLab', response.status) unless response.status == 200
327
+ body = Oj.load(response.body)
328
+ array += body
329
+ break if body.count < 100
330
+
331
+ page += 1
332
+ end
333
+ array
334
+ end
335
+
336
+ ##
337
+ # Locates a repository tag. This will not exit on error (except Authentication errors)
338
+ #
339
+ # @author Jason Colyer
340
+ # @since 1.0.12
341
+ # @param client [Object] An instance of {Readiness::GitLab::Client}
342
+ # @param project [Object] An instance of {Readiness::GitLab::Projects}
343
+ # @param tag_name [String] The tag to find
344
+ # @return [Hash]
345
+ # @see https://docs.gitlab.com/ee/api/tags.html#get-a-single-repository-tag GitLab API > Tags > Get a single project repository tag
346
+ # @example
347
+ # require 'support_readiness'
348
+ # config = Readiness::GitLab::Configuration.new
349
+ # config.token = 'test123abc'
350
+ # client = Readiness::GitLab::Client.new(config)
351
+ # project = Readiness::GitLab::Projects.find!(client, 5)
352
+ # tag = Readiness::GitLab::Repositories.find_tag(client, project, 'v5.0.0')
353
+ # pp tag.['target']
354
+ # # => "60a8ff033665e1207714d6670fcd7b65304ec02f"
355
+ def self.find_tag(client, project, tag_name)
356
+ response = client.connection.get "projects/#{project.id}/repository/tags/#{tag_name}"
357
+ handle_request_error(0, 'GitLab', response.status, { action: 'get', id: "projects/#{project.id}/repository/tags/#{tag_name}" }) unless response.status == 200
358
+ Oj.load(response.body)
359
+ end
360
+
361
+ ##
362
+ # Locates a repository tag. This will exit on error
363
+ #
364
+ # @author Jason Colyer
365
+ # @since 1.0.12
366
+ # @param client [Object] An instance of {Readiness::GitLab::Client}
367
+ # @param project [Object] An instance of {Readiness::GitLab::Projects}
368
+ # @param tag_name [String] The tag to find
369
+ # @return [Hash]
370
+ # @see https://docs.gitlab.com/ee/api/tags.html#get-a-single-repository-tag GitLab API > Tags > Get a single project repository tag
371
+ # @example
372
+ # require 'support_readiness'
373
+ # config = Readiness::GitLab::Configuration.new
374
+ # config.token = 'test123abc'
375
+ # client = Readiness::GitLab::Client.new(config)
376
+ # project = Readiness::GitLab::Projects.find!(client, 5)
377
+ # tag = Readiness::GitLab::Repositories.find_tag!(client, project, 'v5.0.0')
378
+ # pp tag.['target']
379
+ # # => "60a8ff033665e1207714d6670fcd7b65304ec02f"
380
+ def self.find_tag!(client, project, tag_name)
381
+ response = client.connection.get("projects/#{project.id}/repository/tags/#{tag_name}")
382
+ handle_request_error(1, 'GitLab', response.status, { action: 'Find tag', id: "projects/#{project.id}/repository/tags/#{tag_name}" }) unless response.status == 200
383
+ Oj.load(response.body)
384
+ end
385
+
386
+ ##
387
+ # Creates a repository tag. This will exit on error
388
+ #
389
+ # @author Jason Colyer
390
+ # @since 1.0.12
391
+ # @param client [Object] An instance of {Readiness::GitLab::Client}
392
+ # @param project [Object] An instance of {Readiness::GitLab::Projects}
393
+ # @param tag [Hash] The Hash to use for the tag creation
394
+ # @return [Hash]
395
+ # @see https://docs.gitlab.com/ee/api/tags.html#create-a-new-tag GitLab API > Tags > Create a new tag
396
+ # @example
397
+ # require 'support_readiness'
398
+ # config = Readiness::GitLab::Configuration.new
399
+ # config.token = 'test123abc'
400
+ # client = Readiness::GitLab::Client.new(config)
401
+ # project = Readiness::GitLab::Projects.find!(client, 5)
402
+ # tag = {
403
+ # tag_name: 'test',
404
+ # ref: 'main'
405
+ # }
406
+ # create = Readiness::GitLab::Repositories.create_tag!(client, project, tag)
407
+ # pp create['target']
408
+ # # => "2695effb5807a22ff3d138d593fd856244e155e7"
409
+ def self.create_tag!(client, project, tag)
410
+ response = client.connection.post "projects/#{project.id}/repository/tags", tag.to_json
411
+ handle_request_error(1, 'GitLab', response.status, { action: 'Create tag', id: "projects/#{project.id}/repository/tags" }) unless response.status == 200
412
+ Oj.load(response.body)
413
+ end
414
+
415
+ ##
416
+ # Deletes a repository tag. This will exit on error
417
+ #
418
+ # @author Jason Colyer
419
+ # @since 1.0.12
420
+ # @param client [Object] An instance of {Readiness::GitLab::Client}
421
+ # @param project [Object] An instance of {Readiness::GitLab::Projects}
422
+ # @param tag_name [String] The name of the tag to delete
423
+ # @return [Boolean]
424
+ # @see https://docs.gitlab.com/ee/api/tags.html#delete-a-tag GitLab API > Tags > Delete a tag
425
+ # @example
426
+ # require 'support_readiness'
427
+ # config = Readiness::GitLab::Configuration.new
428
+ # config.token = 'test123abc'
429
+ # client = Readiness::GitLab::Client.new(config)
430
+ # project = Readiness::GitLab::Projects.find!(client, 5)
431
+ # delete = Readiness::GitLab::Repositories.create_tag!(client, project, 'test')
432
+ # pp delete
433
+ # # => true
434
+ def self.delete_tag!(client, project, tag_name)
435
+ response = client.connection.delete "projects/#{project.id}/repository/tags/#{tag_name}"
436
+ handle_request_error(1, 'GitLab', response.status, { action: 'Delete tag', id: "projects/#{project.id}/repository/tags/#{tag_name}" }) unless response.status == 200
437
+ true
438
+ end
265
439
  end
266
440
  end
267
441
  end
@@ -507,6 +507,30 @@ module Readiness
507
507
  handle_request_error(0, 'GitLab', response.status) unless response.status == 200
508
508
  Oj.load(response.body)
509
509
  end
510
+
511
+ ##
512
+ # Determines if a user is the only maintainer on projects they are within
513
+ #
514
+ # @author Jason Colyer
515
+ # @since 1.0.3
516
+ # @param client [Object] An instance of {Readiness::GitLab::Client}
517
+ # @param user [Object] An instance of {Readiness::GitLab::Users}
518
+ # @return [Boolean]
519
+ # @example
520
+ # require 'support_readiness'
521
+ # config = Readiness::GitLab::Configuration.new
522
+ # config.token = 'test123abc'
523
+ # client = Readiness::GitLab::Client.new(config)
524
+ # user = Readiness::GitLab::Users.find!(client, 5881867)
525
+ # pp Readiness::GitLab::Users.only_maintainer?(client, user)
526
+ # # => true
527
+ def self.only_maintainer?(client, user)
528
+ Users.projects(client, user).each do |p|
529
+ members = Projects.all_members(client, p)
530
+ return true if members = members.select { |m| m['access_level'] >= 40 && m['username'] != user.username }.count.zero?
531
+ end
532
+ false
533
+ end
510
534
  end
511
535
  end
512
536
  end
@@ -11,6 +11,8 @@ module Readiness
11
11
  require "#{__dir__}/gitlab/configuration"
12
12
  require "#{__dir__}/gitlab/groups"
13
13
  require "#{__dir__}/gitlab/issues"
14
+ require "#{__dir__}/gitlab/markdown"
15
+ require "#{__dir__}/gitlab/merge_requests"
14
16
  require "#{__dir__}/gitlab/namespaces"
15
17
  require "#{__dir__}/gitlab/projects"
16
18
  require "#{__dir__}/gitlab/repositories"
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Defines the module Readiness.
4
+ module Readiness
5
+ ##
6
+ # Defines the module GoogleCalendar
7
+ module GoogleCalendar
8
+ ##
9
+ # Defines the class Client within the module {Readiness::GoogleCalendar}.
10
+ #
11
+ # @author Jason Colyer
12
+ # @since 1.0.12
13
+ class Client
14
+ attr_accessor :calendar_id, :service
15
+
16
+ ##
17
+ # Creates a new {Readiness::GoogleCalendar::Client} instance
18
+ #
19
+ # @author Jason Colyer
20
+ # @since 1.0.12
21
+ # @param config [Object] An instance of {Readiness::GoogleCalendar::Configuration}
22
+ # @example
23
+ # require 'support_readiness'
24
+ # config = Readiness::GoogleCalendar::Configuration.new
25
+ # config.calendar_id = 'abc123'
26
+ # config.filepath = 'data/config.json'
27
+ # client = Readiness::GoogleCalendar::Client.new(config)
28
+ # pp client.calendar_id
29
+ # # => "abc123"
30
+ def initialize(config = Readiness::GoogleCalendar::Configuration.new)
31
+ @service = generate_service(config)
32
+ @calendar_id = config.calendar_id
33
+ end
34
+
35
+ ##
36
+ # Generates a service connection to Google Calendar
37
+ #
38
+ # @author Jason Colyer
39
+ # @since 1.0.12
40
+ # @param config [Object] An instance of {Readiness::GoogleCalendar::Configuration}
41
+ # @example
42
+ # require 'support_readiness'
43
+ # config = Readiness::GoogleCalendar::Configuration.new
44
+ # config.calendar_id = 'abc123'
45
+ # config.filepath = 'data/config.json'
46
+ # service = Readiness::GoogleCalendar::Client.generate_service(config)
47
+ def generate_service(config)
48
+ authorize = Google::Auth::ServiceAccountCredentials.make_creds(
49
+ json_key_io: File.open(config.filepath),
50
+ scope: config.scope
51
+ )
52
+ authorize.fetch_access_token!
53
+ service = Google::Apis::CalendarV3::CalendarService.new
54
+ service.authorization = authorize
55
+ service
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Defines the module Readiness.
4
+ module Readiness
5
+ ##
6
+ # Defines the module GoogleCalendar
7
+ module GoogleCalendar
8
+ ##
9
+ # Defines the class Configuration within the module {Readiness::GoogleCalendar}.
10
+ #
11
+ # @author Jason Colyer
12
+ # @since 1.0.12
13
+ class Configuration
14
+ attr_accessor :calendar_id, :filepath, :scope
15
+
16
+ ##
17
+ # Creates a new {Readiness::GoogleCalendar::Configuration} instance
18
+ #
19
+ # @author Jason Colyer
20
+ # @since 1.0.12
21
+ # @example
22
+ # require 'support_readiness'
23
+ # config = Readiness::GoogleCalendar::Configuration.new
24
+ # config.calendar_id = 'abc123'
25
+ # config.filepath = 'data/config.json'
26
+ # pp config
27
+ # # => #<Readiness::GoogleCalendar::Configuration:0x00007f352fdd1420
28
+ # @calendar_id="abc123"
29
+ # @filepath="data/config.json"
30
+ # @scope="https://www.googleapis.com/auth/calendar">
31
+ def initialize
32
+ # /home/jason/dev/gitlab-support-readiness/zendesk-us-government/tickets/round-robin/lib/round_robin
33
+ @calendar_id = ''
34
+ @filepath = ''
35
+ @scope = 'https://www.googleapis.com/auth/calendar'
36
+ end
37
+ end
38
+ end
39
+ end