Class: Readiness::SupportSuperFormProcessor::CreateMacro

Inherits:
Client
  • Object
show all
Defined in:
lib/support_readiness/support_super_form_processor/create_macro.rb

Overview

Defines the class CreateMacro within the module Zendesk.

Author:

  • Jason Colyer

Since:

  • 1.0.42

Class Method Summary collapse

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

.advancedObject

Sets the global variable advanced

Author:

  • Jason Colyer

Since:

  • 1.0.88



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

.assigneeObject

Sets the global variable assignee

Author:

  • Jason Colyer

Since:

  • 1.0.42



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

.commentObject

Sets the global variable comment

Author:

  • Jason Colyer

Since:

  • 1.0.42



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_neededObject

Since:

  • 1.0.42



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

Author:

  • Jason Colyer

Since:

  • 1.0.88



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: macro_created_message
  }
  comment = Readiness::GitLab::Issues.create_comment!(@gitlab_client, project, issue, comment_params)
end

.determine_actionsObject

Determine the actions for a YAML file

Author:

  • Jason Colyer

Since:

  • 1.0.88



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

.instanceObject

Sets the global variable instance

Author:

  • Jason Colyer

Since:

  • 1.0.42



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_assigneesObject

Since:

  • 1.0.42



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_messageObject

Return a String for a macro creation comment

Author:

  • Jason Colyer

Since:

  • 1.0.88



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.macro_created_message
  <<~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

Author:

  • Jason Colyer

Since:

  • 1.0.42



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.message(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

.nameObject

Sets the global variable name

Author:

  • Jason Colyer

Since:

  • 1.0.42



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

.otherObject

Sets the global variable other

Author:

  • Jason Colyer

Since:

  • 1.0.42



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

Author:

  • Jason Colyer

Since:

  • 1.0.42



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 = message(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

.projectObject

Sets the global variable project

Author:

  • Jason Colyer

Since:

  • 1.0.42



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

.requesterObject

Sets the global variable requester

Author:

  • Jason Colyer

Since:

  • 1.0.42



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_emailObject

Sets the global variable requester_email

Author:

  • Jason Colyer

Since:

  • 1.0.42



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

.tagObject

Sets the global variable tag

Author:

  • Jason Colyer

Since:

  • 1.0.42



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_stateObject

Sets the global variable ticket_state

Author:

  • Jason Colyer

Since:

  • 1.0.88



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_contentsObject

Sets the contents for a YAML file

Author:

  • Jason Colyer

Since:

  • 1.0.88



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