gitlab_support_readiness 1.0.73 → 1.0.74
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 +4 -4
- data/lib/support_readiness/repos/dynamic_content.rb +249 -0
- data/lib/support_readiness/repos.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6b3f87e5a80045ca0cd3f959d9e6b3e2afb6dfa08ae7e3954b9b73cb65fe1f03
|
4
|
+
data.tar.gz: 80d6535997df8341d0bb23dadb13b31057467197438d4ddfa805fe083b5fb4dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0947da13e747aeff24ba01433326d3b3ef1a8e2a155a1669453b29da532b3a8aa116fc94c43de4ced83f188b5fed901511abe72e452f2d1309301f4dbd22def2'
|
7
|
+
data.tar.gz: b04699bb4fe318b9d4382767ca4e65516982c684d6503d1bc275b5dfa21169200469087d6856900df46f110f5caaa1add7a6029616ee3ce8b09c37c9c94b307a
|
@@ -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"
|
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.74
|
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-11 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
|