summaryrefslogtreecommitdiff
path: root/lib/oxidized/hook/xmppdiff.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/oxidized/hook/xmppdiff.rb')
-rw-r--r--lib/oxidized/hook/xmppdiff.rb66
1 files changed, 32 insertions, 34 deletions
diff --git a/lib/oxidized/hook/xmppdiff.rb b/lib/oxidized/hook/xmppdiff.rb
index 396d1b3..6acb172 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] == '+' }
+ 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
+ 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"
+ log "Connected"
- m = Jabber::MUC::SimpleMUCClient.new(client)
- m.join(cfg.channel + "/" + cfg.nick)
+ m = Jabber::MUC::SimpleMUCClient.new(client)
+ m.join(cfg.channel + "/" + cfg.nick)
- log "Joined"
+ 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}"
+ 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)
+ m.say(title + "\n\n" + diff[:patch].lines.to_a[4..-1].join)
- sleep 1
+ sleep 1
- client.close
+ client.close
- log "Finished"
+ log "Finished"
- end
- end
- rescue Timeout::Error
- log "timed out"
end
end
+ rescue Timeout::Error
+ log "timed out"
end
end
end