Class: SlackDiff

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

Instance Attribute Summary

Attributes inherited from Oxidized::Hook

#cfg

Instance Method Summary collapse

Methods inherited from Oxidized::Hook

#initialize, #log

Constructor Details

This class inherits a constructor from Oxidized::Hook

Instance Method Details

#run_hook(ctx) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/oxidized/hook/slackdiff.rb', line 9

def run_hook(ctx)
  if ctx.node
    if ctx.event.to_s == "post_store"
      log "Connecting to slack"
      Slack.configure do |config|
         config.token = cfg.token
         config.proxy = cfg.proxy if cfg.has_key?('proxy')
      end
      client = Slack::Client.new
      client.auth_test
      log "Connected"
      gitoutput = ctx.node.output.new
      diff = gitoutput.get_diff ctx.node, ctx.node.group, ctx.commitref, nil
      title = "#{ctx.node.name.to_s} #{ctx.node.group.to_s} #{ctx.node.model.class.name.to_s.downcase}"
      log "Posting diff as snippet to #{cfg.channel}"
      client.files_upload(channels: cfg.channel, as_user: true,
                           content: diff[:patch].lines.to_a[4..-1].join,
                           filetype: "diff",
                           title: title,
                           filename: "change"
                          )
      log "Finished"
    end
  end
end

#validate_cfg!Object

Raises:

  • (KeyError)


4
5
6
7
# File 'lib/oxidized/hook/slackdiff.rb', line 4

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