Last active
December 26, 2015 00:48
-
-
Save JohnB/7066490 to your computer and use it in GitHub Desktop.
List your repositories and their collaborators
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
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