Class: CiscoSparkDiff

Inherits:
Oxidized::Hook show all
Defined in:
lib/oxidized/hook/ciscosparkdiff.rb

Overview

defaults to posting a diff, if messageformat is supplied them a message will be posted too diff defaults to true Modified from slackdiff

Instance Attribute Summary

Attributes inherited from Oxidized::Hook

#cfg

Instance Method Summary collapse

Methods inherited from Oxidized::Hook

#log

Instance Method Details

#run_hook(ctx) ⇒ Object



13
14
15
16
17
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
# File 'lib/oxidized/hook/ciscosparkdiff.rb', line 13

def run_hook(ctx)
  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
  room = CiscoSpark::Room.new(id: cfg.space)
  log "Connected"

  if cfg.has_key?("diff") ? cfg.diff : 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}"
    room.send_message CiscoSpark::Message.new(text: 'Device ' + title + ' modified:' + "\n" + diff[:patch].lines.to_a[4..-1].join)
  end

  if cfg.message?
    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}"
    room.send_message CiscoSpark::Message.new(text: msg)
  end

  log "Finished"
end

#validate_cfg!Object

Raises:

  • (KeyError)


8
9
10
11
# File 'lib/oxidized/hook/ciscosparkdiff.rb', line 8

def validate_cfg!
  raise KeyError, 'hook.accesskey is required' unless cfg.has_key?('accesskey')
  raise KeyError, 'hook.space is required' unless cfg.has_key?('space')
end