Last active
September 4, 2015 03:02
-
-
Save handerson/6a4fd1e18f9b8446e53f to your computer and use it in GitHub Desktop.
Calculates an organization's average test coverage & gpa from codeclimate
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
require 'net/http' | |
require 'json' | |
token = '' | |
uri = URI('https://codeclimate.com/api/repos?api_token=' + token) | |
response = Net::HTTP.get(uri) | |
repos = JSON.parse(response) | |
test_coverage = [] | |
gpa = [] | |
print 'getting repos' | |
repos.each do |repo| | |
uri = URI("https://codeclimate.com/api/repos/#{repo['id']}?api_token=#{token}") | |
response = Net::HTTP.get(uri) | |
print '.' | |
next if response.nil? || response == '' | |
data = JSON.parse(response) | |
test_coverage << data['last_snapshot']['covered_percent'] | |
gpa << data['last_snapshot']['gpa'] | |
end | |
puts 'done' | |
print 'calculating averages' | |
with_test_coverage = test_coverage.compact | |
no_test_cov_count = test_coverage.length - with_test_coverage.length | |
avg_test_cov = with_test_coverage.reduce(:+) / with_test_coverage.length | |
avg_gpa = gpa.compact.reduce(:+) / gpa.length | |
puts 'done' | |
puts 'Avg. Test Coverage : ' + avg_test_cov.to_s | |
puts 'Avg. GPA : ' + avg_gpa.to_s | |
puts 'Repos without Test Cov Avg: ' + no_test_cov_count.to_s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment