Skip to content

Instantly share code, notes, and snippets.

@handerson
Last active September 4, 2015 03:02
Show Gist options
  • Save handerson/6a4fd1e18f9b8446e53f to your computer and use it in GitHub Desktop.
Save handerson/6a4fd1e18f9b8446e53f to your computer and use it in GitHub Desktop.
Calculates an organization's average test coverage & gpa from codeclimate
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