gitlab_support_readiness 1.0.73 → 1.0.75
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b5a9270d4b584057c87945a396c53986f418b93ef85cfbe2570303042f29b511
|
4
|
+
data.tar.gz: 2267d9e98eef359457e9ee4c77ea5c278d80fbbc4773e48022cb2f35ac4de877
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9b8619ea9ba4a9a1e1e5e93b8973478fc4ded297df66703d248d1390b5f49f3b319d0c051629b9256643d753184d89379a3f5ab9b4e7d072f276d8de075279b8
|
7
|
+
data.tar.gz: da9274ea65b7295ae8e4d1af540f6e609b677318b68254a40b3d768d29f8317a9be0d6819695553c707ac5a50d004851b8ccb17c108fe248d367bfc9e762c946
|
@@ -0,0 +1,249 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Defines the module Readiness.
|
4
|
+
module Readiness
|
5
|
+
# Defines the module Repos
|
6
|
+
module Repos
|
7
|
+
##
|
8
|
+
# Defines the class DynamicContent within the module {Readiness::Repos}.
|
9
|
+
#
|
10
|
+
# @author Jason Colyer
|
11
|
+
# @since 1.0.74
|
12
|
+
class DynamicContent < Readiness::Client
|
13
|
+
##
|
14
|
+
# Compares the repo dynamic content files to the Zendesk instance dynamic content
|
15
|
+
#
|
16
|
+
# @author Jason Colyer
|
17
|
+
# @since 1.0.74
|
18
|
+
# @param zendesk_client [Object] An instance of {Readiness::Zendesk::Client}
|
19
|
+
# @param location [String] The location (relative or absolute) of the repo's data folder
|
20
|
+
# @param verbose [Boolean] Whether you want a detailed report or not
|
21
|
+
# @return [Hash]
|
22
|
+
def self.compare(zendesk_client, location = 'data', verbose = false)
|
23
|
+
@locales = Zendesk::Locales.list(zendesk_client)
|
24
|
+
@from_repo = gather(location)
|
25
|
+
@from_zendesk = Zendesk::DynamicContent.list(zendesk_client)
|
26
|
+
@diffs = {
|
27
|
+
item_creates: [],
|
28
|
+
item_updates: [],
|
29
|
+
variant_creates: [],
|
30
|
+
variant_updates: [],
|
31
|
+
variant_deletes: []
|
32
|
+
}
|
33
|
+
@from_repo.each do |repo|
|
34
|
+
zd = @from_zendesk.detect { |z| z.name == repo[:item].name }
|
35
|
+
if zd.nil?
|
36
|
+
@diffs[:item_creates].push(repo[:item])
|
37
|
+
repo[:variants].each do |v|
|
38
|
+
object = {
|
39
|
+
item: repo[:item].name,
|
40
|
+
variant: v
|
41
|
+
}
|
42
|
+
@diffs[:variant_creates].push(object)
|
43
|
+
end
|
44
|
+
else
|
45
|
+
comparable_zd = zd.dup
|
46
|
+
comparable_zd.id = nil
|
47
|
+
comparable_zd.outdated = nil
|
48
|
+
if to_clean_json(comparable_zd) != to_clean_json(repo[:item])
|
49
|
+
@diffs[:item_updates].push(item_update_object(repo[:item], zd))
|
50
|
+
detailed_diff(repo[:item], comparable_zd) if verbose
|
51
|
+
end
|
52
|
+
zd_variants = Readiness::Zendesk::DynamicContent.variants(zendesk_client, zd)
|
53
|
+
repo[:variants].each do |v|
|
54
|
+
zd_variant = zd_variants.detect { |z| z.locale_id == v.locale_id }
|
55
|
+
if zd_variant.nil?
|
56
|
+
object = {
|
57
|
+
item: repo[:item].name,
|
58
|
+
variant: v
|
59
|
+
}
|
60
|
+
@diffs[:variant_creates].push(object)
|
61
|
+
else
|
62
|
+
comparable_zd_variant = zd_variant.dup
|
63
|
+
comparable_zd_variant.id = nil
|
64
|
+
comparable_zd_variant.outdated = nil
|
65
|
+
if to_clean_json(comparable_zd_variant) != to_clean_json(v)
|
66
|
+
@diffs[:variant_updates].push(variant_update_object(repo[:item], v, zd_variant))
|
67
|
+
detailed_variant_diff(repo[:item], v, comparable_zd_variant) if verbose
|
68
|
+
end
|
69
|
+
end
|
70
|
+
zd_variants.each do |z|
|
71
|
+
unless repo[:variants].map { |v| v.locale_id }.include? z.locale_id
|
72
|
+
object = {
|
73
|
+
item: repo[:item].name,
|
74
|
+
variant: z
|
75
|
+
}
|
76
|
+
@diffs[:variant_deletes].push(object)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
report_diffs if verbose
|
83
|
+
@diffs
|
84
|
+
end
|
85
|
+
|
86
|
+
##
|
87
|
+
# Outputs a comparison report
|
88
|
+
#
|
89
|
+
# @author Jason Colyer
|
90
|
+
# @since 1.0.74
|
91
|
+
def self.report_diffs
|
92
|
+
puts 'Compare report:'
|
93
|
+
puts "- Item Creates: #{@diffs[:item_creates].count}"
|
94
|
+
puts "- Item Updates: #{@diffs[:item_updates].count}"
|
95
|
+
puts "- Variant Creates: #{@diffs[:variant_creates].count}"
|
96
|
+
puts "- Variant Updates: #{@diffs[:variant_updates].count}"
|
97
|
+
puts "- Variant Deletes: #{@diffs[:variant_deletes].count}"
|
98
|
+
end
|
99
|
+
|
100
|
+
##
|
101
|
+
# Outputs a detailed comparison report
|
102
|
+
#
|
103
|
+
# @author Jason Colyer
|
104
|
+
# @since 1.0.74
|
105
|
+
# @param repo [Object] An instance of {Readiness::Zendesk::DynamicContent}
|
106
|
+
# @param zendesk [Object] An instance of {Readiness::Zendesk::DynamicContent}
|
107
|
+
def self.detailed_diff(repo, zendesk)
|
108
|
+
puts "Detailed diff of #{repo.name}"
|
109
|
+
repo.instance_variables.each do |v|
|
110
|
+
next if v == :@id
|
111
|
+
|
112
|
+
if repo.instance_variable_get(v) != zendesk.instance_variable_get(v)
|
113
|
+
puts "- #{v} Repo:"
|
114
|
+
pp repo.instance_variable_get(v)
|
115
|
+
puts " #{v} Zendesk:"
|
116
|
+
pp zendesk.instance_variable_get(v)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
##
|
122
|
+
# Outputs a detailed comparison report
|
123
|
+
#
|
124
|
+
# @author Jason Colyer
|
125
|
+
# @since 1.0.74
|
126
|
+
# @param item [Object] An instance of {Readiness::Zendesk::DynamicContent}
|
127
|
+
# @param repo [Object] An instance of {Readiness::Zendesk::DynamicContentVariants}
|
128
|
+
# @param zendesk [Object] An instance of {Readiness::Zendesk::DynamicContentVariants}
|
129
|
+
def self.detailed_variant_diff(item, repo, zendesk)
|
130
|
+
puts "Detailed diff of variant for '#{item.name}' with locale ID #{repo.locale_id}"
|
131
|
+
repo.instance_variables.each do |v|
|
132
|
+
next if v == :@id
|
133
|
+
|
134
|
+
if repo.instance_variable_get(v) != zendesk.instance_variable_get(v)
|
135
|
+
puts "- #{v} Repo:"
|
136
|
+
pp repo.instance_variable_get(v)
|
137
|
+
puts " #{v} Zendesk:"
|
138
|
+
pp zendesk.instance_variable_get(v)
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
##
|
144
|
+
# Creates an instance of {Readiness::Zendesk::DynamicContent} to use for updates
|
145
|
+
#
|
146
|
+
# @author Jason Colyer
|
147
|
+
# @since 1.0.74
|
148
|
+
# @param repo [Object] An instance of {Readiness::Zendesk::DynamicContent}
|
149
|
+
# @param zendesk [Object] An instance of {Readiness::Zendesk::DynamicContent}
|
150
|
+
# @return [Object]
|
151
|
+
def self.item_update_object(repo, zendesk)
|
152
|
+
object = repo
|
153
|
+
object.id = zendesk.id
|
154
|
+
object
|
155
|
+
end
|
156
|
+
|
157
|
+
##
|
158
|
+
# Creates a Hash to use for updates
|
159
|
+
#
|
160
|
+
# @author Jason Colyer
|
161
|
+
# @since 1.0.74
|
162
|
+
# @param item [Object] An instance of {Readiness::Zendesk::DynamicContent}
|
163
|
+
# @param repo [Object] An instance of {Readiness::Zendesk::DynamicContentVariants}
|
164
|
+
# @param zendesk [Object] An instance of {Readiness::Zendesk::DynamicContentVariants}
|
165
|
+
# @return [Hash]
|
166
|
+
def self.variant_update_object(item, repo, zendesk)
|
167
|
+
object = {
|
168
|
+
item: item.name,
|
169
|
+
variant: repo
|
170
|
+
}
|
171
|
+
object[:variant].id = zendesk.id
|
172
|
+
object
|
173
|
+
end
|
174
|
+
|
175
|
+
##
|
176
|
+
# Parses repo user field files
|
177
|
+
#
|
178
|
+
# @author Jason Colyer
|
179
|
+
# @since 1.0.74
|
180
|
+
# @param location [String] The location (relative or absolute) of the repo's data folder
|
181
|
+
# @return [Array]
|
182
|
+
# @example
|
183
|
+
# require 'support_readiness'
|
184
|
+
# config = Readiness::Zendesk::Configuration.new
|
185
|
+
# config.username = 'alice@example.com'
|
186
|
+
# config.token = 'test123abc'
|
187
|
+
# config.url = 'https://example.zendesk.com/api/v2'
|
188
|
+
# client = Readiness::Zendesk::Client.new(config)
|
189
|
+
# repo = Readiness::Repos::DynamicContent.gather('data')
|
190
|
+
# pp repo.count
|
191
|
+
# # => 2
|
192
|
+
def self.gather(location)
|
193
|
+
@errors = []
|
194
|
+
@location = location
|
195
|
+
array = []
|
196
|
+
Dir["#{@location}/*.yaml"].each do |f|
|
197
|
+
object = YAML.safe_load_file(f)
|
198
|
+
data = {
|
199
|
+
item: Zendesk::DynamicContent.new(object),
|
200
|
+
variants: object['variants'].map { |v| Zendesk::DynamicContentVariants.new(v) }
|
201
|
+
}
|
202
|
+
array.push(data)
|
203
|
+
end
|
204
|
+
repo_check(array)
|
205
|
+
report_errors unless @errors.count.zero?
|
206
|
+
array
|
207
|
+
end
|
208
|
+
|
209
|
+
##
|
210
|
+
# Outputs an error report and exits with a status code of 1
|
211
|
+
#
|
212
|
+
# @author Jason Colyer
|
213
|
+
# @since 1.0.74
|
214
|
+
def self.report_errors
|
215
|
+
puts 'The following errors were found in the repo files:'
|
216
|
+
@errors.each do |e|
|
217
|
+
puts "- #{e}"
|
218
|
+
end
|
219
|
+
puts 'Rectify the errors and retry. We cannot proceed with those errors occurring.'
|
220
|
+
exit 1
|
221
|
+
end
|
222
|
+
|
223
|
+
##
|
224
|
+
# Performs basic checks on the repo
|
225
|
+
#
|
226
|
+
# @author Jason Colyer
|
227
|
+
# @since 1.0.74
|
228
|
+
# @param objects [Array] The Array of Hashes derived from parsing the repo files
|
229
|
+
def self.repo_check(objects)
|
230
|
+
duplicate_names = objects.map { |o| o[:item] }.group_by { |o| o.name }.select { |k, v| v.size > 1 }.map(&:first)
|
231
|
+
unless duplicate_names.count.zero?
|
232
|
+
duplicate_names.each do |d|
|
233
|
+
@errors.push("The item '#{d}' is used in multiple files")
|
234
|
+
end
|
235
|
+
end
|
236
|
+
objects.select { |o| o[:variants].count.zero? }.each do |o|
|
237
|
+
@errors.push("The item '#{o[:item].name}' has no variants")
|
238
|
+
end
|
239
|
+
objects.each do |o|
|
240
|
+
@errors.push("Bad default locale id for the item '#{o[:item].name}'") unless @locales.map { |l| l.id }.include? o[:item].default_locale_id
|
241
|
+
@errors.push("The item '#{o[:item].name}' has no default variant") unless o[:variants].detect { |v| v.default }
|
242
|
+
o[:variants].each_with_index do |v, i|
|
243
|
+
@errors.push("Variant #{i + 1} on item '#{o[:item].name}' has a bad locale") unless @locales.map { |l| l.id }.include? v.locale_id
|
244
|
+
end
|
245
|
+
end
|
246
|
+
end
|
247
|
+
end
|
248
|
+
end
|
249
|
+
end
|
@@ -9,6 +9,7 @@ module Readiness
|
|
9
9
|
module Repos
|
10
10
|
require "#{__dir__}/repos/articles"
|
11
11
|
require "#{__dir__}/repos/automations"
|
12
|
+
require "#{__dir__}/repos/dynamic_content"
|
12
13
|
require "#{__dir__}/repos/groups"
|
13
14
|
require "#{__dir__}/repos/macros"
|
14
15
|
require "#{__dir__}/repos/organization_fields"
|
@@ -24,9 +24,37 @@ module Readiness
|
|
24
24
|
issue.description = team_member_license_message
|
25
25
|
create = Readiness::GitLab::Issues.create!(@gitlab_client, project, issue)
|
26
26
|
puts "Issue created: #{create.web_url}"
|
27
|
+
if Date.parse(expiration) > Date.today + 1.years
|
28
|
+
comment_params = {
|
29
|
+
body: over_a_year_comment
|
30
|
+
}
|
31
|
+
Readiness::GitLab::Issues.create_comment!(@gitlab_client, project, create, comment_params)
|
32
|
+
end
|
27
33
|
exit 0
|
28
34
|
end
|
29
35
|
|
36
|
+
##
|
37
|
+
# Returns a String used for a comment body
|
38
|
+
#
|
39
|
+
# @author Jason Colyer
|
40
|
+
# @since 1.0.75
|
41
|
+
def self.over_a_year_comment
|
42
|
+
<<~STRING
|
43
|
+
Greetings @#{requester.username} !
|
44
|
+
|
45
|
+
We have detected the license you are requesting would have an expiration date over the standard allowance of one year.
|
46
|
+
|
47
|
+
To proceed, please take one of the following actions:
|
48
|
+
|
49
|
+
- Comment stating the maximum standard allowance of one year (#{Date.today + 1.years}) is acceptable
|
50
|
+
- Comment explaining the reason for an exception to the maximum standard allowance of one year (#{Date.today + 1.years})
|
51
|
+
|
52
|
+
Please note without one of the above actions being done, we would not be able to proceed on this request.
|
53
|
+
|
54
|
+
Thanks!
|
55
|
+
STRING
|
56
|
+
end
|
57
|
+
|
30
58
|
##
|
31
59
|
# Sets the global variable requester
|
32
60
|
#
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gitlab_support_readiness
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.75
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Colyer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-12-
|
11
|
+
date: 2024-12-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -292,6 +292,7 @@ files:
|
|
292
292
|
- lib/support_readiness/repos.rb
|
293
293
|
- lib/support_readiness/repos/articles.rb
|
294
294
|
- lib/support_readiness/repos/automations.rb
|
295
|
+
- lib/support_readiness/repos/dynamic_content.rb
|
295
296
|
- lib/support_readiness/repos/groups.rb
|
296
297
|
- lib/support_readiness/repos/macros.rb
|
297
298
|
- lib/support_readiness/repos/organization_fields.rb
|