-
-
Save chrismytton/4518181 to your computer and use it in GitHub Desktop.
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: $ env USERNAME=yourusername PASSWORD=yourpassword ORG=yourorgname ruby leaderboard.rb | |
require 'uri' | |
require 'net/https' | |
require 'json' | |
USERNAME = ENV['USERNAME'] | |
PASSWORD = ENV['PASSWORD'] | |
ORG = ENV['ORG'] | |
unless USERNAME && PASSWORD && ORG | |
puts File.readlines(__FILE__).select { |l| l =~ /^#\//i }.map { |s| s[3..-1] } | |
exit 1 | |
end | |
def get(url) | |
uri = URI.parse(url) | |
http = Net::HTTP.new(uri.host, uri.port) | |
if uri.scheme == 'https' | |
http.use_ssl = true | |
http.verify_mode = OpenSSL::SSL::VERIFY_PEER | |
end | |
request = Net::HTTP::Get.new(uri.request_uri) | |
request.basic_auth(USERNAME, PASSWORD) | |
response = http.request(request) | |
JSON.parse(response.body) | |
end | |
members = get("https://api.github.com/orgs/#{ORG}/members").map { |m| m['login'] } | |
leaderboard = members.map do |u| | |
user_stats = get("https://github.com/users/#{u}/contributions_calendar_data") | |
total = user_stats.map { |s| s[1] }.reduce(&:+) | |
[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