forked from jzoldak/edx-eng-dashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jay Zoldak
committed
Mar 5, 2014
1 parent
931546a
commit e2a533c
Showing
2 changed files
with
69 additions
and
40 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
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
require 'open-uri' | ||
require 'openssl' | ||
require 'json' | ||
|
||
# :first_in sets how long it takes before the job is first run. In this case, it is run immediately | ||
SCHEDULER.every '5m', :first_in => 0 do |job| | ||
|
||
# Retrieve the number of the last stable build | ||
last_build_uri = JENKINS_JOB_URL + '/lastStableBuild/buildNumber' | ||
|
||
# Once SSL certificates are set up correctly, we can remove the :ssl_verify_mode option | ||
response = open(last_build_uri, :ssl_verify_mode=>OpenSSL::SSL::VERIFY_NONE).read | ||
last_build_num = response.to_i | ||
|
||
# Retrieve the coverage info as JSON | ||
coverage_uri = JENKINS_JOB_URL + "/SHARD=1,TEST_SUITE=bok-choy/#{last_build_num}/cobertura/_default_/api/json?depth=2" | ||
coverage_data = open(coverage_uri, :ssl_verify_mode=>OpenSSL::SSL::VERIFY_NONE).read | ||
|
||
# Parse the JSON | ||
json = JSON.parse(coverage_data) | ||
result_elements = json["results"]["elements"] | ||
|
||
line_coverage = nil | ||
result_elements.each do |result| | ||
# Result is a hash with keys 'ratio' and 'name' | ||
# We're looking for the name 'Lines' | ||
if result['name'] == 'Lines' | ||
line_coverage = result['ratio'].to_i | ||
end | ||
end | ||
|
||
send_event('bok_coverage', { value: line_coverage }) | ||
end |