Skip to content

Instantly share code, notes, and snippets.

@andrew
Last active December 10, 2015 23:38
Show Gist options
  • Save andrew/4511005 to your computer and use it in GitHub Desktop.
Save andrew/4511005 to your computer and use it in GitHub Desktop.

Revisions

  1. andrew revised this gist Feb 3, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion leaderboard.rb
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@
    #
    # Get a leaderboard of contributions in your org
    #
    # usage: $ ENV=yourusername PASSWORD=yourpassword ORG=yourorgname ruby leaderboard.rb
    # usage: $ USERNAME=yourusername PASSWORD=yourpassword ORG=yourorgname ruby leaderboard.rb
    #
    # n.b requires the octokit and mechanize gems

  2. andrew created this gist Jan 11, 2013.
    41 changes: 41 additions & 0 deletions leaderboard.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,41 @@
    ## Contribution leaderboard
    #
    # Get a leaderboard of contributions in your org
    #
    # usage: $ ENV=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