cruisestatus 1.1.6 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.6
1
+ 1.2.0
data/bin/cruisestatus CHANGED
@@ -1,25 +1,6 @@
1
1
  #!/usr/bin/env ruby -wKU
2
2
  $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
3
3
  require "cruisestatus"
4
+ require "cruisestatus/command"
4
5
 
5
- unless ARGV.size == 1
6
- $stderr.puts <<-EOS
7
- cruisestatus: RSS feed url required.
8
- Usage: cruisestatus CRUISE_RB_RSS_URL
9
-
10
- Reads the feed at CRUISE_RB_RSS_URL and reports if the build[s] passed.
11
-
12
- Example: cruisestatus http://my.cruiseserver.com/projects.rss
13
-
14
- EOS
15
- exit 1
16
- end
17
-
18
- status = CruiseStatus.new ARGV.first
19
-
20
- unless status.pass?
21
- abort "FAIL: #{status.failures.join( ', ' )}"
22
- else
23
- puts "OK"
24
- exit 0
25
- end
6
+ exit CruiseStatus::Command.run!( ARGV )
data/cruisestatus.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{cruisestatus}
8
- s.version = "1.1.6"
8
+ s.version = "1.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Toby Tripp"]
12
- s.date = %q{2010-01-23}
12
+ s.date = %q{2010-01-24}
13
13
  s.default_executable = %q{cruisestatus}
