Created
July 30, 2019 08:07
-
-
Save emad-elsaid/98096473897a5d23197bd11fc7733a6f to your computer and use it in GitHub Desktop.
This file contains 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 'tty-prompt' | |
require 'open-uri' | |
require 'json' | |
require 'colorize' | |
require 'colorized_string' | |
prompt = TTY::Prompt.new | |
user_name = prompt.ask("What is name of the user or organisation?") | |
type = prompt.select("What type is it?", user: "users", organisation: "orgs") | |
token = ENV['GITHUB_API_TOKEN'] | |
unless token | |
puts "Can't find GITHUB_API_TOKEN in you environment!".light_red | |
puts "Use the follow URL to generate a token: https://github.com/settings/tokens".light_red | |
puts "Then add it to your .bashrc/.bash_profile/...etc as a variable GITHUB_API_TOKEN".light_red | |
exit | |
end | |
page = -1 | |
loop do | |
page += 1 | |
url = "https://api.github.com/#{type}/#{user_name}/repos?access_token=#{token}&page=#{page}" | |
repos = open(url).read | |
repos = JSON.load(repos) | |
break if repos.empty? | |
repos.each do |repo| | |
if Dir.exist?(repo["name"]) | |
puts "Updating #{repo["name"]}...".light_blue | |
Dir.chdir(repo["name"]) do | |
system("git pull --all") | |
end | |
else | |
puts "Cloning #{repo["name"]}...".light_blue | |
system("git clone #{repo["ssh_url"]}") | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment