Created
April 21, 2010 16:13
-
-
Save nstielau/374030 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
if ARGV.size < 1 || ARGV.size > 2 | |
puts "Usage: #{__FILE__} PATH_TO_PROJECT [CIJOE_URL]" | |
exit 1 | |
end | |
############################## | |
JABBER_USERNAME = "[email protected]" | |
JABBER_PASSWORD = "secret" | |
DESTINATION_JABBER_USERNAME = "[email protected]" | |
############################## | |
require 'rubygems' | |
require 'xmpp4r-simple' | |
require 'cijoe' | |
if ARGV.length == 2 | |
cijoe_url = ARGV.pop | |
path_param = ARGV.pop | |
elsif ARGV.length == 1 | |
cijoe_url = "" | |
path_param = ARGV.pop | |
end | |
$project_path = File.expand_path(path_param) | |
if !File.exist?($project_path) | |
puts "#{$project_path} doesn't seem to be a file" | |
exit 1 | |
end | |
# Will either of these two bail if it isn't a git project? | |
joe = CIJoe.new($project_path) | |
last_build = joe.read_build("last") | |
if last_build.nil? | |
puts "Can't find a build in that project. Build first, then try again." | |
exit 1 | |
end | |
is_new_build = (Time.now.to_i - last_build.finished_at.to_i) <= 5 | |
# Exit if it build worked and this isn't breaking news | |
exit if last_build.worked? && !is_new_build | |
im = Jabber::Simple.new(JABBER_USERNAME, JABBER_PASSWORD) | |
# Partychapp specific stuff | |
# TODO: Blame last_build.commit.author? | |
if DESTINATION_JABBER_USERNAME.match("partychapp.appspotchat.com") && is_new_build | |
q = im.deliver(DESTINATION_JABBER_USERNAME, "/alias CIJoeBot") # Get a cool alias | |
q = im.deliver(DESTINATION_JABBER_USERNAME, "#{last_build.project}_builds++") # keep track of builds | |
q = im.deliver(DESTINATION_JABBER_USERNAME, "#{last_build.project}_#{last_build.worked? ? "passes" : "failures"}++") # keep track of passes, failures | |
end | |
if is_new_build | |
message = "Last build of #{last_build.project} #{last_build.status.to_s.upcase}." # yell it! | |
else | |
message = "Reminder: #{last_build.project} has been broken since #{last_build.finished_at}." | |
end | |
message += " #{cijoe_url}" if cijoe_url | |
q = im.deliver(DESTINATION_JABBER_USERNAME, "#{message.gsub("\n","")}") | |
# wait a little for relay to complete | |
sleep(2) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment