Index: app/controllers/status_controller.rb =================================================================== --- app/controllers/status_controller.rb (revision 191) +++ app/controllers/status_controller.rb (working copy) @@ -1,8 +1,14 @@ class StatusController < ApplicationController # TODO: Investigate whether generation of XML # of projects can be done in controller to allow testing - def projects + def cctray @url = url_for(:controller => 'projects', :action => 'index') @projects = Projects.load_all end + + def rss + rss = load_projects.as_rss() + render :text => "#{rss.to_s}" + end + end \ No newline at end of file Index: app/models/project.rb =================================================================== --- app/models/project.rb (revision 191) +++ app/models/project.rb (working copy) @@ -259,6 +259,19 @@ File.join(path, 'build_requested') end + def as_rss(maker) + item = maker.items.new_item + item.link = "???" + item.date = Time.now + if builds.empty? + item.title = "#{name} has never been built" + item.description = "no changesets" + else + item.title = "#{name} build #{last_build.label} #{last_build_status} at #{last_build.time.strftime('%Y-%m-%d %H:%M:%S')}." + item.description = last_build.changeset + end + end + private # sorts a array of builds in order of revision number and rebuild number def order_by_label(builds) Index: app/models/projects.rb =================================================================== --- app/models/projects.rb (revision 191) +++ app/models/projects.rb (working copy) @@ -1,4 +1,5 @@ require 'fileutils' +require 'rss/maker' class Projects @@ -55,6 +56,22 @@ project.source_control.checkout work_dir end + def as_rss + version = "2.0" + rss = RSS::Maker.make(version) do |maker| + maker.channel.title = "CruiseControl RSS feed" + maker.channel.link = "???" + maker.channel.description = "CruiseControl projects and their statuses" + maker.items.do_sort = true # sort items by date + self.each do |project| + project.as_rss(maker) + end + end + + rss + end + + # delegate everything else to the underlying @list def method_missing(method, *args, &block) @list.send(method, *args, &block) Index: config/routes.rb =================================================================== --- config/routes.rb (revision 191) +++ config/routes.rb (working copy) @@ -34,5 +34,9 @@ map.connect ':controller/:action/:id' # Route for CCTray.NET - map.connect 'XmlStatusReport.aspx', :controller => 'status', :action => 'projects' + map.connect 'XmlStatusReport.aspx', :controller => 'status', :action => 'cctray' + + # Route for RSS feed + map.connect 'rss', :controller => 'status', :action => 'rss' + end Index: test/unit/project_test.rb =================================================================== --- test/unit/project_test.rb (revision 191) +++ test/unit/project_test.rb (working copy) @@ -1,6 +1,7 @@ require 'date' require File.expand_path(File.dirname(__FILE__) + '/../test_helper') require 'email_notifier' +require 'rss/maker' class ProjectTest < Test::Unit::TestCase include FileSandbox @@ -359,6 +360,19 @@ Build.expects(:new).with(project, '2').returns(new_build) project.build([new_revision(2)]) end + + def test_as_rss + build = stub_build('20') + project = Project.new('project_name', @svn) + project.stubs(:builds).returns([build]) + + rss = RSS::Maker.make("2.0") do |maker| + project.as_rss(maker) + assert_equal "project_name build 20 success at 2006-08-31 18:20:44.", maker.items.first.title + assert_equal "bobby checked something in", maker.items.first.description + end + end + private @@ -367,6 +381,9 @@ build.stubs(:label).returns(label) build.stubs(:artifacts_directory).returns("project1/build_#{label}") build.stubs(:run) + build.stubs(:status).returns("success") + build.stubs(:time).returns(Time.parse("Aug 31, 2006 18:20:44")) + build.stubs(:changeset).returns("bobby checked something in") build end Index: test/unit/projects_test.rb =================================================================== --- test/unit/projects_test.rb (revision 191) +++ test/unit/projects_test.rb (working copy) @@ -100,13 +100,25 @@ in_sandbox do |sandbox| projects = Projects.new(sandbox.root) projects << @one << @two - + out = "" projects.each do |project| out << project.name end - + assert_equal("onetwo", out) end end + + def test_as_rss + in_sandbox do |sandbox| + projects = Projects.new(sandbox.root) + projects << @one << @two + + rss = projects.as_rss + assert_equal rss.channel.title, "CruiseControl RSS feed" + assert_equal rss.items.length, 2 + end + end + end \ No newline at end of file