Last active
May 3, 2016 17:18
-
-
Save tyrelsouza/9687573 to your computer and use it in GitHub Desktop.
Get all repositories
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
#!/usr/bin/env ruby | |
require 'highline/import' | |
require 'io/console' | |
require 'octokit' | |
# Return true or false if the directory exists | |
def directory_exists?(directory) | |
File.directory?(directory) | |
end | |
def get_repos | |
repos = {} | |
username = ask("Username: ") | |
Octokit.auto_paginate = true | |
client = Octokit::Client.new(:access_token => "API KEY PLZ") | |
# get personal repos | |
personal_repos = [] | |
client.repos.each do |repo| | |
if repo[:owner][:login] == username | |
puts "Adding #{repo[:name]}" | |
personal_repos << {:url=> "[email protected]:#{repo[:full_name]}.git", | |
:full_name => repo[:full_name], | |
:name => repo[:name]} | |
end | |
end | |
repos[username] = personal_repos | |
return repos | |
end | |
# Execute the code to get repos and clone them. | |
def main | |
repos = get_repos() | |
repos.each do |org, data| | |
data.each do |repo| | |
if not directory_exists?(repo[:full_name]) | |
cmd = "git clone #{repo[:url]} #{repo[:full_name]}" | |
puts `#{cmd}` | |
end | |
end | |
end | |
end | |
main() |
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
source 'https://rubygems.org' | |
gem 'octokit' | |
gem 'highline' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment