diff options
author | Nat Morris <nat@nuqe.net> | 2017-11-09 22:14:37 +0000 |
---|---|---|
committer | Neil Lathwood <neil@lathwood.co.uk> | 2017-11-09 22:14:37 +0000 |
commit | aa0e1808f25e5e8b1a76f34c29f2eeb7db75a7c7 (patch) | |
tree | 00367327d8f382f1403a9329eb2aae630170af7e /lib/oxidized/hook/slackdiff.rb | |
parent | 853480fca54492a38feaa4fa76941e88f54f11a8 (diff) |
feature: Slack hook - optionally disable diff snippets and post custom messages (#763)
* continue to diffs by default, but optionally post formatted messages
* updated readme
* remove static channel name
* Update Hooks.md
Diffstat (limited to 'lib/oxidized/hook/slackdiff.rb')
-rw-r--r-- | lib/oxidized/hook/slackdiff.rb | 40 |
1 files changed, 30 insertions, 10 deletions
diff --git a/lib/oxidized/hook/slackdiff.rb b/lib/oxidized/hook/slackdiff.rb index 61f1743..728e5a7 100644 --- a/lib/oxidized/hook/slackdiff.rb +++ b/lib/oxidized/hook/slackdiff.rb @@ -1,5 +1,8 @@ require 'slack' +# defaults to posting a diff, if messageformat is supplied them a message will be posted too +# diffenable defaults to true + class SlackDiff < Oxidized::Hook def validate_cfg! raise KeyError, 'hook.token is required' unless cfg.has_key?('token') @@ -17,16 +20,33 @@ class SlackDiff < Oxidized::Hook 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" - ) + # diff snippet - default + 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} #{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" + ) + end + # message custom formatted - optional + 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.channel}" + client.chat_postMessage(channel: cfg.channel, text: msg, as_user: true) + end log "Finished" end end |