Sha256: cc21782a3bc114aae65a9ac1e7c891b480550eaf0c6be4976526eb52a0c2ba72

Contents?: true

Size: 1.08 KB

Versions: 3

Compression:

Stored size: 1.08 KB

Contents

require 'rexml/document'
require "open-uri"

# Checks the status of one or more project builds on a cruisecontrol.rb
# server.
# 
# == Example:
# 
#     if CruiseStatus.new( 'http://my.cruise.com/projects.rss' ).pass?
#       puts "Build passed!"
#     else
#       puts "Build failed…Boo!"
#     end
#
class CruiseStatus
  
  # feed_url::
  #   URL pointing to a cruise.rb RSS feed.
  #   Example: "http://my.cruise.com/projects.rss"
  #   or: "http://my.cruise.com/projects/myproject.rss""
  # 
  def initialize( feed_url )
    project_feed = Kernel.open( feed_url ).read
    @doc = REXML::Document.new project_feed
  rescue Exception => e
    @failures = [e.message]
    @doc = REXML::Document.new ""
  end
 
  # True if all builds described by the feed are passing.
  # 
  def pass?
    failures.empty?
  end
  
  # A list of failing builds.  Empty if all builds passed.
  # 
  def failures
    @failures ||= REXML::XPath.match( @doc, "//item/title" ).select { |element|
      element.text =~ /failed$/
    }.map do |element|
      element.text.gsub( /(.*) build (.+) failed$/, '\1' )
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
cruisestatus-1.1.5 lib/cruisestatus.rb
cruisestatus-1.1.3 lib/cruisestatus.rb
cruisestatus-1.1.2 lib/cruisestatus.rb