Permalink
Browse files

Add code for twitter notifications

  • Loading branch information...
1 parent 6d3f2e2 commit a08179fade1fa605c6d46d58b789b12970c631b7 @gnufied committed Jan 25, 2010
Showing with 68 additions and 1 deletion.
  1. +2 −1 config/environment.rb
  2. +31 −0 lib/builder_plugins/twitter_notifier.rb
  3. +35 −0 test/unit/plugins/twitter_notifier_test.rb
@@ -16,6 +16,7 @@
# Settings in config/environments/* take precedence over those specified here
config.gem "xml-simple", :lib => "xmlsimple"
config.gem "mocha"
+ config.gem "twitter"
config.gem "rcov" if RUBY_VERSION != '1.8.7' && RUBY_VERSION !~ /^1.9/
def find_home
@@ -66,4 +67,4 @@ def find_home
FileUtils.rm_rf RAILS_ROOT + "/public/builds"
FileUtils.rm_rf RAILS_ROOT + "/public/documentation"
-BuilderPlugin.load_all
+BuilderPlugin.load_all
@@ -0,0 +1,31 @@
+require "twitter"
+
+class TwitterNotifier < BuilderPlugin
+ attr_accessor :username, :password
+ def initialize(project = nil)
+ @username = Configuration.twitter_username
+ @password = Configuration.twitter_password
+ end
+
+ def auth_info?
+ return false if(@username.blank? || @password.blank?)
+ true
+ end
+
+ def build_finished(build)
+ return if(!auth_info?)
+ twit(build, "#{build.project.name} build #{build.abbreviated_label} failed")
+ end
+
+ def build_fixed(build)
+ return if not !auth_info?
+ twit(build,"#{build.project.name} build #{build.abbreviated_label} fixed")
+ end
+
+ def twit(build, messsage)
+ twitter_auth_info = Twitter::HTTPAuth.new(@username,@password,:ssl => true)
+ client = Twitter::Base.new(twitter_auth_info)
+ client.update(messsage)
+ end
+end
+
@@ -0,0 +1,35 @@
+require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
+
+class TwitterNotifierTest < Test::Unit::TestCase
+ include FileSandbox
+ def setup
+ setup_sandbox
+ @project = Project.new("myproj")
+ @project.path = @sandbox.root
+ @build = Build.new(@project, 5)
+ @previous_build = Build.new(@project, 4)
+
+ @notifier = TwitterNotifier.new
+ @notifier.account = "foo"
+ @notifier.password = "bar"
+
+ @project.add_plugin(@notifier,:test_twitter_notifier)
+ end
+
+ def teardown
+ teardown_sandbox
+ end
+
+ def test_do_nothing_with_passing_build
+ @notifier.build_finished(@build)
+ end
+
+ def test_send_twit_when_build_failed
+
+ end
+
+ def test_send_twit_when_build_fixed
+
+ end
+end
+

0 comments on commit a08179f

Please sign in to comment.