Created
December 12, 2015 03:22
-
-
Save gesteves/1b3785986b0101ca9337 to your computer and use it in GitHub Desktop.
Prints commit/additions/deletions for each non-fork repo in a given Github organization for this year
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 'octokit' | |
class Github | |
def initialize(access_token) | |
Octokit.auto_paginate = true | |
@client = Octokit::Client.new(access_token: access_token) | |
end | |
def get_org_stats(org) | |
repos = @client.org_repos(org) | |
repos.reject! { |repo| repo.fork } | |
total_commits = 0 | |
total_additions = 0 | |
total_deletions = 0 | |
repos.each do |repo| | |
additions, deletions, commits = repo_stats(repo.full_name) | |
unless commits.nil? || commits == 0 | |
puts "#{repo.full_name}: #{commits} commits, #{additions} additions, #{deletions} deletions" | |
total_commits += commits | |
total_additions += additions | |
total_deletions += deletions | |
end | |
end | |
puts "" | |
puts "stats for #{org}: #{total_commits} commits, #{total_additions} additions, #{total_deletions} deletions" | |
end | |
def repo_stats(repo) | |
contributors = @client.contributor_stats(repo) | |
additions = 0 | |
deletions = 0 | |
commits = 0 | |
unless contributors.nil? || contributors == '' | |
contributors.each do |contributor| | |
new_years = Time.parse('01-01-2015').to_i | |
weeks = contributor.weeks.reject { |week| week.w.to_i < new_years } | |
additions += weeks.map(&:a).reduce(:+) | |
deletions += weeks.map(&:d).reduce(:+) | |
commits += weeks.map(&:c).reduce(:+) | |
end | |
return additions, deletions, commits | |
end | |
end | |
end | |
github = Github.new('put yer access token here') | |
github.get_org_stats('put yer org name here') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment