Class: Readiness::Repos::SLAs
- Defined in:
- lib/support_readiness/repos/sla_policies.rb
Overview
Defines the class SLAs within the module Readiness::Repos.
Class Method Summary collapse
-
.compare(zendesk_client, location = 'data', verbose = false) ⇒ Hash
Compares the repo automation files to the Zendesk instance SLA policies.
-
.detailed_diff(repo, zendesk) ⇒ Object
Outputs a comparison report.
-
.gather(location = 'data') ⇒ Array
Parses repo group files.
-
.repo_check(objects) ⇒ Object
Performs basic checks on the repo.
-
.report_diffs(diffs) ⇒ Object
Outputs a comparison report.
-
.report_errors ⇒ Object
Outputs an error report and exits with a status code of 1.
-
.update_object(repo, zendesk) ⇒ Object
Creates an instance of Zendesk::Groups to use for updates.
-
.validity_check(file, object) ⇒ Object
Performs basic checks on a repo 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
.compare(zendesk_client, location = 'data', verbose = false) ⇒ Hash
Compares the repo automation files to the Zendesk instance SLA policies
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/support_readiness/repos/sla_policies.rb', line 50 def self.compare(zendesk_client, location = 'data', verbose = false) @zendesk_client = zendesk_client diffs = { updates: [], creates: [] } from_repo = gather(location) from_zendesk = Zendesk::SLAs.list(zendesk_client) from_repo.each do |repo| zd = from_zendesk.detect { |z| z.title == repo.title } if zd.nil? diffs[:creates].push(repo) else comparable_zd = zd.dup comparable_repo = repo.dup comparable_zd.id = nil comparable_zd.policy_metrics.map { |a| a.delete('target_in_seconds') } comparable_zd.policy_metrics.sort_by! { |a| [a['priority'], a['metric']] } comparable_repo.policy_metrics.sort_by! { |a| [a['priority'], a['metric']] } diffs[:updates].push(update_object(repo, zd)) if to_clean_json(comparable_repo) != to_clean_json(comparable_zd) detailed_diff(repo, comparable_zd) if verbose && to_clean_json(comparable_repo) != to_clean_json(comparable_zd) end end report_diffs(diffs) if verbose diffs end |
.detailed_diff(repo, zendesk) ⇒ Object
Outputs a comparison report
96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/support_readiness/repos/sla_policies.rb', line 96 def self.detailed_diff(repo, zendesk) puts "Detailed diff of #{repo.title}" repo.instance_variables.each do |v| next if v == :@id if repo.instance_variable_get(v) != zendesk.instance_variable_get(v) puts "- #{v} Repo:" pp repo.instance_variable_get(v) puts " #{v} Zendesk:" pp zendesk.instance_variable_get(v) end end end |
.gather(location = 'data') ⇒ Array
Parses repo group files
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/support_readiness/repos/sla_policies.rb', line 136 def self.gather(location = 'data') @brands = Readiness::Zendesk::Brands.list(@zendesk_client) @categories = Readiness::Zendesk::TriggerCategories.list(@zendesk_client) @groups = Readiness::Zendesk::Groups.list(@zendesk_client) @schedules = Readiness::Zendesk::Schedules.list(@zendesk_client) @satisfaction_reasons = Readiness::Zendesk::SatisfactionReasons.list(@zendesk_client) @targets = Readiness::Zendesk::Targets.list(@zendesk_client) @ticket_fields = Readiness::Zendesk::TicketFields.list(@zendesk_client) @ticket_forms = Readiness::Zendesk::TicketForms.list(@zendesk_client) @webhooks = Readiness::Zendesk::Webhooks.list(@zendesk_client) @errors = [] @location = location array = [] Dir["#{@location}/*.yaml"].each do |f| object = YAML.safe_load_file(f) object = convert_conditions(object, 'filter') validity_check(f, object) object['id'] = nil array.push(Zendesk::SLAs.new(object)) end repo_check(array) report_errors unless @errors.count.zero? array end |
.repo_check(objects) ⇒ Object
Performs basic checks on the repo
193 194 195 196 197 198 199 200 |
# File 'lib/support_readiness/repos/sla_policies.rb', line 193 def self.repo_check(objects) duplicate_names = objects.group_by { |o| o.title }.select { |k, v| v.size > 1 }.map(&:first) unless duplicate_names.count.zero? duplicate_names.each do |d| @errors.push("The name '#{d}' is used in multiple files") end end end |
.report_diffs(diffs) ⇒ Object
Outputs a comparison report
83 84 85 86 87 |
# File 'lib/support_readiness/repos/sla_policies.rb', line 83 def self.report_diffs(diffs) puts 'Compare report:' puts "- Creates: #{diffs[:creates].count}" puts "- Updates: #{diffs[:updates].count}" end |
.report_errors ⇒ Object
Outputs an error report and exits with a status code of 1
166 167 168 169 170 171 172 173 |
# File 'lib/support_readiness/repos/sla_policies.rb', line 166 def self.report_errors puts 'The following errors were found in the repo files:' @errors.each do |e| puts "- #{e}" end puts 'Rectify the errors and retry. We cannot proceed with those errors occurring.' exit 1 end |
.update_object(repo, zendesk) ⇒ Object
Creates an instance of Zendesk::Groups to use for updates
118 119 120 121 122 |
# File 'lib/support_readiness/repos/sla_policies.rb', line 118 def self.update_object(repo, zendesk) object = repo object.id = zendesk.id object end |
.validity_check(file, object) ⇒ Object
Performs basic checks on a repo file
182 183 184 185 |
# File 'lib/support_readiness/repos/sla_policies.rb', line 182 def self.validity_check(file, object) @errors.push("Missing title: #{file}") if object['title'].nil? @errors.push("Missing position: #{file}") if object['position'].nil? end |