gitlab_support_readiness 1.0.19 → 1.0.20

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f6182992b5b76e5e94d186d3d998b3086aa2f8556ab2ec415831571f4cea307e
4
- data.tar.gz: 2f5ced30fdfc09a3f77d0bf39e441ea17495d6aad1c773a0d83301f616c7143e
3
+ metadata.gz: b36aa05c5d936f08ea9961cf7fc0582f496c90cdb33e0c6b9573e024d991353e
4
+ data.tar.gz: 9590937ab59c4faf480784ca41d16be020bde4074b27432a28185d3f5d01f5d2
5
5
  SHA512:
6
- metadata.gz: 1a83c65f3fcb8d2f87e332d7a68bcaa53196435d37bb48a93fe9172a9fe49d66b09f4c3ee6774e64893d19c988f6e0631b277b8d09e4ffbe04b98e36bc945319
7
- data.tar.gz: 508307ad679cd07b8007773010367a9e5a2115f1cd1c4066b3edc07531363a14d8658e3065121b0219c1b60496a732abdf0ab95f0034c287bae5b8dd52204467
6
+ metadata.gz: c178be37acfff617bb1f949bcf037777e959ba1835c4655a5dbc00f2a28701a0307e3f2c3ad58abea2c65ec1b903b017f7373598b018ecc1398a9573a485cb8f
7
+ data.tar.gz: cf2b8eea4098df2ad838b50897378a1cf288af69239a3b55ee8543d1948b425ed77750e0b699df093160859132d025af38ab69d9496d3b053c36c912bb18fc30
@@ -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
  #
@@ -273,7 +296,7 @@ module Readiness
273
296
  end
274
297
 
275
298
  ##
276
- # Updatea a theme. This will exit on error
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.update!(client, theme, 'data/modified_theme')
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.19
4
+ version: 1.0.20
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-17 00:00:00.000000000 Z
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