Skip to content

Commit

Permalink
minor slackdiff refactor
Browse files Browse the repository at this point in the history
untested
  • Loading branch information
ytti committed Nov 3, 2018
1 parent 1985f0a commit 4cc7fc3
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions lib/oxidized/hook/slackdiff.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'slack'

# defaults to posting a diff, if messageformat is supplied them a message will be posted too
# diffenable defaults to true
# diff defaults to true

class SlackDiff < Oxidized::Hook
def validate_cfg!
Expand All @@ -21,14 +21,7 @@ def run_hook(ctx)
client = Slack::Client.new
client.auth_test
log "Connected"
# diff snippet - default
diffenable = true
if cfg.has_key?('diff') == true
if cfg.diff == false
diffenable = false
end
end
if diffenable == true
if cfg.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"
Expand All @@ -42,9 +35,9 @@ def run_hook(ctx)
end
end
# message custom formatted - optional
if cfg.has_key?('message') == true
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 }
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)
Expand Down

0 comments on commit 4cc7fc3

Please sign in to comment.