In order to post to our Campfire chat when the CI goes red, we threw the following script in script/campfire_post:
#!/usr/bin/env ruby require 'rubygems' require 'net/http' require 'uri' require 'json' url = URI.parse('http://SUBDOMAIN.campfirenow.com/room/ROOM_ID/speak.json') req = Net::HTTP::Post.new(url.path) req.basic_auth 'API_KEY', 'X' # leave the X req.body = JSON.dump({ :message => { :body => ARGV.first }}) req.content_type = 'application/json' res = Net::HTTP.new(url.host, url.port).start {|http| http.request(req) } case res when Net::HTTPSuccess, Net::HTTPRedirection # OK else res.error! end
And then in cruise.rake:
desc "The task that cruisecontrol.rb runs" task :cruise do begin rake "spec" # etc # etc rescue exclaim = ["Oh goodness, t", "OMG t", "Look sharp, t", "Attention everyone! T", "Ohnoes! T"][rand * 5] system "ruby script/campfire_post '#{exclaim}he build just went red!'" raise end end
And it’s even cheeky!
About the Author