gitlab_support_readiness 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +7 -0
  2. data/lib/support_readiness/client.rb +108 -0
  3. data/lib/support_readiness/gitlab/client.rb +64 -0
  4. data/lib/support_readiness/gitlab/configuration.rb +46 -0
  5. data/lib/support_readiness/gitlab/groups.rb +180 -0
  6. data/lib/support_readiness/gitlab/issues.rb +410 -0
  7. data/lib/support_readiness/gitlab/namespaces.rb +190 -0
  8. data/lib/support_readiness/gitlab/projects.rb +510 -0
  9. data/lib/support_readiness/gitlab/repositories.rb +267 -0
  10. data/lib/support_readiness/gitlab/users.rb +488 -0
  11. data/lib/support_readiness/gitlab.rb +19 -0
  12. data/lib/support_readiness/pagerduty/client.rb +66 -0
  13. data/lib/support_readiness/pagerduty/configuration.rb +43 -0
  14. data/lib/support_readiness/pagerduty/escalation_policies.rb +123 -0
  15. data/lib/support_readiness/pagerduty/schedules.rb +223 -0
  16. data/lib/support_readiness/pagerduty/services.rb +132 -0
  17. data/lib/support_readiness/pagerduty.rb +16 -0
  18. data/lib/support_readiness/redis.rb +90 -0
  19. data/lib/support_readiness/zendesk/articles.rb +210 -0
  20. data/lib/support_readiness/zendesk/automations.rb +304 -0
  21. data/lib/support_readiness/zendesk/client.rb +84 -0
  22. data/lib/support_readiness/zendesk/configuration.rb +49 -0
  23. data/lib/support_readiness/zendesk/group_memberships.rb +256 -0
  24. data/lib/support_readiness/zendesk/groups.rb +249 -0
  25. data/lib/support_readiness/zendesk/job_statuses.rb +188 -0
  26. data/lib/support_readiness/zendesk/macros.rb +267 -0
  27. data/lib/support_readiness/zendesk/organization_fields.rb +233 -0
  28. data/lib/support_readiness/zendesk/organization_memberships.rb +257 -0
  29. data/lib/support_readiness/zendesk/organizations.rb +515 -0
  30. data/lib/support_readiness/zendesk/roles.rb +194 -0
  31. data/lib/support_readiness/zendesk/search.rb +159 -0
  32. data/lib/support_readiness/zendesk/sla_policies.rb +232 -0
  33. data/lib/support_readiness/zendesk/ticket_fields.rb +222 -0
  34. data/lib/support_readiness/zendesk/ticket_forms.rb +290 -0
  35. data/lib/support_readiness/zendesk/tickets.rb +854 -0
  36. data/lib/support_readiness/zendesk/triggers.rb +269 -0
  37. data/lib/support_readiness/zendesk/users.rb +946 -0
  38. data/lib/support_readiness/zendesk/views.rb +469 -0
  39. data/lib/support_readiness/zendesk.rb +31 -0
  40. data/lib/support_readiness.rb +29 -0
  41. metadata +215 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a0e81abed456cb750b54dcdcef581f933c1b27e906353c1cb12fde4d70d5ccb0
