Improved naming of variables.

This commit is contained in:
Martin Edenhofer 2016-04-18 10:01:20 +02:00
parent 9eb7fd02df
commit f242f2e125

View file

@ -90,15 +90,16 @@ backend.perform
color = '#38ad69' color = '#38ad69'
end end
config['items'].each {|item| config['items'].each {|local_config|
next if local_config['webhook'].empty?
# check if reminder_reached/escalation/escalation_warning is already sent today # check if reminder_reached/escalation/escalation_warning is already sent today
md5_webhook = Digest::MD5.hexdigest(@item['webhook']) md5_webhook = Digest::MD5.hexdigest(local_config['webhook'])
cache_key = "slack::backend::#{@item[:type]}::#{md5_webhook}" cache_key = "slack::backend::#{@item[:type]}::#{md5_webhook}"
if sent_value if sent_value
value = Cache.get(cache_key) value = Cache.get(cache_key)
if value == sent_value if value == sent_value
Rails.logger.debug "did not send webhook, already sent (#{@item[:type]}/#{ticket.id}/#{@item['webhook']})" Rails.logger.debug "did not send webhook, already sent (#{@item[:type]}/#{ticket.id}/#{local_config['webhook']})"
next next
end end
Cache.write( Cache.write(
@ -111,47 +112,47 @@ backend.perform
end end
# check action # check action
if item['types'].class == Array if local_config['types'].class == Array
hit = false hit = false
item['types'].each {|type| local_config['types'].each {|type|
next if type.to_s != @item[:type].to_s next if type.to_s != @item[:type].to_s
hit = true hit = true
break break
} }
next if !hit next if !hit
elsif item['types'] elsif local_config['types']
next if item['types'].to_s != @item[:type].to_s next if local_config['types'].to_s != @item[:type].to_s
end end
# check group # check group
if item['group_ids'].class == Array if local_config['group_ids'].class == Array
hit = false hit = false
item['group_ids'].each {|group_id| local_config['group_ids'].each {|group_id|
next if group_id.to_s != ticket.group_id.to_s next if group_id.to_s != ticket.group_id.to_s
hit = true hit = true
break break
} }
next if !hit next if !hit
elsif item['group_ids'] elsif local_config['group_ids']
next if item['group_ids'].to_s != ticket.group_id.to_s next if local_config['group_ids'].to_s != ticket.group_id.to_s
end end
logo_url = 'https://zammad.com/assets/images/logo-200x200.png' logo_url = 'https://zammad.com/assets/images/logo-200x200.png'
if !item['logo_url'].empty? if !local_config['logo_url'].empty?
logo_url = item['logo_url'] logo_url = local_config['logo_url']
end end
Rails.logger.debug "sent webhook (#{@item[:type]}/#{ticket.id}/#{@item['webhook']})" Rails.logger.debug "sent webhook (#{@item[:type]}/#{ticket.id}/#{local_config['webhook']})"
notifier = Slack::Notifier.new( notifier = Slack::Notifier.new(
item['webhook'], local_config['webhook'],
channel: item['channel'], channel: local_config['channel'],
username: item['username'], username: local_config['username'],
icon_url: logo_url, icon_url: logo_url,
mrkdwn: true, mrkdwn: true,
http_client: Transaction::Slack::Client, http_client: Transaction::Slack::Client,
) )
if item['expand'] if local_config['expand']
body = "#{result[:subject]}\n#{result[:body]}" body = "#{result[:subject]}\n#{result[:body]}"
result = notifier.ping body result = notifier.ping body
else else
@ -167,10 +168,10 @@ backend.perform
if sent_value if sent_value
Cache.delete(cache_key) Cache.delete(cache_key)
end end
Rails.logger.error "Unable to post webhook: #{@item['webhook']}: #{result.inspect}" Rails.logger.error "Unable to post webhook: #{local_config['webhook']}: #{result.inspect}"
next next
end end
Rails.logger.debug "sent webhook (#{@item[:type]}/#{ticket.id}/#{@item['webhook']})" Rails.logger.debug "sent webhook (#{@item[:type]}/#{ticket.id}/#{local_config['webhook']})"
} }
end end