Skip to content

Add bamboo RSS feed check type. #70

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ If you ever need to kill Checkman:
To get the PROJECT NAME, look at the CCTray XML and paste in the value before the ` :: ` from `<Project name="">`
To get the STEP NAME, look at the CCTray XML and paste in the value after the ` :: ` from `<Project name="">`

* `bamboo.check <BAMBOO_RSS_URL>`
Checks your Bamboo job status using the built in RSS feeds
e.g. `bamboo.check http://bamboo.mydomain.com/rss/createAllBuildsRssFeed.action?feedType=rssAll&buildKey=MYBUILDJOB`

Above scripts are located in `/Applications/Checkman.app/Contents/Resources/`.
Checkman makes these scripts available by appending stated path to PATH env
variable when running check commands.
Expand Down
56 changes: 56 additions & 0 deletions scripts/bamboo.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env ruby
require 'json'
require 'open-uri'
require 'webrick'
require 'nokogiri'

class BambooStatus
def initialize(rssUrl, rssFeed)
@rssUrl = rssUrl
@latest_build_title = rssFeed.xpath('/rss/channel/item/title').first.text
@latest_build_link = rssFeed.xpath('/rss/channel/item/link').first.text
@latest_build_description = rssFeed.xpath('/rss/channel/item/description').first

raise ArgumentError, 'nil response from bamboo' if rssFeed.nil?
end

def ok?
@latest_build_title.include?('was SUCCESSFUL')
end

def as_json(*)
{
:result => ok?,
:changing => false,
:rssUrl => @rssUrl,
:info => [
[:link, @latest_build_link],
[:title, @latest_build_title],
[:description, @latest_build_description]
]
}
end

def to_json(*)
JSON.dump(as_json)
end
end

class Bamboo
def initialize(rssUrl)
raise ArgumentError 'url must not be nil' unless @rssUrl = rssUrl
end

def latest_status
BambooStatus.new(@rssUrl, http_get_rss_feed(@rssUrl))
end

private

def http_get_rss_feed(rssUrl)
rss_feed_uri = URI(WEBrick::HTTPUtils.escape(rssUrl))
@rssFeed = Nokogiri::XML(open(rss_feed_uri))
end
end

puts Bamboo.new(*ARGV).latest_status.to_json if __FILE__ == $0
91 changes: 91 additions & 0 deletions scripts/specs/bamboo_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
$:.unshift(File.dirname(__FILE__))
require 'spec_helper'

describe_check :Bamboo, 'bamboo' do
bamboo_fail_xml = <<-XML
<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
<channel>
<title>Bamboo build results feed for the build</title>
<link>http://bamboo.local</link>
<description>This feed is updated whenever the build gets built</description>
<item>
<title>the build has FAILED : Updated by the developer</title>
<link>http://bamboo.local/browse/BUILD1</link>
<description>description of build</description>
<pubDate>Wed, 25 May 2016 09:47:15 GMT</pubDate>
<guid>http://bamboo.local/browse/BUILD1</guid>
<dc:date>2016-05-25T09:47:15Z</dc:date>
</item>
<item>
<title>the build was SUCCESSFUL : Updated by the developer</title>
<link>http://bamboo.local/browse/BUILD2</link>
<description>description of build</description>
<pubDate>Wed, 25 May 2016 09:47:15 GMT</pubDate>
<guid>http://bamboo.local/browse/BUILD2</guid>
<dc:date>2016-05-25T09:47:15Z</dc:date>
</item>
</channel>
</rss>
XML

bamboo_pass_xml = <<-XML
<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
<channel>
<title>Bamboo build results feed for the build</title>
<link>http://bamboo.local</link>
<description>This feed is updated whenever the build gets built</description>
<item>
<title>the build was SUCCESSFUL : Updated by the developer</title>
<link>http://bamboo.local/browse/BUILD2</link>
<description>description of build</description>
<pubDate>Wed, 25 May 2016 09:47:15 GMT</pubDate>
<guid>http://bamboo.local/browse/BUILD2</guid>
<dc:date>2016-05-25T09:47:15Z</dc:date>
</item>
<item>
<title>the build has FAILED : Updated by the developer</title>
<link>http://bamboo.local/browse/BUILD1</link>
<description>description of build</description>
<pubDate>Wed, 25 May 2016 09:47:15 GMT</pubDate>
<guid>http://bamboo.local/browse/BUILD1</guid>
<dc:date>2016-05-25T09:47:15Z</dc:date>
</item>
</channel>
</rss>
XML

before(:all) { WebMock.disable_net_connect! }
after(:all) { WebMock.allow_net_connect! }

before(:all) do
WebMock.stub_request(:get, 'http://bamboo.local/failedbuild.rss').
to_return(:status => 200, :body => bamboo_fail_xml, :headers => {})

WebMock.stub_request(:get, 'http://bamboo.local/passedbuild.rss').
to_return(:status => 200, :body => bamboo_pass_xml, :headers => {})
end

context 'when the first item in the feed shows was SUCCESSFUL' do
it_returns_ok %w(http://bamboo.local/passedbuild.rss)
end

context 'when the first item in the feed shows has FAILED' do
it_returns_fail %w(http://bamboo.local/failedbuild.rss)
end

context 'when showing build details, provides useful links' do
let(:opts) { %w(http://bamboo.local/passedbuild.rss) }

it 'returns an url to RSS feed' do
url = subject.latest_status.as_json[:rssUrl]
expect(url).to eq('http://bamboo.local/passedbuild.rss')
end

it 'returns an url that links directly to the bamboo build' do
link = subject.latest_status.as_json[:info][0][1]
expect(link).to eq('http://bamboo.local/browse/BUILD2');
end
end
end