4
+ data.tar.gz: 367d670acb747d15d574e13850e250c95acb6a99faf43e9f38e0345803845833
5
+ SHA512:
6
+ metadata.gz: ebaa805e5fec5fd2c9df475e00af09c548fcdeca8d571ffb548e93ef22f8a121672445532ad84d1abfab049e17d78f7ac9b41515d0dce206a5c6f2ceab599eb9
7
+ data.tar.gz: e710ac16335bf813d780446fdbc7cfc8a95f2b0e62165b62f7e381aa9c09112eef36b7281c03cdf490db93df55119a44225d633daf6fbf9893427697801b936c
@@ -0,0 +1,108 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Defines the module Readiness.
4
+ module Readiness
5
+ ##
6
+ # Defines the class Client within the module {Readiness}.
7
+ #
8
+ # @author Jason Colyer
9
+ # @since 1.0.0
10
+ class Client
11
+ def self.to_param_string(parms)
12
+ return '' if parms.count.zero?
13
+
14
+ "#{parms.join('&')}"
15
+ end
16
+ ##
17
+ # Converts an Object to a Hash
18
+ #
19
+ # @author Jason Colyer
20
+ # @since 1.0.0
21
+ # @param object [Object]
22
+ # @return [Hash]
23
+ def self.to_hash(object)
24
+ Hash[object.instance_variables.map { |name| [name.to_s[1..-1], object.instance_variable_get(name)] }]
25
+ end
26
+
27
+ ##
28
+ # Converts an Object to a JSON String, removing nil values
29
+ #
30
+ # @author Jason Colyer
31
+ # @since 1.0.0
32
+ # @param object [Object]
33
+ # @return [String]
34
+ def self.to_clean_json(object)
35
+ hash = to_hash(object).compact
36
+ hash.to_json
37
+ end
38
+
39
+ ##
40
+ # Converts an Object to a JSON String with a leading key, removing nil values
41
+ #
42
+ # @author Jason Colyer
43
+ # @since 1.0.0
44
+ # @param object [Object]
45
+ # @param key [String]
46
+ # @return [String]
47
+ def self.to_clean_json_with_key(object, key)
48
+ hash = { "#{key}": to_hash(object).compact }
49
+ hash.to_json
50
+ end
51
+
52
+ ##
53
+ # Handles error occurred from making Faraday requests
54
+ #
55
+ # @author Jason Colyer
56
+ # @since 1.0.0
57
+ def self.handle_request_error(type, system, code, params = {})
58
+ auth_error(system) if code == 401 || code == 403
59
+ if type == 1
60
+ bad_request_error(system, params) if code == 400
61
+ not_found_error(system, params) if code == 404
62
+ not_processible_error(system, params) if code == 422
63
+ end
64
+ end
65
+
66
+ ##
67
+ # Handles 404 Not found errors from making Faraday requests.
68
+ #
69
+ # @author Jason Colyer
70
+ # @since 1.0.0
71
+ # @param system [String] The system the error occurred on
72
+ # @param params [Hash] A Hash of information about the request
73
+ def self.not_found_error(system, params)
74
+ puts "Action '#{params[:action]}' to ID #{params[:id]} on #{system} returned a 404 error"
75
+ exit 1
76
+ end
77
+
78
+ ##
79
+ # Handles authentication errors from making Faraday requests.
80
+ #
81
+ # @author Jason Colyer
82
+ # @since 1.0.0
83
+ # @param system [String] The system the error occurred on
84
+ def self.auth_error(system)
85
+ puts "Unable to authenticate to #{system}. Check your configuration and try again."
86
+ exit 1
87
+ end
88
+
89
+ def self.bad_request_error(system, params)
90
+ pp system
91
+ pp params
92
+ exit 1
93
+ end
94
+
95
+ ##
96
+ # Handles Unprocessable Content errors from making Faraday requests.
97
+ #
98
+ # @author Jason Colyer
99
+ # @since 1.0.0
100
+ # @param system [String] The system the error occurred on
101
+ # @param params [Hash] A Hash of information about the request
102
+ def self.not_processible_error(system, params)
103
+ puts "Unable to '#{params[:action]}' on #{system}, as it returned the message:"
104
+ pp params[:message]
105
+ exit 1
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,64 @@
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 Client within the module {Readiness::GitLab}.
9
+ #
10
+ # @author Jason Colyer
11
+ # @since 1.0.0
12
+ class Client
13
+ attr_reader :connection, :upload_connection
14
+
15
+ ##
16
+ # Creates a new {Readiness::GitLab::Client} instance
17
+ #
18
+ # @author Jason Colyer
19
+ # @since 1.0.0
20
+ # @param config [Object] An instance of {Readiness::GitLab::Configuration}
21
+ # @example
22
+ # require 'support_readiness'
23
+ # config = Readiness::GitLab::Configuration.new
24
+ # config.token = 'test123abc'
25
+ # client = Readiness::GitLab::Client.new(config)
26
+ def initialize(config = Readiness::GitLab::Configuration.new)
27
+ @connection = generate_connection(config)
28
+ end
29
+
30
+ ##
31
+ # Used to generate the retry options passed to Faraday via faraday-retry
32
+ #
33
+ # @author Jason Colyer
34
+ # @since 1.0.0
35
+ # @param config [Object] An instance of {Readiness::GitLab::Configuration}
36
+ # @return [Hash]
37
+ def retry_options(config)
38
+ {
39
+ max: config.retry_max,
40
+ interval: config.retry_interval,
41
+ interval_randomness: config.retry_randomness,
42
+ backoff_factor: config.retry_backoff,
43
+ exceptions: config.retry_exceptions
44
+ }
45
+ end
46
+
47
+ ##
48
+ # Used to generate a Faraday connection
49
+ #
50
+ # @author Jason Colyer
51
+ # @since 1.0.0
52
+ # @param config [Object] An instance of {Readiness::GitLab::Configuration}
53
+ # @return [Object]
54
+ def generate_connection(config)
55
+ Faraday.new(config.url) do |c|
56
+ c.request :retry, retry_options(config)
57
+ c.adapter Faraday.default_adapter
58
+ c.headers['Content-Type'] = 'application/json'
59
+ c.headers['Authorization'] = "Bearer #{config.token}"
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,46 @@
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 Configuration within the module {Readiness::GitLab}.
9
+ #
10
+ # @author Jason Colyer
11
+ # @since 1.0.0
12
+ class Configuration
13
+ attr_accessor :url, :token, :retry_options, :retry_max, :retry_interval, :retry_randomness, :retry_backoff, :retry_exceptions
14
+
15
+ ##
16
+ # Creates a new {Readiness::GitLab::Configuration} instance
17
+ #
18
+ # @author Jason Colyer
19
+ # @since 1.0.0
20
+ # @example
21
+ # require 'support_readiness'
22
+ # config = Readiness::GitLab::Configuration.new
23
+ # config.token = 'test123abc'
24
+ # pp config
25
+ # # => #<Readiness::GitLab::Configuration:0x00007f352fdd1420
26
+ # @retry_backoff=2,
27
+ # @retry_exceptions=
28
+ # [Errno::ETIMEDOUT, "Timeout::Error", Faraday::TimeoutError, Faraday::RetriableResponse, Faraday::ConnectionFailed],
29
+ # @retry_interval=1,
30
+ # @retry_max=5,
31
+ # @retry_randomness=0.5,
32
+ # @token="test123abc",
33
+ # @url="https://gitlab.com/api/v4">
34
+
35
+ def initialize
36
+ @url = 'https://gitlab.com/api/v4'
37
+ @token = ''
38
+ @retry_max = 5
39
+ @retry_interval = 1
40
+ @retry_randomness = 0.5
41
+ @retry_backoff = 2
42
+ @retry_exceptions = Faraday::Retry::Middleware::DEFAULT_EXCEPTIONS + [Faraday::ConnectionFailed]
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,180 @@
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 Groups 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/groups.html not currently here
13
+ class Groups < Readiness::Client
14
+ attr_accessor :allowed_email_domains_list, :auto_devops_enabled, :avatar_url, :default_branch, :default_branch_protection, :default_branch_protection_defaults, :description, :duo_features_enabled, :emails_disabled, :emails_enabled, :extra_shared_runners_minutes_limit, :full_name, :full_path, :id, :ip_restriction_ranges, :ldap_access, :ldap_cn, :lfs_enabled, :lock_duo_features_enabled, :lock_math_rendering_limits_enabled, :marked_for_deletion_on, :math_rendering_limits_enabled, :membership_lock, :mentions_disabled, :name, :organization_id, :parent_id, :path, :prevent_forking_outside_group, :project_creation_level, :repository_storage, :request_access_enabled, :require_two_factor_authentication, :runners_token, :shared_runners_minutes_limit, :shared_runners_setting, :shared_with_groups, :share_with_group_lock, :subgroup_creation_level, :two_factor_grace_period, :visibility, :web_url, :wiki_access_level
15
+
16
+ ##
17
+ # Creates a new {Readiness::GitLab::Groups} instance
18
+ #
19
+ # @author Jason Colyer
20
+ # @since 1.0.0
21
+ # @param object [Object] An instance of {Readiness::GitLab::Groups}
22
+ # @example
23
+ # require 'support_readiness'
24
+ # group = Readiness::GitLab::Groups.new
25
+ def initialize(object = {})
26
+ @allowed_email_domains_list = object['allowed_email_domains_list']
27
+ @auto_devops_enabled = object['auto_devops_enabled']
28
+ @avatar_url = object['avatar_url']
29
+ @default_branch = object['default_branch']
30
+ @default_branch_protection = object['default_branch_protection']
31
+ @default_branch_protection_defaults = object['default_branch_protection_defaults']
32
+ @description = object['description']
33
+ @duo_features_enabled = object['duo_features_enabled']
34
+ @emails_disabled = object['emails_disabled']
35
+ @emails_enabled = object['emails_enabled']
36
+ @extra_shared_runners_minutes_limit = object['extra_shared_runners_minutes_limit']
37
+ @full_name = object['full_name']
38
+ @full_path = object['full_path']
39
+ @id = object['id']
40
+ @ip_restriction_ranges = object['ip_restriction_ranges']
41
+ @ldap_access = object['ldap_access']
42
+ @ldap_cn = object['ldap_cn']
43
+ @lfs_enabled = object['lfs_enabled']
44
+ @lock_duo_features_enabled = object['lock_duo_features_enabled']
45
+ @lock_math_rendering_limits_enabled = object['lock_math_rendering_limits_enabled']
46
+ @marked_for_deletion_on = object['marked_for_deletion_on']
47
+ @math_rendering_limits_enabled = object['math_rendering_limits_enabled']
48
+ @membership_lock = object['membership_lock']
49
+ @mentions_disabled = object['mentions_disabled']
50
+ @name = object['name']
51
+ @organization_id = object['organization_id']
52
+ @parent_id = object['parent_id']
53
+ @path = object['path']
54
+ @prevent_forking_outside_group = object['prevent_forking_outside_group']
55
+ @project_creation_level = object['project_creation_level']
56
+ @repository_storage = object['repository_storage']
57
+ @request_access_enabled = object['request_access_enabled']
58
+ @require_two_factor_authentication = object['require_two_factor_authentication']
59
+ @runners_token = object['runners_token']
60
+ @shared_runners_minutes_limit = object['shared_runners_minutes_limit']
61
+ @shared_runners_setting = object['shared_runners_setting']
62
+ @shared_with_groups = object['shared_with_groups']
63
+ @share_with_group_lock = object['share_with_group_lock']
64
+ @subgroup_creation_level = object['subgroup_creation_level']
65
+ @two_factor_grace_period = object['two_factor_grace_period']
66
+ @visibility = object['visibility']
67
+ @web_url = object['web_url']
68
+ @wiki_access_level = object['wiki_access_level']
69
+ end
70
+
71
+ ##
72
+ # Lists projects in a group.
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 group [Object] An instance of {Readiness::GitLab::Groups}
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/groups.html#list-a-groups-projects GitLab API > GRoups > List a group's projects
82
+ # @example
83
+ # require 'support_readiness'
84
+ # config = Readiness::GitLab::Configuration.new
85
+ # config.token = 'test123abc'
86
+ # client = Readiness::GitLab::Client.new(config)
87
+ # group = Readiness::GitLab::Groups.new
88
+ # group.id = 1
89
+ # projects = Readiness::GitLab::Groups.projects(client, group, ["archived=false", "include_subgroups=true"])
90
+ # puts projects.first.web_url
91
+ # # => "https://gitlab.com/gitlab-com/support/support-team-meta"
92
+ def self.projects(client, group, filters = [])
93
+ array = []
94
+ page = 1
95
+ loop do
96
+ response = client.connection.get "groups/#{group.id}/projects?per_page=100&page=#{page}&#{to_param_string(filters)}"
97
+ handle_request_error(0, 'GitLab', response.status) unless response.status == 200
98
+ body = Oj.load(response.body)
99
+ array += body.map { |p| Projects.new(p) }
100
+ break if body.count < 100
101
+
102
+ page += 1
103
+ end
104
+ array
105
+ end
106
+
107
+ ##
108
+ # Lists direct members in a group.
109
+ # This method can take a long time to run depending on the parameters used.
110
+ #
111
+ # @author Jason Colyer
112
+ # @since 1.0.0
113
+ # @param client [Object] An instance of {Readiness::GitLab::Client}
114
+ # @param group [Object] An instance of {Readiness::GitLab::Groups}
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/members.html#list-all-members-of-a-group-or-project GitLab API > Members > List all members of a group or project
118
+ # @example
119
+ # require 'support_readiness'
120
+ # config = Readiness::GitLab::Configuration.new
121
+ # config.token = 'test123abc'
122
+ # client = Readiness::GitLab::Client.new(config)
123
+ # group = Readiness::GitLab::Groups.new
124
+ # group.id = 1
125
+ # members = Readiness::GitLab::Groups.members(client, group, ["query=jcolyer"])
126
+ # puts members.first['username']
127
+ # # => "jcolyer-123"
128
+ def self.members(client, group, filters = [])
129
+ array = []
130
+ page = 1
131
+ loop do
132
+ response = client.connection.get "groups/#{group.id}/members?per_page=100&page=#{page}&#{to_param_string(filters)}"
133
+ handle_request_error(0, 'GitLab', response.status) unless response.status == 200
134
+ body = Oj.load(response.body)
135
+ array += body
136
+ break if body.count < 100
137
+
138
+ page += 1
139
+ end
140
+ array
141
+ end
142
+
143
+ ##
144
+ # Lists all members in a group.
145
+ # This method can take a long time to run depending on the parameters used.
146
+ #
147
+ # @author Jason Colyer
148
+ # @since 1.0.0
149
+ # @param client [Object] An instance of {Readiness::GitLab::Client}
150
+ # @param group [Object] An instance of {Readiness::GitLab::Groups}
151
+ # @param filters [Array] An array of filter Strings to use. Should be in the format of key=value
152
+ # @return [Array]
153
+ # @see https://docs.gitlab.com/ee/api/members.html#list-all-members-of-a-group-or-project-including-inherited-and-invited-members GitLab API > Members > List all members of a group or project including inherited and invited members
154
+ # @example
155
+ # require 'support_readiness'
156
+ # config = Readiness::GitLab::Configuration.new
157
+ # config.token = 'test123abc'
158
+ # client = Readiness::GitLab::Client.new(config)
159
+ # group = Readiness::GitLab::Groups.new
160
+ # group.id = 1
161
+ # members = Readiness::GitLab::Groups.all_members(client, group, ["query=jcolyer"])
162
+ # puts members.first['username']
163
+ # # => "jcolyer"
164
+ def self.all_members(client, group, filters = [])
165
+ array = []
166
+ page = 1
167
+ loop do
168
+ response = client.connection.get "groups/#{group.id}/members/all?per_page=100&page=#{page}&#{to_param_string(filters)}"
169
+ handle_request_error(0, 'GitLab', response.status) unless response.status == 200
170
+ body = Oj.load(response.body)
171
+ array += body
172
+ break if body.count < 100
173
+
174
+ page += 1
175
+ end
176
+ array
177
+ end
178
+ end
179
+ end
180
+ end