12
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
43
44
45
46
|
# File 'lib/oxidized/hook/slackdiff.rb', line 12
def run_hook(ctx)
return unless ctx.node
return unless ctx.event.to_s == "post_store"
log "Connecting to slack"
Slack::Web::Client.configure do |config|
config.token = cfg.token
config.proxy = cfg.proxy if cfg.has_key?('proxy')
end
client = Slack::Web::Client.new
client.auth_test
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
unless diff == "no diffs"
title = "#{ctx.node.name} #{ctx.node.group} #{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")
end
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.channel}"
client.chat_postMessage(channel: cfg.channel, text: msg, as_user: true)
end
log "Finished"
end
|