Last active
December 10, 2015 23:38
-
-
Save andrew/4511005 to your computer and use it in GitHub Desktop.
Get a leaderboard of contributions in your GitHub organization
This file contains hidden or 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
## Contribution leaderboard | |
# | |
# Get a leaderboard of contributions in your org | |
# | |
# usage: $ USERNAME=yourusername PASSWORD=yourpassword ORG=yourorgname ruby leaderboard.rb | |
# | |
# n.b requires the octokit and mechanize gems | |
require 'rubygems' | |
require 'octokit' | |
require 'mechanize' | |
USERNAME = ENV['USERNAME'] | |
PASSWORD = ENV['PASSWORD'] | |
ORG = ENV['ORG'] | |
client = Octokit::Client.new(:login => USERNAME, :password => PASSWORD, :auto_traversal => true) | |
users = client.org_members(ORG).map(&:login) | |
a = Mechanize.new { |agent| agent.user_agent_alias = 'Mac Safari' } | |
# comment this block out for open source contributions only | |
a.get('http://github.com/login') do |login_page| | |
login_page.form_with(:action => '/session') do |f| | |
f.login = ENV['USERNAME'] | |
f.password = ENV['PASSWORD'] | |
end.click_button | |
end | |
leaderboard = [] | |
users.each do |u| | |
page = a.get("http://github.com/#{u}") | |
total = page.search('.contrib-day .num').text.match(/([\d,]+)/)[1].delete(',').to_i | |
leaderboard << [u, total] | |
end | |
leaderboard.sort_by{|u| u[1] }.reverse.each do |u| | |
puts "#{u[0]} - #{u[1]}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Very cool! I think the usage section is slightly wrong, it should be:
❤️