Skip to content

Instantly share code, notes, and snippets.

@chrisk
Created December 10, 2009 22:49
Show Gist options
  • Save chrisk/253773 to your computer and use it in GitHub Desktop.
Save chrisk/253773 to your computer and use it in GitHub Desktop.
Stateful version of the Integrity notifier for Campfire
# A stateful version of the Integrity notifier for Campfire. It only pings the room
# when the build is broken or when it's just been fixed. This is nice when you already
# have a post-receive hook posting every commit to the same room.
require 'rubygems'
require 'integrity'
require 'tinder'
require 'action_view'
module Integrity
class Notifier
class Campfire < Notifier::Base
include ActionView::Helpers::TextHelper
attr_reader :config
def self.to_haml
File.read File.dirname(__FILE__) / "config.haml"
end
def deliver!
if build.failed? && already_broken?
room.speak "The #{build.project.name} build is still broken: #{build_url}"
elsif build.failed? && !already_broken?
record!("red")
room.speak "#{build.commit_author.name} broke the #{build.project.name} build: #{build_url}"
elsif build.successful? && already_broken?
record!("green")
room.speak "#{build.commit_author.name} fixed the #{build.project.name} build: #{build_url}"
else
# the build was green, and it's still green. that's how we dooz it, no need to flaunt it
end
end
private
def room
@room ||= begin
campfire = Tinder::Campfire.new(config['account'], :ssl => true)
campfire.login(config['user'], config['pass'])
campfire.find_room_by_name(config['room'])
end
end
def log_filename
repo = build.project.name.gsub(/\s+/, '')
"/home/git/shared_hooks/logs/#{repo}.build_status.log"
end
def already_broken?
status = "green"
if File.exist?(log_filename)
status = File.open(log_filename) { |f| f.read.strip }
end
status == "red"
end
def record!(status)
File.open(log_filename, "w+") { |f| f.write(status) }
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment