Last active
October 14, 2015 21:53
-
-
Save SteveMarshall/316808849ee857d4c21f to your computer and use it in GitHub Desktop.
Quick and dirty tool to get code stats from a github org using the API
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
source 'https://rubygems.org' | |
gem 'github_api' | |
gem 'awesome_print' | |
gem 'pry' |
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 'pp' | |
require 'github_api' | |
github = Github.new auto_pagination: true, oauth_token: ENV['GH_TOKEN'] | |
repos = github.repos.list user: 'ministryofjustice' | |
all_changes = repos.inject({}) do |result, repo| | |
puts repo.name | |
for i in 0..5 | |
changes = github.repos.stats.code_frequency(user: 'ministryofjustice', repo: repo.name) | |
total_changes = { additions: 0, deletions: 0 } | |
unless changes.body.empty? | |
total_changes = changes.body.inject(total_changes) do |result, week| | |
result[:additions] += week[1] | |
result[:deletions] += week[2] | |
result | |
end | |
end | |
break unless 0 == total_changes[:additions] | |
sleep i * i | |
end | |
pp total_changes | |
commits = github.repos.stats.participation( | |
user: 'ministryofjustice', repo: repo.name | |
) | |
unless commits.body.empty? | |
commits = commits.body.all.inject(0, &:+) | |
else | |
commits = 0 | |
end | |
pp commits | |
result[repo.name] = { | |
changes: total_changes, | |
commits_this_year: commits, | |
} | |
result | |
end | |
total_values = all_changes.values.inject({ | |
additions: 0, deletions: 0, commits_this_year: 0 | |
}) do |result, values| | |
result[:additions] += values[:changes][:additions] | |
result[:deletions] += values[:changes][:deletions] | |
result[:commits_this_year] += values[:commits_this_year] | |
result | |
end | |
pp total_values |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment