Created
January 19, 2015 15:18
-
-
Save davehunt/de9b4bf7c5028bb9a114 to your computer and use it in GitHub Desktop.
Octokit.rb script to generate repositories and members for Web QA's teams
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 'colorize' | |
require 'octokit' | |
Octokit.auto_paginate = true | |
client = Octokit::Client.new(:access_token => "") | |
teams = { | |
261214 => 'Web QA Enthusiasts', | |
26107 => 'Web QA Apprentices', | |
1229240 => 'Web QA Sorcerers' | |
} | |
teams.keys.each { |t| | |
puts 'Team: '.yellow + client.team(t).name | |
now = Time.now.to_i | |
last_year = (now - 365 * 24 * 60 * 60) | |
active_contributors = Hash.new | |
puts 'Repositories:'.green | |
client.team_repos(t).each_with_index { |r, i| | |
puts (i + 1).to_s.blue + '. '.blue + r.full_name | |
stats = client.contributors_stats(r.id) | |
if stats.nil? | |
sleep(5.0) | |
stats = client.contributors_stats(r.id) | |
end | |
stats.each{ |s| | |
s.weeks.each { |w| | |
if w.w > last_year && w.c > 0 | |
contributions = active_contributors.fetch(s.author.id, 0) | |
active_contributors[s.author.id] = contributions + w.c | |
end | |
} | |
} | |
} | |
puts 'Active contributors:'.green | |
count = 1 | |
active_contributors.sort_by { |k, v| v }.reverse.each { |ac, c| | |
u = client.user(ac) | |
n = (u.name.nil? || u.name.empty? ? u.login : u.name) | |
in_team = (client.team_member?(t, u.login) ? 'member' : 'non-member') | |
puts (count).to_s.blue + '. '.blue + '%s (%s) - %d contribution(s) - %s' %[n, u.login, c, in_team] | |
count += 1 | |
} | |
puts 'Members:'.green | |
client.team_members(t).each_with_index { |m, i| | |
u = client.user(m.id) | |
n = (u.name.nil? || u.name.empty? ? u.login : u.name) | |
status = (active_contributors.keys.include?(m.id) ? 'active' : 'inactive') | |
puts (i + 1).to_s.blue + '. '.blue + '%s (%s) - %s' %[n, u.login, status] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment