diff options
author | ytti <saku@ytti.fi> | 2018-04-16 21:44:54 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-16 21:44:54 +0300 |
commit | 9a8692a7738d42a06d392aa573b5a4128da2ebec (patch) | |
tree | 3fc545ba2c256a98bdb04ec5946aafa122b27926 | |
parent | b29550ce0cfaf6192652747d340da2dc777ac22b (diff) | |
parent | 2e1717ec45d25b818f8ea10a5aa6d84f5d6947fc (diff) |
Merge pull request #1283 from wk/refactor-slackdiff
restructure slackdiff.rb to comply with rubocop
-rw-r--r-- | .rubocop_todo.yml | 16 | ||||
-rw-r--r-- | lib/oxidized/hook/slackdiff.rb | 77 |
2 files changed, 37 insertions, 56 deletions
diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 44d0fb6..81776bd 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -261,7 +261,6 @@ Layout/MultilineBlockLayout: # SupportedStyles: symmetrical, new_line, same_line Layout/MultilineMethodCallBraceLayout: Exclude: - - 'lib/oxidized/hook/slackdiff.rb' - 'lib/oxidized/output/git.rb' # Offense count: 14 @@ -379,7 +378,6 @@ Layout/SpaceInsideBlockBraces: # SupportedStylesForEmptyBraces: space, no_space Layout/SpaceInsideHashLiteralBraces: Exclude: - - 'lib/oxidized/hook/slackdiff.rb' - 'lib/oxidized/output/git.rb' - 'lib/oxidized/output/gitcrypt.rb' - 'lib/oxidized/output/http.rb' @@ -481,12 +479,6 @@ Lint/ShadowingOuterLocalVariable: - 'lib/oxidized/model/fortios.rb' - 'lib/oxidized/model/planet.rb' -# Offense count: 4 -# Cop supports --auto-correct. -Lint/StringConversionInInterpolation: - Exclude: - - 'lib/oxidized/hook/slackdiff.rb' - # Offense count: 10 Lint/UnderscorePrefixedVariableName: Exclude: @@ -682,12 +674,6 @@ Style/Alias: Style/AndOr: Enabled: false -# Offense count: 1 -# Configuration parameters: AllowedChars. -Style/AsciiComments: - Exclude: - - 'lib/oxidized/hook/slackdiff.rb' - # Offense count: 4 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, ProceduralMethods, FunctionalMethods, IgnoredMethods. @@ -802,7 +788,6 @@ Style/ExpandPathArguments: # SupportedStyles: format, sprintf, percent Style/FormatString: Exclude: - - 'lib/oxidized/hook/slackdiff.rb' - 'lib/oxidized/node.rb' - 'lib/oxidized/nodes.rb' @@ -819,7 +804,6 @@ Style/FormatStringToken: Style/GuardClause: Exclude: - 'lib/oxidized/cli.rb' - - 'lib/oxidized/hook/slackdiff.rb' - 'lib/oxidized/input/cli.rb' - 'lib/oxidized/jobs.rb' - 'lib/oxidized/nodes.rb' diff --git a/lib/oxidized/hook/slackdiff.rb b/lib/oxidized/hook/slackdiff.rb index 7cd4465..e271d5f 100644 --- a/lib/oxidized/hook/slackdiff.rb +++ b/lib/oxidized/hook/slackdiff.rb @@ -10,47 +10,44 @@ class SlackDiff < Oxidized::Hook end 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" - # 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 - unless diff == "no diffs" - 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 - 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" + return unless ctx.node + return unless 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" + # 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 + 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 + # message custom formatted - optional + if cfg.has_key?('message') == true + log cfg.message + msg = format(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 |