summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorWild Kat <wk@futureinquestion.net>2018-04-15 08:58:25 +0200
committerWild Kat <wk@futureinquestion.net>2018-04-15 08:58:25 +0200
commita26a1f78a71a03f5de7bbeee11a87d57be6a5343 (patch)
tree246c83031821287398db6b7d5a8bf86c7b8dc883 /lib
parentec90b081f0fed05497ce6ae21e4b4ba4d44ecc01 (diff)
massage into rubocop compliance
Diffstat (limited to 'lib')
-rw-r--r--lib/oxidized/hook/ciscosparkdiff.rb66
1 files changed, 32 insertions, 34 deletions
diff --git a/lib/oxidized/hook/ciscosparkdiff.rb b/lib/oxidized/hook/ciscosparkdiff.rb
index 12094e6..d43ff81 100644
--- a/lib/oxidized/hook/ciscosparkdiff.rb
+++ b/lib/oxidized/hook/ciscosparkdiff.rb
@@ -11,41 +11,39 @@ class CiscoSparkDiff < Oxidized::Hook
end
def run_hook(ctx)
- if ctx.node
- if ctx.event.to_s == "post_store"
- log "Connecting to Cisco Spark"
- CiscoSpark.configure do |config|
- config.api_key = cfg.accesskey
- config.proxy = cfg.proxy if cfg.has_key?('proxy')
- end
- space = cfg.space
- client = CiscoSpark::Room.new(id: space)
- client.fetch
- log "Connected"
- diffenable = true
- if cfg.has_key?('diff') == true
- if cfg.diff == false
- diffenable = false
- end
- end
- if diffenable == true
- gitoutput = ctx.node.output.new
- diff = gitoutput.get_diff ctx.node, ctx.node.group, ctx.commitref, nil
- title = "#{ctx.node.name.to_s}"
- log "Posting diff as snippet to #{cfg.space}"
- message = CiscoSpark::Message.new(text: 'Device ' + title + ' modified:' + "\n" + diff[:patch].lines.to_a[4..-1].join)
- room = CiscoSpark::Room.new(id: space)
- room.send_message(message)
- end
- if cfg.has_key?('message') == true
- log cfg.message
- msg = cfg.message % {:node => ctx.node.name.to_s, :group => ctx.node.group.to_s, :commitref => ctx.commitref, :model => ctx.node.model.class.name.to_s.downcase}
- log msg
- log "Posting message to #{cfg.space}"
- client.chat_postMessage(channel: cfg.channel, text: msg, as_user: true)
- end
- log "Finished"
+ return unless ctx.node
+ return unless ctx.event.to_s == "post_store"
+ log "Connecting to Cisco Spark"
+ CiscoSpark.configure do |config|
+ config.api_key = cfg.accesskey
+ config.proxy = cfg.proxy if cfg.has_key?('proxy')
+ end
+ space = cfg.space
+ client = CiscoSpark::Room.new(id: space)
+ client.fetch
+ log "Connected"
+ diffenable = true
+ if cfg.has_key?('diff') == true
+ if cfg.diff == false
+ diffenable = false
end
end
+ if diffenable == true
+ gitoutput = ctx.node.output.new
+ diff = gitoutput.get_diff ctx.node, ctx.node.group, ctx.commitref, nil
+ title = ctx.node.name.to_s
+ log "Posting diff as snippet to #{cfg.space}"
+ message = CiscoSpark::Message.new(text: 'Device ' + title + ' modified:' + "\n" + diff[:patch].lines.to_a[4..-1].join)
+ room = CiscoSpark::Room.new(id: space)
+ room.send_message(message)
+ end
+ if cfg.has_key?('message') == true
+ log cfg.message
+ msg = format(cfg.message, :node => ctx.node.name.to_s, :group => ctx.node.group.to_s, :commitref => ctx.commitref, :model => ctx.node.model.class.name.to_s.downcase)
+ log msg
+ log "Posting message to #{cfg.space}"
+ client.chat_postMessage(channel: cfg.channel, text: msg, as_user: true)
+ end
+ log "Finished"
end
end