Class: Readiness::SupportSuperFormProcessor::PagerdutyShadowModification
- Inherits:
-
Client
- Object
- Client
- Readiness::SupportSuperFormProcessor::PagerdutyShadowModification
- Defined in:
- lib/support_readiness/support_super_form_processor/pd_shadow_modification.rb
Overview
Defines the class PagerdutyShadowModification within the module Zendesk.
Class Method Summary collapse
-
.added ⇒ Object
Creates an issue to indicate being added.
- .added_message ⇒ Object
-
.bad_pd_user ⇒ Object
Creates an issue to indicate the requesterer doesn’t have a PD user.
- .bad_user_message ⇒ Object
-
.layer_name ⇒ Object
Sets the global layer_name.
-
.process!(gitlab_client, gitlab_admin_client, pagerduty_client) ⇒ Object
Process a Pagerduty Shadow Modification request.
-
.project ⇒ Object
Sets the global variable project.
-
.removed ⇒ Object
Creates an issue to indicate being removed.
- .removed_message ⇒ Object
-
.requester ⇒ Object
Sets the global variable requester.
-
.requester_email ⇒ Object
Sets the global variable requester_email.
-
.schedule_id ⇒ Object
Sets the global schedule_id.
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
.added ⇒ Object
Creates an issue to indicate being added
70 71 72 73 74 75 76 77 |
# File 'lib/support_readiness/support_super_form_processor/pd_shadow_modification.rb', line 70 def self.added issue = Readiness::GitLab::Issues.new issue.title = "Add to Pagerduty Shadow rotation" issue.description = create = Readiness::GitLab::Issues.create!(@gitlab_client, project, issue) puts "Issue created: #{create.web_url}" exit 0 end |
.added_message ⇒ Object
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/support_readiness/support_super_form_processor/pd_shadow_modification.rb', line 158 def self. <<~STRING ## Add to Pagerduty Shadow rotation Greetings @#{requester.username} ! We received a request to add you to a Pagerduty shadow rotation. This is to let you know it has been completed at this time. Do note you are at the top of the list, so your oncall for that would start this week. /label ~"AutomatedRequests::Pagerduty" /assign @#{requester.username} STRING end |
.bad_pd_user ⇒ Object
Creates an issue to indicate the requesterer doesn’t have a PD user
56 57 58 59 60 61 62 63 |
# File 'lib/support_readiness/support_super_form_processor/pd_shadow_modification.rb', line 56 def self.bad_pd_user issue = Readiness::GitLab::Issues.new issue.title = "Invalid request regarding Pagerduty Shadow rotation" issue.description = create = Readiness::GitLab::Issues.create!(@gitlab_client, project, issue) puts "Issue created: #{create.web_url}" exit 0 end |
.bad_user_message ⇒ Object
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/support_readiness/support_super_form_processor/pd_shadow_modification.rb', line 138 def self. <<~STRING ## Invalid request regarding Pagerduty Shadow rotation Greetings @#{requester.username} ! We received a request to add or remove you from a Pagerduty shadow rotation. We were unable to proceed as a PD user using your email, #{requester_email}, was not found Please double check your request to ensure the email you used matches the email in Pagerduty. Once that has been rectified, please submit a new request. /label ~"AutomatedRequests::Bad Pagerduty User" /assign @#{requester.username} STRING end |
.layer_name ⇒ Object
Sets the global layer_name
134 135 136 |
# File 'lib/support_readiness/support_super_form_processor/pd_shadow_modification.rb', line 134 def self.layer_name @layer_name ||= ENV.fetch('PD_SHADOW_LAYER') end |
.process!(gitlab_client, gitlab_admin_client, pagerduty_client) ⇒ Object
Process a Pagerduty Shadow Modification request
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/support_readiness/support_super_form_processor/pd_shadow_modification.rb', line 18 def self.process!(gitlab_client, gitlab_admin_client, pagerduty_client) @gitlab_client = gitlab_client @gitlab_admin_client = gitlab_admin_client @pagerduty_client = pagerduty_client requester pd_user = Readiness::Pagerduty::Users.find_by_email(@pagerduty_client, requester_email) bad_pd_user if pd_user.nil? schedule = Readiness::Pagerduty::Schedules.find!(@pagerduty_client, schedule_id) layer = schedule.schedule_layers.detect { |l| l['name'] == "Layer #{layer_name}" } if layer['users'].detect { |u| u['user']['id'] == pd_user.id } type = 'remove' if layer['users'].count == 1 layer['users'] = [{ user: { id: 'PRGFAO1', type: 'user_reference' }}] else layer['users'].delete_at(layer['users'].find_index { |u| u['user']['id'] == pd_user.id }) end else type = 'add' if layer['users'].count == 1 && layer['users'].first['user']['id'] == 'PRGFAO1' layer['users'] = [{ user: { id: pd_user.id, type: 'user_reference' }}] else layer['users'].push({ user: { id: pd_user.id, type: 'user_reference' }}) end end schedule.schedule_layers.each_with_index do |l, i| schedule.schedule_layers[i] = layer if l['name'] == layer['name'] break if l['name'] == layer['name'] end Readiness::Pagerduty::Schedules.update!(@pagerduty_client, schedule) added if type == 'add' removed if type == 'remove' end |
.project ⇒ Object
Sets the global variable project
116 117 118 |
# File 'lib/support_readiness/support_super_form_processor/pd_shadow_modification.rb', line 116 def self.project @project ||= Readiness::GitLab::Projects.find!(@gitlab_client, 12811526) end |
.removed ⇒ Object
Creates an issue to indicate being removed
84 85 86 87 88 89 90 91 |
# File 'lib/support_readiness/support_super_form_processor/pd_shadow_modification.rb', line 84 def self.removed issue = Readiness::GitLab::Issues.new issue.title = "Remove from Pagerduty Shadow rotation" issue.description = create = Readiness::GitLab::Issues.create!(@gitlab_client, project, issue) puts "Issue created: #{create.web_url}" exit 0 end |
.removed_message ⇒ Object
174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/support_readiness/support_super_form_processor/pd_shadow_modification.rb', line 174 def self. <<~STRING ## Remove from Pagerduty Shadow rotation Greetings @#{requester.username} ! We received a request to remove you from a Pagerduty shadow rotation. This is to let you know it has been completed at this time. /label ~"AutomatedRequests::Pagerduty" /assign @#{requester.username} STRING end |
.requester ⇒ Object
Sets the global variable requester
98 99 100 |
# File 'lib/support_readiness/support_super_form_processor/pd_shadow_modification.rb', line 98 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
107 108 109 |
# File 'lib/support_readiness/support_super_form_processor/pd_shadow_modification.rb', line 107 def self.requester_email @requester_email ||= ENV.fetch('REQUESTER_EMAIL') end |
.schedule_id ⇒ Object
Sets the global schedule_id
125 126 127 |
# File 'lib/support_readiness/support_super_form_processor/pd_shadow_modification.rb', line 125 def self.schedule_id @schedule_id ||= ENV.fetch('PD_SHADOW_SCHEDULE') end |