Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Version bump to 0.0.0

  • Loading branch information...
commit 20a03e41117a50cf4df8f3c6d7b16993a83abae6 1 parent 7648f44
Darrin Holst authored
4 Rakefile
View
@@ -5,12 +5,14 @@ begin
require 'jeweler'
Jeweler::Tasks.new do |gem|
gem.name = "build-lights"
+ gem.executables = "buildlights"
gem.summary = %Q{build monitor that will trigger lights via x10}
gem.email = "darrinholst@gmail.com"
gem.homepage = "http://github.com/darrinholst/build-lights"
gem.authors = ["Darrin Holst"]
gem.rubyforge_project = "build-lights"
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
+ gem.add_dependency("simple-rss", ">= 1.2")
+ gem.add_dependency("hpricot", ">= 0.8.1")
end
Jeweler::RubyforgeTasks.new
1  VERSION
View
@@ -0,0 +1 @@
+0.0.0
1  bin/buildlights.rb
View
@@ -0,0 +1 @@
+puts "here"
15 lib/bottle_rocket.rb
View
@@ -0,0 +1,15 @@
+class BottleRocket
+ def self.turn_on(unit, house='A')
+ send('on', unit, house)
+ end
+
+ def self.turn_off(unit, house='A')
+ send('off', unit, house)
+ end
+
+ private
+
+ def self.send(command, unit, house)
+ puts `br -v --house=#{house} --#{command}=#{unit}`
+ end
+end
0  lib/build-lights.rb
View
No changes.
13 lib/ccnet_xml_scanner.rb
View
@@ -0,0 +1,13 @@
+require 'xml_parser'
+
+class CcNetXmlScanner
+ def initialize(uri, parser = XmlParser)
+ @doc = parser.parse(uri)
+ end
+
+ def failed_jobs
+ @doc.search(:Project).map do |project|
+ project[:name] if project[:lastBuildStatus] =~ /FAIL/i
+ end.compact
+ end
+end
8 lib/feed_parser.rb
View
@@ -0,0 +1,8 @@
+require 'simple-rss'
+require 'open-uri'
+
+class FeedParser
+ def self.parse(uri)
+ SimpleRSS.parse(open(uri))
+ end
+end
15 lib/hudson_feed_scanner.rb
View
@@ -0,0 +1,15 @@
+require 'feed_parser'
+
+class HudsonFeedScanner
+ def initialize(uri, parser = FeedParser)
+ @feed = parser.parse uri
+ end
+
+ def failed_jobs
+ @feed.entries.each.map do |entry|
+ match = /(.*) #\d+ (.*)/.match(entry.title)
+ raise "Invalid rss title #{entry.title}" unless match
+ match[1] if /FAIL/i.match(match[2])
+ end.compact
+ end
+end
20 lib/lights.rb
View
@@ -0,0 +1,20 @@
+require 'bottle_rocket'
+
+class Lights
+ GREEN = 1
+ RED = 2
+
+ def initialize(implementation = BottleRocket)
+ @implementation = implementation
+ end
+
+ def success
+ @implementation.turn_on GREEN
+ @implementation.turn_off RED
+ end
+
+ def failed
+ @implementation.turn_on RED
+ @implementation.turn_off GREEN
+ end
+end
8 lib/xml_parser.rb
View
@@ -0,0 +1,8 @@
+require 'hpricot'
+require 'open-uri'
+
+class XmlParser
+ def self.parse(uri)
+ Hpricot::XML(open(uri))
+ end
+end
7 test/build-lights_test.rb
View
@@ -1,7 +0,0 @@
-require 'test_helper'
-
-class BuildLightsTest < Test::Unit::TestCase
- def test_something_for_real
- flunk "hey buddy, you should probably rename this file and start testing for real"
- end
-end
48 test/ccnet_xml_scanner_test.rb
View
@@ -0,0 +1,48 @@
+require 'test_helper'
+require 'ccnet_xml_scanner'
+
+class CcNetXmlScannerTest < Test::Unit::TestCase
+ URI = "some uri"
+
+ def test_failed_jobs
+ parser = parser_for(URI, ["job 1", "Failed"], ["job 2", "Failed"])
+ scanner = CcNetXmlScanner.new(URI, parser)
+ assert_equal(["job 1", "job 2"], scanner.failed_jobs)
+ end
+
+ def test_successful_jobs
+ parser = parser_for(URI, ["job 1", "Success"], ["job 2", "Success"])
+ scanner = CcNetXmlScanner.new(URI, parser)
+ assert_equal([], scanner.failed_jobs)
+ end
+
+ def test_mixed_jobs
+ parser = parser_for(URI, ["job 1", "Success"], ["job 2", "Failed"])
+ scanner = CcNetXmlScanner.new(URI, parser)
+ assert_equal(["job 2"], scanner.failed_jobs)
+ end
+
+ def test_mixed_case
+ parser = parser_for(URI, ["job 1", "FAILED"], ["job 2", "SUCCESS"], ["job 3", "FAIL"])
+ scanner = CcNetXmlScanner.new(URI, parser)
+ assert_equal(["job 1", "job 3"], scanner.failed_jobs)
+ end
+
+ private
+
+ def parser_for(uri, *jobs)
+ projects = jobs.map do |j|
+ project = mock()
+ project.stubs(:[]).with(:name).returns(j[0])
+ project.stubs(:[]).with(:lastBuildStatus).returns(j[1])
+ project
+ end
+
+ doc = mock()
+ doc.expects(:search).with(:Project).returns(projects)
+
+ parser = mock()
+ parser.expects(:parse).with(uri).returns(doc)
+ parser
+ end
+end
39 test/hudson_feed_scanner_test.rb
View
@@ -0,0 +1,39 @@
+require 'test_helper'
+require 'hudson_feed_scanner'
+
+class HudsonFeedScannerTest < Test::Unit::TestCase
+ URI = "some uri"
+
+ def test_all_successful
+ parser = feed_parser_for(URI, "job 1 #1 (SUCCESS)", "job 2 #1 (SUCCESS)")
+ scanner = HudsonFeedScanner.new(URI, parser)
+ assert_equal([], scanner.failed_jobs)
+ end
+
+ def test_all_failed
+ parser = feed_parser_for(URI, "job 1 #1 (FAILED)", "job 2 #1 (FAILED)")
+ scanner = HudsonFeedScanner.new(URI, parser)
+ assert_equal(['job 1', 'job 2'], scanner.failed_jobs)
+ end
+
+ def test_mixed
+ parser = feed_parser_for(URI, "job 1 #1 (SUCCESS)", "job 2 #1 (FAILED)", "job 3 #1 (SUCCESS)")
+ scanner = HudsonFeedScanner.new(URI, parser)
+ assert_equal(['job 2'], scanner.failed_jobs)
+ end
+
+ def test_mixed_with_lower_case
+ parser = feed_parser_for(URI, "job 1 #1 (success)", "job 2 #1 (failed)", "job 3 #1 (success)")
+ scanner = HudsonFeedScanner.new(URI, parser)
+ assert_equal(['job 2'], scanner.failed_jobs)
+ end
+
+ private
+
+ def feed_parser_for(uri, *titles)
+ entries = stub(:entries => titles.map {|t| stub(:title => t)})
+ parser = mock()
+ parser.expects(:parse).with(uri).returns(entries)
+ parser
+ end
+end
20 test/lights_test.rb
View
@@ -0,0 +1,20 @@
+require 'test_helper'
+require 'lights'
+
+class LightsTest < Test::Unit::TestCase
+ def test_successful_builds
+ impl = mock()
+ impl.expects(:turn_on).with(1)
+ impl.expects(:turn_off).with(2)
+
+ Lights.new(impl).success
+ end
+
+ def test_failed_builds
+ impl = mock()
+ impl.expects(:turn_on).with(2)
+ impl.expects(:turn_off).with(1)
+
+ Lights.new(impl).failed
+ end
+end
2  test/test_helper.rb
View
@@ -1,9 +1,9 @@
require 'rubygems'
require 'test/unit'
+require 'mocha'
$LOAD_PATH.unshift(File.dirname(__FILE__))
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
-require 'build-lights'
class Test::Unit::TestCase
end
Please sign in to comment.
Something went wrong with that request. Please try again.