Skip to content
Snippets Groups Projects
Verified Commit 81bc1034 authored by Alexander Olofsson's avatar Alexander Olofsson
Browse files

Make rubocop happy

parent f2c9ac13
No related branches found
No related tags found
No related merge requests found
---
AllCops:
NewCops: enable
Metrics/AbcSize:
Enabled: false
Style/Documentation:
Enabled: false
# frozen_string_literal: true # frozen_string_literal: true
module ForemanNotificationSend module ForemanNotificationSend
module NotificationExtensions module NotificationExtensions
def self.prepended(base) def self.prepended(base)
...@@ -8,20 +9,12 @@ module ForemanNotificationSend ...@@ -8,20 +9,12 @@ module ForemanNotificationSend
end end
def send_notification def send_notification
if Setting[:notification_send_enable] send_notification_fallback if Setting[:notification_send_enable]
sender = SenderBase.create_sender(
backend: :matrix,
hs_url: Setting[:notification_send_target_url],
access_token: Setting[:notification_send_token],
room: Setting[:notification_send_target_room]
)
sender.send_notification(self)
end
#NotificationTarget.select { |target| target.should_send?(self) } # NotificationTarget.select { |target| target.should_send?(self) }
# .each { |target| target.send(self) } # .each { |target| target.send(self) }
rescue StandardError => ex rescue StandardError => e
Foreman::Logging.exception "Failed to send notification #{self}", ex Foreman::Logging.exception "Failed to send notification #{self}", e
end end
def level_to_symbol def level_to_symbol
...@@ -39,18 +32,15 @@ module ForemanNotificationSend ...@@ -39,18 +32,15 @@ module ForemanNotificationSend
def to_html def to_html
unless actions.empty? unless actions.empty?
action_str = '' munged = (actions[:links] || []).map do |action|
(actions[:links] || []).each do |action|
next unless action.key?(:href) && action.key?(:title) next unless action.key?(:href) && action.key?(:title)
url = action[:href] url = action[:href]
url = Setting[:foreman_url] + url unless action[:external] url = Setting[:foreman_url] + url unless action[:external]
action_str += ' | ' unless action_str.empty? "<a href=\"#{url}\">#{action[:title]}</a>"
action_str += "<a href=\"#{url}\">#{action[:title]}</a>"
end end
action_str = "<br/>[ #{action_str} ]" action_str = "<br/>[ #{munged.join ' | '} ]"
end end
"<b>#{notification_blueprint.group}</b>:<br/>#{level_to_symbol} #{message}#{action_str}" "<b>#{notification_blueprint.group}</b>:<br/>#{level_to_symbol} #{message}#{action_str}"
...@@ -58,20 +48,28 @@ module ForemanNotificationSend ...@@ -58,20 +48,28 @@ module ForemanNotificationSend
def to_markdown def to_markdown
unless actions.empty? unless actions.empty?
action_str = '' munged = (actions[:links] || []).map do |action|
(actions[:links] || []).each do |action|
next unless action.key?(:href) && action.key?(:title) next unless action.key?(:href) && action.key?(:title)
url = action[:href] url = action[:href]
url = Setting[:foreman_url] + url unless action[:external] url = Setting[:foreman_url] + url unless action[:external]
action_str += ' | ' unless action_str.empty? "[#{action[:title]}](#{url})"
action_str += "[#{action[:title]}](#{url})"
end end
action_str = " \n\\[ #{action_str}\\ ]" action_str = " \n\\[ #{munged.join ' | '}\\ ]"
end end
"**#{notification_blueprint.group}**:\n#{level_to_symbol} #{message}#{action_str}" "**#{notification_blueprint.group}**:\n#{level_to_symbol} #{message}#{action_str}"
end end
private
def send_notification_fallback
SenderBase.create_sender(
backend: :matrix,
hs_url: Setting[:notification_send_target_url],
access_token: Setting[:notification_send_token],
room: Setting[:notification_send_target_room]
).send_notification(self)
end
end end
end end
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
module ForemanNotificationSend module ForemanNotificationSend
class NotificationTarget < ApplicationRecord class NotificationTarget < ApplicationRecord
before_validation do before_validation do
backend = slugify_backend if backend # backend = slugify_backend if backend
end end
validate :validate_backend validate :validate_backend
......
# frozen_string_literal: true # frozen_string_literal: true
require 'matrix_sdk/api' require 'matrix_sdk/api'
module ForemanNotificationSend module ForemanNotificationSend
......
# frozen_string_literal: true
class AddNotificationTargets < ActiveRecord::Migration[5.1] class AddNotificationTargets < ActiveRecord::Migration[5.1]
def change def change
create_table :notification_targets do |t| create_table :notification_targets do |t|
...@@ -11,4 +13,3 @@ class AddNotificationTargets < ActiveRecord::Migration[5.1] ...@@ -11,4 +13,3 @@ class AddNotificationTargets < ActiveRecord::Migration[5.1]
end end
end end
end end
# frozen_string_literal: true
require 'foreman_notification_send/engine' require 'foreman_notification_send/engine'
module ForemanNotificationSend module ForemanNotificationSend
......
# frozen_string_literal: true
module ForemanNotificationSend module ForemanNotificationSend
VERSION = '0.1.0'.freeze VERSION = '0.1.0'
end end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment