Class: Readiness::SupportSuperFormProcessor::EditMacro

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

Overview

Defines the class EditMacro 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

.commentObject

Sets the global variable comment

Author:

  • Jason Colyer

Since:

  • 1.0.42



91
92
93
# File 'lib/support_readiness/support_super_form_processor/edit_macro.rb', line 91

def self.comment
  @comment ||= ENV.fetch('EDIT_MACRO_COMMENT')
end

.create_macro_file_if_neededObject

Since:

  • 1.0.42



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/support_readiness/support_super_form_processor/edit_macro.rb', line 31

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

.descriptionObject

Sets the global variable description

Author:

  • Jason Colyer

Since:

  • 1.0.42



118
119
120
# File 'lib/support_readiness/support_super_form_processor/edit_macro.rb', line 118

def self.description
  @tag ||= ENV.fetch('EDIT_MACRO_DESCRIPTION')
end

.instanceObject

Sets the global variable instance

Author:

  • Jason Colyer

Since:

  • 1.0.42



100
101
102
# File 'lib/support_readiness/support_super_form_processor/edit_macro.rb', line 100

def self.instance
  @instance ||= ENV.fetch('EDIT_MACRO_INSTANCE')
end

.issue_assigneesObject

Since:

  • 1.0.42



122
123
124
125
126
# File 'lib/support_readiness/support_super_form_processor/edit_macro.rb', line 122

def self.issue_assignees
  return '@jcolyer @secole' if instance == 'Zendesk US Government'

  '@jcolyer @nabeel.bilgrami @avilla4 @dtragjasi @secole @rverschoor'
end

.message(file_path) ⇒ Object

Return the string for the issue body

Author:

  • Jason Colyer

Since:

  • 1.0.42



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/support_readiness/support_super_form_processor/edit_macro.rb', line 133

def self.message(file_path)
  <<~STRING
    ## Edit an existing macro

    Greetings @#{requester.username} !

    This is a request to edit an existing macro within a Zendesk instance. The details are as follows:

    - Name of Macro: #{name}
    - Zendesk Instance: #{instance}
    - Type of comment: #{comment}
    - Managed content file: #{file_path.nil? ? 'N/A' : file_path}
    - Description of changes:

    ```

    #{description}

    ```

    /label ~"Stage::Development" ~zendesk ~"Customer::Support" ~p4 ~administrative

    /assign #{issue_assignees}
  STRING
end

.nameObject

Sets the global variable name

Author:

  • Jason Colyer

Since:

  • 1.0.42



109
110
111
# File 'lib/support_readiness/support_super_form_processor/edit_macro.rb', line 109

def self.name
  @name ||= ENV.fetch('EDIT_MACRO_CURRENT_NAME')
end

.process!(gitlab_client, gitlab_admin_client) ⇒ Object

Process a Edit Macro request

Author:

  • Jason Colyer

Since:

  • 1.0.42



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/support_readiness/support_super_form_processor/edit_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 = 'Edit an existing macro'
  issue.description = message(file_path)
  create = Readiness::GitLab::Issues.create!(@gitlab_client, project, issue)
  puts "Issue created: #{create.web_url}"
  exit 0
end

.projectObject

Sets the global variable project

Author:

  • Jason Colyer

Since:

  • 1.0.42



82
83
84
# File 'lib/support_readiness/support_super_form_processor/edit_macro.rb', line 82

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



64
65
66
# File 'lib/support_readiness/support_super_form_processor/edit_macro.rb', line 64

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



73
74
75
# File 'lib/support_readiness/support_super_form_processor/edit_macro.rb', line 73

def self.requester_email
  @requester_email ||= ENV.fetch('REQUESTER_EMAIL')
end