14
14
  s.description = %q{Allows scripts and applications to check the status of your project's build.}
15
15
  s.email = %q{toby.tripp+git@gmail.com}
@@ -28,6 +28,8 @@ Gem::Specification.new do |s|
28
28
  "bin/cruisestatus",
29
29
  "cruisestatus.gemspec",
30
30
  "lib/cruisestatus.rb",
31
+ "lib/cruisestatus/command.rb",
32
+ "spec/cruisestatus/command_spec.rb",
31
33
  "spec/cruisestatus_spec.rb",
32
34
  "spec/spec.opts",
33
35
  "spec/spec_helper.rb"
@@ -38,7 +40,8 @@ Gem::Specification.new do |s|
38
40
  s.rubygems_version = %q{1.3.5}
39
41
  s.summary = %q{Check the build status on a cruise.rb server}
40
42
  s.test_files = [
41
- "spec/cruisestatus_spec.rb",
43
+ "spec/cruisestatus/command_spec.rb",
44
+ "spec/cruisestatus_spec.rb",
42
45
  "spec/spec_helper.rb"
43
46
  ]
44
47
 
@@ -0,0 +1,52 @@
1
+ require "readline"
2
+ require "optparse"
3
+
4
+ class CruiseStatus::Command
5
+ DEFAULT_PROMPT = "Are you sure you want to check in? (y/n): "
6
+
7
+ def self.run!( argv )
8
+ @prompt = nil
9
+
10
+ opts = OptionParser.new do |o|
11
+ o.banner = <<-EOS
12
+ Usage: #{File.basename($0)} [options] CRUISE_RB_RSS_URL
13
+
14
+ Reads the feed at CRUISE_RB_RSS_URL and reports if the build[s] passed.
15
+
16
+ Examples:
17
+ #{File.basename($0)} http://my.cruiseserver.com
18
+ #{File.basename($0)} http://my.cruiseserver.com/projects.rss
19
+ #{File.basename($0)} http://my.cruiseserver.com/projects/myproject.rss
20
+
21
+ EOS
22
+
23
+ o.on( "-p", "--prompt" ) { |val| @prompt = DEFAULT_PROMPT }
24
+ end
25
+
26
+ opts.parse! argv
27
+
28
+ if argv.empty?
29
+ abort opts.banner
30
+ else
31
+ status = CruiseStatus.new argv.last
32
+
33
+ if status.pass?
34
+ puts "Build PASSED"
35
+ 0
36
+ else
37
+ return are_you_sure?( status ) if @prompt
38
+ 1
39
+ end
40
+ end
41
+ end
42
+
43
+ def self.are_you_sure?( status )
44
+ puts "\n", "Build FAILURES: #{status.failure_message}"
45
+ input = ""
46
+ while( input.strip.empty? )
47
+ input = Readline.readline @prompt
48
+ end
49
+
50
+ input.strip.downcase[0,1] == "y" ? 0 : 1
51
+ end
52
+ end
data/lib/cruisestatus.rb CHANGED
@@ -13,12 +13,27 @@ require "open-uri"
13
13
  # end
14
14
  #
15
15
  class CruiseStatus
16
+ attr_reader :feed_url
17
+
16
18
  # feed_url::
17
19
  # URL pointing to a cruise.rb RSS feed.
18
20
  # Example: "http://my.cruise.com/projects.rss"
19
21
  # or: "http://my.cruise.com/projects/myproject.rss""
20
22
  #
21
23
  def initialize( feed_url )
24
+ self.feed_url = feed_url
25
+ check
26
+ end
27
+
28
+ # Check the given cruise feed and return true if all builds have passed.
29
+ # False otherwise.
30
+ def self.check( feed_url )
31
+ new( feed_url ).pass?
32
+ end
33
+
34
+ # Update build status
35
+ #
36
+ def check
22
37
  project_feed = Kernel.open( feed_url ).read
23
38
  @doc = REXML::Document.new project_feed
24
39
  rescue Exception => e
@@ -41,4 +56,13 @@ class CruiseStatus
41
56
  element.text.gsub( /(.*) build (.+) failed$/, '\1' )
42
57
  end
43
58
  end
59
+
60
+ def failure_message
61
+ self.failures.join ", "
62
+ end
63
+
64
+ def feed_url=( url )
65
+ @feed_url = url
66
+ @feed_url += '/projects.rss' unless url =~ /\.rss$/
67
+ end
44
68
  end
@@ -0,0 +1,74 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe CruiseStatus::Command do
4
+ before :each do
5
+ @status = mock( "cruisestatus" )
6
+ @status.stub!( :pass? ).and_return true
7
+ @status.stub!( :failure_message ).and_return "FAILURES"
8
+
9
+ CruiseStatus.stub!( :new ).with( "url" ).and_return @status
10
+ end
11
+
12
+ it "passes the given url to the cruise status checker" do
13
+ CruiseStatus.should_receive( :new ).with "url"
14
+ CruiseStatus::Command.run! ["url"]
15
+ end
16
+
17
+ it "returns 0 if the builds have passed" do
18
+ @status.should be_pass
19
+ CruiseStatus::Command.run!( ["url"] ).should == 0
20
+ end
21
+
22
+ it "returns 1 if the builds have failed" do
23
+ @status.should_receive( :pass? ).and_return false
24
+ CruiseStatus::Command.run!( ["url"] ).should == 1
25
+ end
26
+
27
+ it "aborts if no url is provided" do
28
+ CruiseStatus::Command.should_receive( :abort )
29
+ CruiseStatus::Command.run! []
30
+ end
31
+
32
+
33
+ describe "when given the 'prompt' option" do
34
+ before :each do
35
+ @status.stub!( :pass? ).and_return false
36
+ end
37
+
38
+ it "passes the url to the status checker" do
39
+ Readline.should_receive( :readline ).
40
+ with( CruiseStatus::Command::DEFAULT_PROMPT ).
41
+ and_return "y"
42
+
43
+ CruiseStatus::Command.run! %w[-p url]
44
+ end
45
+
46
+ it "prompts the user if the build has failed" do
47
+ Readline.should_receive( :readline ).
48
+ with( CruiseStatus::Command::DEFAULT_PROMPT ).
49
+ and_return "y"
50
+
51
+ output = capture_stdout do
52
+ CruiseStatus::Command.run! %w[-p url]
53
+ end
54
+
55
+ output.should == "\nBuild FAILURES: FAILURES\n"
56
+ end
57
+
58
+ it "returns 0 if the user enters 'y' at the prompt" do
59
+ Readline.should_receive( :readline ).
60
+ with( CruiseStatus::Command::DEFAULT_PROMPT ).
61
+ and_return "y"
62
+
63
+ CruiseStatus::Command.run!( %w[-p url] ).should == 0
64
+ end
65
+
66
+ it "returns 1 if the user enters 'n' at the prompt" do
67
+ Readline.should_receive( :readline ).
68
+ with( CruiseStatus::Command::DEFAULT_PROMPT ).
69
+ and_return "n"
70
+
71
+ CruiseStatus::Command.run!( %w[-p url] ).should == 1
72
+ end
73
+ end
74
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,10 +1,18 @@
1
1
  $LOAD_PATH.unshift(File.dirname(__FILE__))
2
2
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
3
  require 'cruisestatus'
4
+ require 'cruisestatus/command'
4
5
 
5
6
  require "rubygems"
6
7
  require 'spec'
7
8
  require 'spec/autorun'
8
9
 
9
10
  Spec::Runner.configure do |config|
11
+ def capture_stdout(&block)
12
+ old_stdout, $stdout = $stdout, StringIO.new
13
+ yield
14
+ $stdout.string
15
+ ensure
16
+ $stdout = old_stdout
17
+ end
10
18
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cruisestatus
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.6
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Toby Tripp
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-23 00:00:00 -06:00
12
+ date: 2010-01-24 00:00:00 -06:00
13
13
  default_executable: cruisestatus
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -41,6 +41,8 @@ files:
41
41
  - bin/cruisestatus
42
42
  - cruisestatus.gemspec
43
43
  - lib/cruisestatus.rb
44
+ - lib/cruisestatus/command.rb
45
+ - spec/cruisestatus/command_spec.rb
44
46
  - spec/cruisestatus_spec.rb
45
47
  - spec/spec.opts
46
48
  - spec/spec_helper.rb
@@ -73,5 +75,6 @@ signing_key:
73
75
  specification_version: 3
74
76
  summary: Check the build status on a cruise.rb server
75
77
  test_files:
78
+ - spec/cruisestatus/command_spec.rb
76
79
  - spec/cruisestatus_spec.rb
77
80
  - spec/spec_helper.rb