Skip to content

Instantly share code, notes, and snippets.

@xymor
Last active July 8, 2016 16:19
Show Gist options
  • Save xymor/61153d8b3be627e51a85cf4f5f859335 to your computer and use it in GitHub Desktop.
Save xymor/61153d8b3be627e51a85cf4f5f859335 to your computer and use it in GitHub Desktop.
Ruby script that reads the bamboo build status and coverage metric to push them as a desktop notification
#!/usr/bin/env ruby
require 'net/http'
require 'rss'
require 'rexml/document'
project = "LASATESOURARIA-TESOURARIA"
username = 'user'
password = 'password'
def get_content(url)
uri = URI(url)
req = Net::HTTP::Get.new(uri)
req.basic_auth username, password
res = Net::HTTP.start(uri.hostname, uri.port) {|http|
http.request(req)
}
res.body
end
body = get_content("http://bamboo.b2w/rss/createAllBuildsRssFeed.action?feedType=rssAll&buildKey=#{project}&os_authType=basic")
latest = RSS::Parser.parse(body).items[0].title
body = get_content("http://bamboo.b2w/browse/#{project}/latest/artifact/JOB1/cobertura/coverage.xml")
percentage = (REXML::XPath.first(REXML::Document.new(body), "coverage").attributes["line-rate"].to_f * 100).round(0)
passing = (latest.include? "SUCCESSFUL") ? "✔" : "✖"
puts "#{passing} #{percentage}%"
@xymor
Copy link
Author

xymor commented Jul 8, 2016

notification

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment