Class: Patches::Notifier
- Inherits:
-
Object
- Object
- Patches::Notifier
- Defined in:
- lib/patches/notifier.rb
Class Method Summary collapse
- .append_tenant_message(message) ⇒ Object
- .environment_prefix ⇒ Object
- .failure_message(patch_path, error) ⇒ Object
- .notify_failure(patch_path, error) ⇒ Object
- .notify_success(patches) ⇒ Object
- .send_hipchat_message(message, options) ⇒ Object
- .send_slack_message(message, color) ⇒ Object
- .success_message(patches) ⇒ Object
Class Method Details
.append_tenant_message(message) ⇒ Object
30 31 32 33 |
# File 'lib/patches/notifier.rb', line 30 def () = + " for tenant: #{Apartment::Tenant.current}" if defined?(Apartment) end |
.environment_prefix ⇒ Object
26 27 28 |
# File 'lib/patches/notifier.rb', line 26 def environment_prefix "[#{Rails.env.upcase}] " if defined?(Rails) end |
.failure_message(patch_path, error) ⇒ Object
20 21 22 23 24 |
# File 'lib/patches/notifier.rb', line 20 def (patch_path, error) details = "#{Pathname.new(patch_path).basename} failed with error: #{error}" = "#{environment_prefix}Error applying patch: #{details}" () end |
.notify_failure(patch_path, error) ⇒ Object
10 11 12 13 |
# File 'lib/patches/notifier.rb', line 10 def notify_failure(patch_path, error) ((patch_path, error), color: 'red') ((patch_path, error), 'danger') end |
.notify_success(patches) ⇒ Object
5 6 7 8 |
# File 'lib/patches/notifier.rb', line 5 def notify_success(patches) ((patches), color: 'green') ((patches), 'good') end |
.send_hipchat_message(message, options) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/patches/notifier.rb', line 35 def (, ) return unless defined?(HipChat) && config.use_hipchat client = HipChat::Client.new(config.hipchat_api_token, config.) room = client[config.hipchat_room] room.send(config.hipchat_user, , ) end |
.send_slack_message(message, color) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/patches/notifier.rb', line 43 def (, color) return unless defined?(Slack) && config.use_slack notifier = Slack::Notifier.new( config.slack_webhook_url, channel: config.slack_channel, username: config.slack_username) payload = { attachments: [{ color: color, text: }] } notifier.post payload end |
.success_message(patches) ⇒ Object
15 16 17 18 |
# File 'lib/patches/notifier.rb', line 15 def (patches) = "#{environment_prefix}#{patches.count} patches succeeded" () end |