Last active
July 8, 2016 16:19
-
-
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
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
#!/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}%" |
Author
xymor
commented
Jul 8, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment