summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWild Kat <wk@futureinquestion.net>2018-04-15 13:08:53 +0200
committerWild Kat <wk@futureinquestion.net>2018-04-15 13:08:53 +0200
commitcc5c846b3b88cafd8c01c645e6ada3bab714ae91 (patch)
tree5bfb0c611da680f6938bdfb7515357ecb348cc6a
parent56ec279b2e9e2735ed88405fd177e77f9e376801 (diff)
restructure xmppdiff.rb to comply with rubocop
-rw-r--r--.rubocop_todo.yml12
-rw-r--r--lib/oxidized/hook/xmppdiff.rb86
2 files changed, 42 insertions, 56 deletions
diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml
index 8121015..0ff8dce 100644
--- a/.rubocop_todo.yml
+++ b/.rubocop_todo.yml
@@ -94,14 +94,6 @@ Layout/CommentIndentation:
- 'lib/oxidized/model/planet.rb'
- 'lib/oxidized/output/http.rb'
-# Offense count: 1
-# Cop supports --auto-correct.
-# Configuration parameters: EnforcedStyleAlignWith, AutoCorrect, Severity.
-# SupportedStylesAlignWith: start_of_line, def
-Layout/DefEndAlignment:
- Exclude:
- - 'lib/oxidized/hook/xmppdiff.rb'
-
# Offense count: 3
# Cop supports --auto-correct.
Layout/ElseAlignment:
@@ -504,7 +496,6 @@ Lint/ShadowingOuterLocalVariable:
Lint/StringConversionInInterpolation:
Exclude:
- 'lib/oxidized/hook/slackdiff.rb'
- - 'lib/oxidized/hook/xmppdiff.rb'
# Offense count: 10
Lint/UnderscorePrefixedVariableName:
@@ -716,7 +707,6 @@ Style/AsciiComments:
# IgnoredMethods: lambda, proc, it
Style/BlockDelimiters:
Exclude:
- - 'lib/oxidized/hook/xmppdiff.rb'
- 'lib/oxidized/model/aricentiss.rb'
- 'lib/oxidized/model/hatteras.rb'
@@ -768,7 +758,6 @@ Style/ClassVars:
# Cop supports --auto-correct.
Style/ColonMethodCall:
Exclude:
- - 'lib/oxidized/hook/xmppdiff.rb'
- 'lib/oxidized/input/ssh.rb'
- 'lib/oxidized/input/telnet.rb'
@@ -841,7 +830,6 @@ Style/GuardClause:
Exclude:
- 'lib/oxidized/cli.rb'
- 'lib/oxidized/hook/slackdiff.rb'
- - 'lib/oxidized/hook/xmppdiff.rb'
- 'lib/oxidized/input/cli.rb'
- 'lib/oxidized/jobs.rb'
- 'lib/oxidized/nodes.rb'
diff --git a/lib/oxidized/hook/xmppdiff.rb b/lib/oxidized/hook/xmppdiff.rb
index 396d1b3..52cc0e0 100644
--- a/lib/oxidized/hook/xmppdiff.rb
+++ b/lib/oxidized/hook/xmppdiff.rb
@@ -7,54 +7,52 @@ class XMPPDiff < Oxidized::Hook
raise KeyError, 'hook.password is required' unless cfg.has_key?('password')
raise KeyError, 'hook.channel is required' unless cfg.has_key?('channel')
raise KeyError, 'hook.nick is required' unless cfg.has_key?('nick')
- end
+ end
def run_hook(ctx)
- if ctx.node
- if ctx.event.to_s == "post_store"
- begin
- Timeout::timeout(15) do
- gitoutput = ctx.node.output.new
- diff = gitoutput.get_diff ctx.node, ctx.node.group, ctx.commitref, nil
-
- interesting = diff[:patch].lines.to_a[4..-1].any? { |line|
- ["+", "-"].include?(line[0]) and not ["#", "!"].include?(line[1])
- }
- interesting &&= diff[:patch].lines.to_a[5..-1].any? { |line| line[0] == '-' }
- interesting &&= diff[:patch].lines.to_a[5..-1].any? { |line| line[0] == '+' }
-
- if interesting
- log "Connecting to XMPP"
- client = Jabber::Client.new(Jabber::JID.new(cfg.jid))
- client.connect
- sleep 1
- client.auth(cfg.password)
- sleep 1
-
- log "Connected"
-
- m = Jabber::MUC::SimpleMUCClient.new(client)
- m.join(cfg.channel + "/" + cfg.nick)
-
- log "Joined"
-
- 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}"
-
- m.say(title + "\n\n" + diff[:patch].lines.to_a[4..-1].join)
-
- sleep 1
-
- client.close
-
- log "Finished"
-
- end
- end
- rescue Timeout::Error
- log "timed out"
+ return unless ctx.node
+ return unless ctx.event.to_s == "post_store"
+ begin
+ Timeout.timeout(15) do
+ gitoutput = ctx.node.output.new
+ diff = gitoutput.get_diff ctx.node, ctx.node.group, ctx.commitref, nil
+
+ interesting = diff[:patch].lines.to_a[4..-1].any? do |line|
+ ["+", "-"].include?(line[0]) and not ["#", "!"].include?(line[1])
+ end
+ interesting &&= diff[:patch].lines.to_a[5..-1].any? { |line| line[0] == '-' }
+ interesting &&= diff[:patch].lines.to_a[5..-1].any? { |line| line[0] == '+' }
+
+ if interesting
+ log "Connecting to XMPP"
+ client = Jabber::Client.new(Jabber::JID.new(cfg.jid))
+ client.connect
+ sleep 1
+ client.auth(cfg.password)
+ sleep 1
+
+ log "Connected"
+
+ m = Jabber::MUC::SimpleMUCClient.new(client)
+ m.join(cfg.channel + "/" + cfg.nick)
+
+ log "Joined"
+
+ title = "#{ctx.node.name} #{ctx.node.group} #{ctx.node.model.class.name.to_s.downcase}"
+ log "Posting diff as snippet to #{cfg.channel}"
+
+ m.say(title + "\n\n" + diff[:patch].lines.to_a[4..-1].join)
+
+ sleep 1
+
+ client.close
+
+ log "Finished"
+
end
end
+ rescue Timeout::Error
+ log "timed out"
end
end
end