Browse files

rename to smoke_signals

  • Loading branch information...
1 parent 8e928bb commit c256cda93e6ecfa9cf923dfd8175df1021de90e5 @muness muness committed Mar 14, 2008
Showing with 165 additions and 9 deletions.
  1. +9 −9 README
  2. +89 −0 smoke_signals.rb
  3. +5 −0 smoke_signals.yml_sample
  4. +62 −0 test/smoke_signals_test.rb
View
18 README
@@ -1,26 +1,26 @@
-h1. Campfire Notifier for Ruby Cruise Control
+h1. Smoke Signals
-h2. Version: 0.1 (forked from Giles Bowkett's 0.3)
+h2. Version: 0.1
+Forked from Giles Bowkett's cc_campfire_notifier version 0.3
h2. Description
A plugin for CruiseControl.rb that does the following features:
- * Send notifications to a Campfire room with the build status (success, failure, fixed).
+ * Send notifications to a Campfire room with the build status (success, failure, fixed) along with a URL to the build.
* Detects and sends notifications re Subversion failures.
* Supports different rooms per build.
h2. Install
# sudo gem install tinder
-# copy campfire_notifier.rb into <CRUISE_ROOT>/builder_plugins/installed
-
-h2. Usage
-# copy campfire_notifier.yml_sample to <CRUISE_ROOT>/config/campfire_notifier.yml
+# copy smoke_signals.rb into <CRUISE_ROOT>/builder_plugins/installed
+# copy smoke_signals.yml_sample to <CRUISE_ROOT>/config/smoke_signals.yml
# modify it with your campfire specifics
# for project-specific rooms, in your build's specific cruise_config.rb add the following:
- project.campfire_notifier.room_name = "Room name" # replace Room name
+ project.smoke_signals.room_name = "Room name" # replace Room name
# restart CruiseControl.rb
h2. URLS
- * "svn trunk":https://opensource.thinkrelevance.com/svn/incubator/cc_campfire_notifier/campfire_notifier.rb
+ * "Home page": http://opensource.thinkrelevance.com/wiki/smoke_signals
+ * "git master": git://github.com/relevance/smoke_signals.git
* "CC.rb plugins documentation":http://cruisecontrolrb.thoughtworks.com/documentation/plugins
h2. LICENSE
View
89 smoke_signals.rb
@@ -0,0 +1,89 @@
+require 'tinder'
+
+class SmokeSignals
+ VERSION = 0.1
+ attr_accessor :room_name
+
+ def initialize(project = nil)
+ @project = project
+ end
+
+ def self.settings
+ YAML.load_file(File.join(RAILS_ROOT, "config", "smoke_signals.yml")) rescue nil
+ end
+
+ def settings
+ SmokeSignals.settings
+ end
+
+ def room
+ self.room_name ||= settings["room"]
+ return if room_name.nil?
+ logger.debug("Campfire Notifier configured with #{settings.inspect}")
+ campfire = Tinder::Campfire.new(settings["subdomain"], :ssl => settings["use_ssl"])
+ campfire.login settings["login"], settings["password"]
+ logger.debug("Logged in to campfire #{settings['subdomain']} as #{settings['login']}")
+ campfire.find_room_by_name(room_name)
+ rescue => e
+ logger.error("Trouble initalizing campfire room #{room_name}")
+ raise
+ end
+
+ def build_finished(build)
+ clear_flag
+ build_text = "Build #{build.label}"
+ build_text << (build.failed? ? " broken" : " successful")
+ build_text << "\nSee #{build.url} for details"
+ speak(build_text)
+ end
+
+ def build_fixed(build, previous_build=nil)
+ clear_flag
+ speak("Build fixed in #{build.label}")
+ end
+
+ def build_loop_failed(error)
+ return if flagged? && is_subversion_down?(error)
+ if is_subversion_down?(error)
+ speak "Build loop failed: Error connecting to Subversion: #{error.message}"
+ set_flag
+ else
+ speak( "Build loop failed with: #{error.class}: #{error.message}")
+ speak error.backtrace.join("\n")
+ end
+ end
+
+ def speak(message)
+ room.speak(message) unless room_name.nil?
+ rescue => e
+ logger.error("Error speaking into campfire room #{room_name}")
+ raise
+ end
+
+ def logger
+ CruiseControl::Log
+ end
+
+ def flagged?
+ File.exists?("#{@project.name}.svn_flag")
+ end
+
+ def set_flag
+ File.open("#{@project.name}.svn_flag","w") do |file|
+ file.puts "#{@project.name} subversion down"
+ end
+ end
+
+ def clear_flag
+ return unless flagged?
+ File.delete("#{@project.name}.svn_flag")
+ speak "Subversion is back"
+ end
+
+ def is_subversion_down?(error)
+ !(/(svn: PROPFIND request failed|apr_error)/.match(error.message).nil?)
+ end
+
+end
+
+Project.plugin :smoke_signals unless SmokeSignals.settings.nil?
View
5 smoke_signals.yml_sample
@@ -0,0 +1,5 @@
+subdomain: your_campfirenow_subdomain
+use_ssl: true_or_false
+login: the_login_to_use
+password: the_password
+room: the_room
View
62 test/smoke_signals_test.rb
@@ -0,0 +1,62 @@
+require 'rubygems'
+require File.dirname(__FILE__) + '/../smoke_signals'
+require 'rubygems'
+require 'mocha'
+require 'test/spec'
+
+describe "SmokeSignals" do
+ it "speaks when the build is fixed" do
+ notifier = SmokeSignals.new
+ build = stub(:label => "label")
+ notifier.expects(:speak).with("Build fixed in label")
+ notifier.expects(:clear_flag)
+ notifier.build_fixed(build)
+ end
+ it "speaks when the build is successful" do
+ notifier = SmokeSignals.new
+ build = stub(:label => "label", :failed? => false, :url => "http://cc.project.com/builds/Project/label")
+ notifier.expects(:speak).with("Build label successful\nSee http://cc.project.com/builds/Project/label for details")
+ notifier.expects(:clear_flag)
+ notifier.build_finished(build)
+ end
+ it "speaks when the build fails" do
+ notifier = SmokeSignals.new
+ build = stub(:label => "label", :failed? => true, :url => "http://cc.project.com/builds/Project/label")
+ notifier.expects(:speak).with("Build label broken\nSee http://cc.project.com/builds/Project/label for details")
+ notifier.expects(:clear_flag)
+ notifier.build_finished(build)
+ end
+ it "recognize apr_error as svn failures" do
+ notifier = SmokeSignals.new
+ notifier.is_subversion_down?(stub(:message => "apr_error=something")).should == true
+ end
+ it "recognize PROPFIND request failure as svn failures" do
+ notifier = SmokeSignals.new
+ notifier.is_subversion_down?(stub(:message => "svn: PROPFIND request failed|apr_error")).should == true
+ end
+ it "speaks when the build loop fails because of a subversion error" do
+ notifier = SmokeSignals.new
+ notifier.stubs(:flagged?).returns(false)
+ notifier.expects(:speak).with("Build loop failed: Error connecting to Subversion: svn: PROPFIND request failed")
+ notifier.expects(:is_subversion_down?).returns(true)
+ notifier.expects(:set_flag)
+ notifier.build_loop_failed(stub(:message => "svn: PROPFIND request failed"))
+ end
+ it "doesn't spam campfire when failing because it's not an svn error" do
+ notifier = SmokeSignals.new
+ notifier.stubs(:flagged?).returns(false)
+ notifier.expects(:speak).times(2)
+ notifier.expects(:is_subversion_down?).returns(false)
+ notifier.build_loop_failed(stub_everything(:backtrace => [:x, :y, :z, :a, :b]))
+ end
+ it "room is nil if room_name is nil" do
+ notifer = SmokeSignals.new
+ notifer.stubs(:settings).returns(stub_everything)
+ notifer.room_name = nil
+ notifer.room.should == nil
+ end
+ it "delegates settings to the class variable settings" do
+ SmokeSignals.stubs(:settings).returns(settings = stub)
+ SmokeSignals.new.settings.should == settings
+ end
+end

0 comments on commit c256cda

Please sign in to comment.