Skip to content

Instantly share code, notes, and snippets.

@tosik
Last active December 17, 2015 15:39
Show Gist options
  • Select an option

  • Save tosik/5632979 to your computer and use it in GitHub Desktop.

Select an option

Save tosik/5632979 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'carrier-pigeon'
require 'json'
require 'pp'
command = <<EOS
ssh gerrit.example.com gerrit stream-events
EOS
IO.popen(command, 'r+') do |io|
loop do
data = JSON.parse(io.gets)
pp data
if data
case data["type"]
when "comment-added"
comment = data["comment"].gsub(/[\r\n]/,"")
message = "#{comment} by #{data["author"]["name"]} #{data["change"]["url"]} owner is #{data["change"]["owner"]["name"]}"
when "patchset-created"
message = "patchset created by #{data["uploader"]["name"]} #{data["change"]["url"]} owner is #{data["change"]["owner"]["name"]}"
when 'change-merged'
"merged #{data["change"]["url"]} #{data["change"]["owner"]["name"]}"
end
CarrierPigeon.send(uri: 'irc://username:[email protected]/#gerrit', message: message, ssl: true, notice: false, join: true)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment