Skip to content

Instantly share code, notes, and snippets.

@dennisreimann
Created October 6, 2010 12:50
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save dennisreimann/613299 to your computer and use it in GitHub Desktop.
Save dennisreimann/613299 to your computer and use it in GitHub Desktop.
CIJoe mail notification script.
#!/usr/bin/env ruby
# CIJoe mail notification script.
# Some things in here are shamelessly ripped from
# http://gist.github.com/374030
#
# Call this from your hooks (build-worked, build-failed) with something like:
# ~/ci/scripts/mail.rb ~/ci/PROJECT/ CIJOE_URL BRANCH
#
# Requirements
# * gem install pony
if ARGV.size < 1 || ARGV.size > 2
puts "Usage: #{__FILE__} PATH_TO_PROJECT [CIJOE_URL]"
exit 1
end
from = 'cijoe@DOMAIN'
to = 'dev@DOMAIN'
require 'cijoe'
require 'pony'
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
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
subject = "[#{last_build.project}] #{joe.git_branch} build #{last_build.status.to_s}"
if last_build.worked? || (last_build.failed? && is_new_build)
body = "Last build of #{last_build.project} #{last_build.status.to_s}."
else
body = "Reminder: #{last_build.project} has been broken since #{last_build.finished_at}."
end
body += "\n\nDetails: #{cijoe_url}"
body += "\nAuthor: #{last_build.commit.author}"
body += "\nMessage: #{last_build.commit.message}"
body += "\n\nOutput: #{last_build.clean_output}" if last_build.failed?
Pony.mail(:from => from, :to => to, :subject => subject, :body => body)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment