gitlab_support_readiness 1.0.19 → 1.0.21
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/support_readiness/repos/themes.rb +138 -0
- data/lib/support_readiness/repos.rb +1 -0
- data/lib/support_readiness/zendesk/themes.rb +52 -3
- 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: 0ac5cbb03de328e4bec9581e0e6ddcd65876de9708427bc95c2a793100e93355
|
4
|
+
data.tar.gz: 159d9e4823dbad2b62579c9adf0a69a1e015e234388c300d898585d8fdfc493a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 190e8d238e72846abf8d103cc4c24c6dd17d67f93a9204996bc64489bf01bf9c1e41d15cf96a3d57f760f27f8015620d9447dcdd4c16bee868acf1acaf932da8
|
7
|
+
data.tar.gz: 0f3ccceec4f67d4107d276835b601cf5255f9cdd842847e4453567b5c9c5d34c626ff6609617f3afe35b5022652bd2d1ff40bfde271e63fd3c967dcc83b0554b
|
@@ -0,0 +1,138 @@
|
|
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 Themes within the module {Readiness::Repos}.
|
9
|
+
#
|
10
|
+
# @author Jason Colyer
|
11
|
+
# @since 1.0.20
|
12
|
+
class Themes < Readiness::Client
|
13
|
+
##
|
14
|
+
# Creates a modified theme
|
15
|
+
#
|
16
|
+
# @author Jason Colyer
|
17
|
+
# @since 1.0.20
|
18
|
+
# @param source [String] The absolute or relative path of the theme folder
|
19
|
+
# @param target [String] The absolute or relative path you want your modified theme put in
|
20
|
+
# @param fields [Array] An array of {Readiness::Zendesk::TicketFields} instances
|
21
|
+
# @param forms [Array] An array of {Readiness::Zendesk::TicketForms} instances
|
22
|
+
def self.create_modified(source, target, fields, forms)
|
23
|
+
create_copy(source, target)
|
24
|
+
convert_only(target, fields, forms)
|
25
|
+
end
|
26
|
+
|
27
|
+
##
|
28
|
+
# Runs the conversion for a theme
|
29
|
+
#
|
30
|
+
# @author Jason Colyer
|
31
|
+
# @since 1.0.20
|
32
|
+
# @param destination [String] The absolute or relative path of the the theme folder to convert
|
33
|
+
# @param fields [Array] An array of {Readiness::Zendesk::TicketFields} instances
|
34
|
+
# @param forms [Array] An array of {Readiness::Zendesk::TicketForms} instances
|
35
|
+
def self.convert_only(destination, fields, forms)
|
36
|
+
@destination = destination
|
37
|
+
@fields = fields
|
38
|
+
@forms = forms
|
39
|
+
files_to_convert.each do |file|
|
40
|
+
convert_file(file)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
##
|
45
|
+
# Copies from source to target
|
46
|
+
#
|
47
|
+
# @author Jason Colyer
|
48
|
+
# @since 1.0.20
|
49
|
+
# @param source [String] The absolute or relative path of the theme folder
|
50
|
+
# @param target [String] The absolute or relative path you want your modified theme put in
|
51
|
+
def self.create_copy(source = 'data/theme', target = 'data/modified_theme')
|
52
|
+
FileUtils.copy_entry source, target
|
53
|
+
end
|
54
|
+
|
55
|
+
##
|
56
|
+
# Generates an array of files to use
|
57
|
+
#
|
58
|
+
# @author Jason Colyer
|
59
|
+
# @since 1.0.20
|
60
|
+
# @return [Array]
|
61
|
+
def self.files_to_convert
|
62
|
+
Dir["#{@destination}/templates/*.hbs"] + ["#{@destination}/script.js"]
|
63
|
+
end
|
64
|
+
|
65
|
+
##
|
66
|
+
# Converts the contents of a file for a theme
|
67
|
+
#
|
68
|
+
# @author Jason Colyer
|
69
|
+
# @since 1.0.20
|
70
|
+
# @param file [String] The absolute or relative path of a file to convert
|
71
|
+
def self.convert_file(file)
|
72
|
+
contents = File.read(file)
|
73
|
+
if contents =~ /\[\[form/ || contents =~ /\[\[field/
|
74
|
+
contents = scan_and_replace(contents)
|
75
|
+
end
|
76
|
+
File.write(file, contents)
|
77
|
+
end
|
78
|
+
|
79
|
+
##
|
80
|
+
# Scans and replaces items for themes
|
81
|
+
#
|
82
|
+
# @author Jason Colyer
|
83
|
+
# @since 1.0.20
|
84
|
+
# @param contents [String] The contents of a file being converted
|
85
|
+
# @return [String]
|
86
|
+
def self.scan_and_replace(contents)
|
87
|
+
contents.scan(/\[\[form:\ ?['"]?[^\]]+['"]?\]\]/).each { |m| contents = replace_forms(contents, m) }
|
88
|
+
contents.scan(/\[\[field:\ ?['"]?[^\]]+['"]?\]\]/).each { |m| contents = replace_fields(contents, m) }
|
89
|
+
contents
|
90
|
+
end
|
91
|
+
|
92
|
+
##
|
93
|
+
# Replaces form placeholders with their matching ID value
|
94
|
+
#
|
95
|
+
# @author Jason Colyer
|
96
|
+
# @since 1.0.20
|
97
|
+
# @param contents [String] The contents of a file being converted
|
98
|
+
# @param match [String] The regex match of a form placeholder
|
99
|
+
# @return [String]
|
100
|
+
def self.replace_forms(contents, match)
|
101
|
+
name = item_from_match(match)
|
102
|
+
form = @forms.detect { |f| f.name == name }
|
103
|
+
puts "Bad form in code: #{name}" if form.nil?
|
104
|
+
exit 1 if form.nil?
|
105
|
+
|
106
|
+
contents.gsub(match, form.id.to_s)
|
107
|
+
end
|
108
|
+
|
109
|
+
##
|
110
|
+
# Replaces field placeholders with their matching ID value
|
111
|
+
#
|
112
|
+
# @author Jason Colyer
|
113
|
+
# @since 1.0.20
|
114
|
+
# @param contents [String] The contents of a file being converted
|
115
|
+
# @param match [String] The regex match of a field placeholder
|
116
|
+
# @return [String]
|
117
|
+
def self.replace_fields(contents, match)
|
118
|
+
name = item_from_match(match)
|
119
|
+
field = @fields.detect { |f| f.title == name }
|
120
|
+
puts "Bad field in code: #{name}" if field.nil?
|
121
|
+
exit 1 if field.nil?
|
122
|
+
|
123
|
+
contents.gsub(match, field.id.to_s)
|
124
|
+
end
|
125
|
+
|
126
|
+
##
|
127
|
+
# Determine the title/name of the form/field in a match
|
128
|
+
#
|
129
|
+
# @author Jason Colyer
|
130
|
+
# @since 1.0.20
|
131
|
+
# @param match [String] The regex match of a form or field placeholder
|
132
|
+
# @return [String]
|
133
|
+
def self.item_from_match(match)
|
134
|
+
match.split(':').last.split(']').first.strip.gsub(/^['"]/, '').gsub(/['"]$/, '')
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
@@ -13,6 +13,7 @@ module Readiness
|
|
13
13
|
require "#{__dir__}/repos/macros"
|
14
14
|
require "#{__dir__}/repos/organization_fields"
|
15
15
|
require "#{__dir__}/repos/sla_policies"
|
16
|
+
require "#{__dir__}/repos/themes"
|
16
17
|
require "#{__dir__}/repos/ticket_fields"
|
17
18
|
require "#{__dir__}/repos/ticket_forms"
|
18
19
|
require "#{__dir__}/repos/triggers"
|
@@ -128,6 +128,29 @@ module Readiness
|
|
128
128
|
Themes.new(Oj.load(response.body)['theme'])
|
129
129
|
end
|
130
130
|
|
131
|
+
#
|
132
|
+
# Locates a theme within Zendesk by its name.
|
133
|
+
#
|
134
|
+
# @author Jason Colyer
|
135
|
+
# @since 1.0.20
|
136
|
+
# @param client [Object] An instance of {Readiness::Zendesk::Client}
|
137
|
+
# @param name [String] The theme name to locate
|
138
|
+
# @return [Object]
|
139
|
+
# @example
|
140
|
+
# require 'support_readiness'
|
141
|
+
# config = Readiness::Zendesk::Configuration.new
|
142
|
+
# config.username = 'alice@example.com'
|
143
|
+
# config.token = 'test123abc'
|
144
|
+
# config.url = 'https://example.zendesk.com/api/v2'
|
145
|
+
# client = Readiness::Zendesk::Client.new(config)
|
146
|
+
# theme = Readiness::Zendesk::Themes.find_by_name(client, 'GitLab Zendesk Global Theme')
|
147
|
+
# pp theme.id
|
148
|
+
# # => "6d7ccf08-5674-467c-9036-3403b6c5e91d"
|
149
|
+
def self.find_by_name(client, name)
|
150
|
+
themes = Themes.list(client)
|
151
|
+
themes.detect { |t| t.name == name }
|
152
|
+
end
|
153
|
+
|
131
154
|
##
|
132
155
|
# Creates a zip file from the given directory for a Zendesk app. This will exit on error
|
133
156
|
#
|
@@ -209,7 +232,7 @@ module Readiness
|
|
209
232
|
}
|
210
233
|
}
|
211
234
|
response = client.connection.post 'guide/theming/jobs/themes/imports', object.to_json
|
212
|
-
handle_request_error(1, 'Zendesk', response.status, { action: '
|
235
|
+
handle_request_error(1, 'Zendesk', response.status, { action: 'Create theme import job', id: theme.name }) unless response.status == 202
|
213
236
|
ThemeJobStatuses.new(Oj.load(response.body)['job'])
|
214
237
|
end
|
215
238
|
|
@@ -273,7 +296,7 @@ module Readiness
|
|
273
296
|
end
|
274
297
|
|
275
298
|
##
|
276
|
-
#
|
299
|
+
# Creates a theme. This will exit on error
|
277
300
|
#
|
278
301
|
# @author Jason Colyer
|
279
302
|
# @since 1.0.12
|
@@ -289,7 +312,7 @@ module Readiness
|
|
289
312
|
# config.url = 'https://example.zendesk.com/api/v2'
|
290
313
|
# client = Readiness::Zendesk::Client.new(config)
|
291
314
|
# theme = Readiness::Zendesk::Themes.live_theme(client)
|
292
|
-
# job = Readiness::Zendesk::Themes.
|
315
|
+
# job = Readiness::Zendesk::Themes.create!(client, theme, 'data/modified_theme')
|
293
316
|
# job = Readiness::Zendesk::Themes.upload!(client, job, file)
|
294
317
|
# pp job.id
|
295
318
|
# # => "a66e7bde543c6b6d018f0e07a654feaf"
|
@@ -298,6 +321,32 @@ module Readiness
|
|
298
321
|
job = generate_import_job!(client, theme)
|
299
322
|
upload!(client, job, file)
|
300
323
|
end
|
324
|
+
|
325
|
+
##
|
326
|
+
# Deletes a theme. Will exit if unsuccessful
|
327
|
+
#
|
328
|
+
# @author Jason Colyer
|
329
|
+
# @since 1.0.20
|
330
|
+
# @param client [Object] An instance of {Readiness::Zendesk::Client}
|
331
|
+
# @param theme [Object] An instance of {Readiness::Zendesk::Themes}
|
332
|
+
# @return [Boolean]
|
333
|
+
# @see https://developer.zendesk.com/api-reference/help_center/help-center-api/theming/#delete-theme Zendesk API > Themes > Delete Theme
|
334
|
+
# @example
|
335
|
+
# require 'support_readiness'
|
336
|
+
# config = Readiness::Zendesk::Configuration.new
|
337
|
+
# config.username = 'alice@example.com'
|
338
|
+
# config.token = 'test123abc'
|
339
|
+
# config.url = 'https://example.zendesk.com/api/v2'
|
340
|
+
# client = Readiness::Zendesk::Client.new(config)
|
341
|
+
# theme = Readiness::Zendesk::Themes.find!(client, 'a66e7bde543c6b6d018f0e07a654feaf')
|
342
|
+
# delete = Readiness::Zendesk::Themes.delete!(client, theme)
|
343
|
+
# pp delete
|
344
|
+
# # => true
|
345
|
+
def self.delete!(client, theme)
|
346
|
+
response = client.connection.delete "guide/themeing/themes/#{theme.id}"
|
347
|
+
handle_request_error(1, 'Zendesk', response.status, { action: 'Delete a theme', id: theme.id, message: Oj.load(response.body)}) unless response.status == 204
|
348
|
+
true
|
349
|
+
end
|
301
350
|
end
|
302
351
|
end
|
303
352
|
end
|
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.21
|
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-10-
|
11
|
+
date: 2024-10-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -278,6 +278,7 @@ files:
|
|
278
278
|
- lib/support_readiness/repos/macros.rb
|
279
279
|
- lib/support_readiness/repos/organization_fields.rb
|
280
280
|
- lib/support_readiness/repos/sla_policies.rb
|
281
|
+
- lib/support_readiness/repos/themes.rb
|
281
282
|
- lib/support_readiness/repos/ticket_fields.rb
|
282
283
|
- lib/support_readiness/repos/ticket_forms.rb
|
283
284
|
- lib/support_readiness/repos/triggers.rb
|