Class: Readiness::SupportSuperFormProcessor::CreateMacro
- Defined in:
- lib/support_readiness/support_super_form_processor/create_macro.rb
Overview
Defines the class CreateMacro within the module Zendesk.
Class Method Summary collapse
-
.advanced ⇒ Object
Sets the global variable advanced.
-
.assignee ⇒ Object
Sets the global variable assignee.
-
.comment ⇒ Object
Sets the global variable comment.
- .create_macro_file_if_needed ⇒ Object
-
.create_yaml_file(issue, path) ⇒ Object
Create the macro YAML file.
-
.determine_actions ⇒ Object
Determine the actions for a YAML file.
-
.instance ⇒ Object
Sets the global variable instance.
- .issue_assignees ⇒ Object
-
.macro_created_message ⇒ Object
Return a String for a macro creation comment.
-
.message(file_path) ⇒ Object
Return the string for the issue body.
-
.name ⇒ Object
Sets the global variable name.
-
.other ⇒ Object
Sets the global variable other.
-
.process!(gitlab_client, gitlab_admin_client) ⇒ Object
Process a Create Macro request.
-
.project ⇒ Object
Sets the global variable project.
-
.requester ⇒ Object
Sets the global variable requester.
-
.requester_email ⇒ Object
Sets the global variable requester_email.
-
.tag ⇒ Object
Sets the global variable tag.
-
.ticket_state ⇒ Object
Sets the global variable ticket_state.
-
.yaml_contents ⇒ Object
Sets the contents for a YAML file.
Methods inherited from Client
auth_error, bad_request_error, convert_actions, convert_conditions, convert_standard_names_to_ids, convert_ticket_form_agent_conditions, convert_ticket_form_brands, convert_ticket_form_end_user_conditions, convert_ticket_form_names_to_ids, convert_view_names_to_ids, convert_view_restrictions, covert_ticket_form_field_ids, create_package!, erb_renderer, handle_request_error, not_found_error, not_processible_error, put_into_archive, recursively_deflate_directory, timestamp_filename, to_clean_json, to_clean_json_with_key, to_hash, to_nearly_clean_json, to_nearly_clean_json_with_key, to_param_string, write_entries
Class Method Details
.advanced ⇒ Object
Sets the global variable advanced
144 145 146 |
# File 'lib/support_readiness/support_super_form_processor/create_macro.rb', line 144 def self.advanced @advanced ||= ENV.fetch('CREATE_MACRO_ADVANCED', 'yes') end |
.assignee ⇒ Object
Sets the global variable assignee
235 236 237 |
# File 'lib/support_readiness/support_super_form_processor/create_macro.rb', line 235 def self.assignee @assignee ||= ENV.fetch('CREATE_MACRO_ASSIGNEE') end |
.comment ⇒ Object
Sets the global variable comment
208 209 210 |
# File 'lib/support_readiness/support_super_form_processor/create_macro.rb', line 208 def self.comment @comment ||= ENV.fetch('CREATE_MACRO_COMMENT') end |
.create_macro_file_if_needed ⇒ Object
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/support_readiness/support_super_form_processor/create_macro.rb', line 148 def self.create_macro_file_if_needed return nil if comment == 'none' macro_project_id = if instance == 'Zendesk Global' 53382456 else 53561363 end macro_project = Readiness::GitLab::Projects.find!(@gitlab_client, macro_project_id) path = "active/#{name.split('::').join('/')}.md" file = Readiness::GitLab::Repositories.file(@gitlab_client, macro_project, path, 'master') unless file.key? 'file_name' commit_params = { branch: 'master', commit_message: 'Creating placeholder file for macro', actions: [ { file_path: path, content: 'PLACEHOLDER', action: 'create' } ] } Readiness::GitLab::Repositories.create_commit!(@gitlab_client, macro_project, commit_params) end path end |
.create_yaml_file(issue, path) ⇒ Object
Create the macro YAML file
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/support_readiness/support_super_form_processor/create_macro.rb', line 37 def self.create_yaml_file(issue, path) macro_project_id = if instance == 'Zendesk Global' 53382019 else 53561342 end macro_project = Readiness::GitLab::Projects.find!(@gitlab_client, macro_project_id) commit_params = { branch: 'master', commit_message: 'Creating new macro', actions: [ { file_path: "data/#{path.gsub(/md$/, 'yaml')}", content: yaml_contents, action: 'create' } ] } Readiness::GitLab::Repositories.create_commit!(@gitlab_client, macro_project, commit_params) comment_params = { body: } comment = Readiness::GitLab::Issues.create_comment!(@gitlab_client, project, issue, comment_params) end |
.determine_actions ⇒ Object
Determine the actions for a YAML file
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/support_readiness/support_super_form_processor/create_macro.rb', line 104 def self.determine_actions actions = [] if ticket_state != 'none' actions.push({ 'field' => 'status', 'value' => ticket_state }) end if assignee == 'Unassign' actions.push({ 'field' => 'assignee_id', 'value' => '' }) end if assignee == 'Current User' actions.push({ 'field' => 'assignee_id', 'value' => 'current_user' }) end if tag != 'None' actions.push({ 'field' => 'current_tags', 'value' => tag }) end if comment == 'Public' actions.push({ 'field' => 'comment_mode_is_public', 'value' => 'true' }) end if comment == 'Private' actions.push({ 'field' => 'comment_mode_is_public', 'value' => 'false' }) end if comment != 'none' actions.push({ 'field' => 'comment_value', 'value' => 'MANAGED_CONTENT' }) end actions end |
.instance ⇒ Object
Sets the global variable instance
217 218 219 |
# File 'lib/support_readiness/support_super_form_processor/create_macro.rb', line 217 def self.instance @instance ||= ENV.fetch('CREATE_MACRO_INSTANCE') end |
.issue_assignees ⇒ Object
257 258 259 260 261 |
# File 'lib/support_readiness/support_super_form_processor/create_macro.rb', line 257 def self.issue_assignees return '@jcolyer @secole' if instance == 'Zendesk US Government' '@jcolyer @nabeel.bilgrami @avilla4 @dtragjasi @secole @rverschoor' end |
.macro_created_message ⇒ Object
Return a String for a macro creation comment
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/support_readiness/support_super_form_processor/create_macro.rb', line 67 def self. <<~STRING Greetings @#{requester.username} ! Your macro has now been created on the #{instance} instance. Keep in mind a hard refresh of your Zendesk tab might be required to see the macro listed. If using a managed content file for this new macro and you had not populated it before your submission, a placeholder file was created for you (and you will need to make a MR on it to update the macro's wording). If you have any problems, please reopen this issue and ping the Support Readiness team for assistance. /label ~"Stage::Completed" /close STRING end |
.message(file_path) ⇒ Object
Return the string for the issue body
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 |
# File 'lib/support_readiness/support_super_form_processor/create_macro.rb', line 268 def self.(file_path) <<~STRING ## Create a macro Greetings @#{requester.username} ! This is a request to create a new macro within a Zendesk instance. The details are as follows: - Name of Macro: #{name} - Zendesk Instance: #{instance} - Assigne change: #{assignee} - Tag to add: #{tag} - Type of comment: #{comment} - Ticket state to set: #{ticket_state} - Managed content file: #{file_path.nil? ? 'N/A' : file_path} Some other details are: ``` #{other} ``` /label ~"Stage::Development" ~administrative ~p4 ~"Customer::Support" ~zendesk /assign #{issue_assignees} STRING end |
.name ⇒ Object
Sets the global variable name
226 227 228 |
# File 'lib/support_readiness/support_super_form_processor/create_macro.rb', line 226 def self.name @name ||= ENV.fetch('CREATE_MACRO_NAME') end |
.other ⇒ Object
Sets the global variable other
253 254 255 |
# File 'lib/support_readiness/support_super_form_processor/create_macro.rb', line 253 def self.other @other ||= ENV.fetch('CREATE_MACRO_OTHER') end |
.process!(gitlab_client, gitlab_admin_client) ⇒ Object
Process a Create Macro request
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/support_readiness/support_super_form_processor/create_macro.rb', line 18 def self.process!(gitlab_client, gitlab_admin_client) @gitlab_client = gitlab_client @gitlab_admin_client = gitlab_admin_client requester file_path = create_macro_file_if_needed issue = Readiness::GitLab::Issues.new issue.title = 'Create a new macro' issue.description = (file_path) create = Readiness::GitLab::Issues.create!(@gitlab_client, project, issue) puts "Issue created: #{create.web_url}" create_yaml_file(create, file_path) if advanced == 'no' exit 0 end |
.project ⇒ Object
Sets the global variable project
199 200 201 |
# File 'lib/support_readiness/support_super_form_processor/create_macro.rb', line 199 def self.project @project ||= Readiness::GitLab::Projects.find!(@gitlab_client, 68534119) end |
.requester ⇒ Object
Sets the global variable requester
181 182 183 |
# File 'lib/support_readiness/support_super_form_processor/create_macro.rb', line 181 def self.requester @requester ||= Readiness::SupportSuperFormProcessor::Shared.gitlab_user_check(@gitlab_admin_client, requester_email) end |
.requester_email ⇒ Object
Sets the global variable requester_email
190 191 192 |
# File 'lib/support_readiness/support_super_form_processor/create_macro.rb', line 190 def self.requester_email @requester_email ||= ENV.fetch('REQUESTER_EMAIL') end |
.tag ⇒ Object
Sets the global variable tag
244 245 246 |
# File 'lib/support_readiness/support_super_form_processor/create_macro.rb', line 244 def self.tag @tag ||= ENV.fetch('CREATE_MACRO_TAG') end |
.ticket_state ⇒ Object
Sets the global variable ticket_state
135 136 137 |
# File 'lib/support_readiness/support_super_form_processor/create_macro.rb', line 135 def self.ticket_state @ticket_state ||= ENV.fetch('CREATE_MACRO_STATE', 'none') end |
.yaml_contents ⇒ Object
Sets the contents for a YAML file
88 89 90 91 92 93 94 95 96 97 |
# File 'lib/support_readiness/support_super_form_processor/create_macro.rb', line 88 def self.yaml_contents { 'title' => name, 'active' => true, 'description' => '', 'actions' => determine_actions, 'restriction' => nil, 'contains_managed_content' => (comment != 'none') }.to_yaml end |