summaryrefslogtreecommitdiff
path: root/lib/oxidized/hook
diff options
context:
space:
mode:
Diffstat (limited to 'lib/oxidized/hook')
-rw-r--r--lib/oxidized/hook/exec.rb1
-rw-r--r--lib/oxidized/hook/githubrepo.rb2
-rw-r--r--lib/oxidized/hook/slackdiff.rb42
-rw-r--r--lib/oxidized/hook/xmppdiff.rb60
4 files changed, 94 insertions, 11 deletions
diff --git a/lib/oxidized/hook/exec.rb b/lib/oxidized/hook/exec.rb
index a9a5950..3f984c2 100644
--- a/lib/oxidized/hook/exec.rb
+++ b/lib/oxidized/hook/exec.rb
@@ -71,6 +71,7 @@ class Exec < Oxidized::Hook
"OX_NODE_FROM" => ctx.node.from.to_s,
"OX_NODE_MSG" => ctx.node.msg.to_s,
"OX_NODE_GROUP" => ctx.node.group.to_s,
+ "OX_NODE_MODEL" => ctx.node.model.class.name,
"OX_REPO_COMMITREF" => ctx.commitref.to_s,
"OX_REPO_NAME" => ctx.node.repo.to_s,
)
diff --git a/lib/oxidized/hook/githubrepo.rb b/lib/oxidized/hook/githubrepo.rb
index d33e54e..f74b22a 100644
--- a/lib/oxidized/hook/githubrepo.rb
+++ b/lib/oxidized/hook/githubrepo.rb
@@ -51,7 +51,7 @@ class GithubRepo < Oxidized::Hook
else
if cfg.has_key?('publickey') && cfg.has_key?('privatekey')
log "Using ssh auth with key", :debug
- Rugged::Credentials::SshKey.new(username: 'git', publickey: File.expand_path(cfg.publickey), privatekey: File.expand_path(cfg.privatekey))
+ Rugged::Credentials::SshKey.new(username: 'git', publickey: File.expand_path(cfg.publickey), privatekey: File.expand_path(cfg.privatekey), passphrase: ENV["OXIDIZED_SSH_PASSPHRASE"])
else
log "Using ssh auth with agentforwarding", :debug
Rugged::Credentials::SshKeyFromAgent.new(username: 'git')
diff --git a/lib/oxidized/hook/slackdiff.rb b/lib/oxidized/hook/slackdiff.rb
index 61f1743..7cd4465 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,35 @@ 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
+ 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"
end
end
diff --git a/lib/oxidized/hook/xmppdiff.rb b/lib/oxidized/hook/xmppdiff.rb
new file mode 100644
index 0000000..396d1b3
--- /dev/null
+++ b/lib/oxidized/hook/xmppdiff.rb
@@ -0,0 +1,60 @@
+require 'xmpp4r'
+require 'xmpp4r/muc/helper/simplemucclient'
+
+class XMPPDiff < Oxidized::Hook
+ def validate_cfg!
+ raise KeyError, 'hook.jid is required' unless cfg.has_key?('jid')
+ 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
+
+ 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"
+ end
+ end
+ end
+ end
+end