Skip to content

Instantly share code, notes, and snippets.

@JohnB
Last active December 26, 2015 00:48
Show Gist options
  • Save JohnB/7066490 to your computer and use it in GitHub Desktop.
Save JohnB/7066490 to your computer and use it in GitHub Desktop.
List your repositories and their collaborators
require 'json'
#
# List your repositories and their collaborators
#
# Before running this script, follow these steps:
# 1) get an OAuth token from https://github.com/settings/applications
# 2) add it to your environment with "export GW=abc123..."
# 3) add your github user to your environment (e.g. "export GWUSER=JohnB" is mine)
# 4) run this script via "ruby collabotators.rb"
#
# Canonical script location: https://gist.github.com/JohnB/7066490
class Collaborator
REPOS_URL = "https://api.github.com/users/#{ENV['GWUSER']}/repos"
def self.all
repos = fetch(REPOS_URL)
repos.map do |repo|
collaborators_url = repo["collaborators_url"][0..-16]
collaborator_data = fetch(collaborators_url)
collaborators = collaborator_data.map {|c| c["login"] }
"%s: %s" % [collaborators_url, collaborators.inspect]
end
end
def self.fetch(url)
puts "Fetching #{url}"
cmd = "curl -u #{ENV['GW']}:x-oauth-basic #{url} 2> /dev/null"
JSON.parse(`#{cmd}`)
end
end
puts "\n-----\n" + Collaborator.all.join("\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment