Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote branch 'iconoclast/master'
- Loading branch information
Showing
3 changed files
with
33 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,8 @@ publisher: | |
on_event: | ||
rss: | ||
file: | ||
channel_link: | ||
keep: | ||
on_event: | ||
campfire: | ||
url: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,41 @@ | ||
require 'cerberus/publisher/base' | ||
require 'time' | ||
require 'builder' | ||
require 'rss' | ||
|
||
class Cerberus::Publisher::RSS < Cerberus::Publisher::Base | ||
def self.publish(state, manager, options) | ||
config = options[:publisher, :rss] | ||
subject,body = Cerberus::Publisher::Base.formatted_message(state, manager, options) | ||
|
||
pub_date = Time.now.iso8601 | ||
description = "<pre>#{body}</pre>".to_xs | ||
result = <<-END | ||
<rss version="2.0"> | ||
<channel> | ||
<title>Cerberus build feed for #{options[:application_name].to_xs}</title> | ||
<pubDate>#{pub_date}</pubDate> | ||
<generator>http://rubyforge.org/projects/cerberus</generator> | ||
<item> | ||
<title>#{subject.to_xs}</title> | ||
<pubDate>#{pub_date}</pubDate> | ||
<description>#{description}</description> | ||
</item> | ||
</channel> | ||
</rss> | ||
END | ||
pub_date = Time.now | ||
|
||
IO.write(config[:file], result) | ||
begin | ||
feed = RSS::Parser.parse(File.read(config[:file]), false) | ||
raise RSS::Error unless feed | ||
keep = config[:keep] || 1 | ||
feed.items.slice!(keep -1 ..-1) # one less than keep value, to make room for the new build | ||
rescue RSS::Error, Errno::ENOENT | ||
# if there's no existing file or we can't parse it, start a new one from scratch | ||
feed = RSS::Maker.make("2.0") do |new_rss| | ||
new_rss.channel.title = "#{options[:application_name].to_xs} build status" | ||
new_rss.channel.description = "Cerberus build feed for #{options[:application_name].to_xs}" | ||
new_rss.channel.generator = "http://rubyforge.org/projects/cerberus" | ||
new_rss.channel.link = config[:channel_link] || "file://#{config[:file]}" | ||
end | ||
end | ||
|
||
# update channel link if we have it explicitly set, otherwise retain existing value | ||
feed.channel.link = config[:channel_link] unless config[:channel_link].nil? | ||
feed.channel.pubDate = pub_date | ||
|
||
new_item = RSS::Rss::Channel::Item.new() | ||
new_item.title = subject | ||
new_item.pubDate = pub_date | ||
new_item.description = "<pre>#{body}</pre>" | ||
|
||
feed.items.unshift new_item | ||
|
||
IO.write(config[:file], feed) | ||
end | ||
end |