Created
December 10, 2017 14:07
-
-
Save pocke/ce2d7a49591f212c4852f217637270b1 to your computer and use it in GitHub Desktop.
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
# Requirements: ghq, hub | |
# Usage: ruby ghq_clone.rb YOUR_ACCOUNT_NAME | |
gem 'psych', '>= 3.0.1' | |
require 'octokit' | |
require 'psych' | |
require 'pathname' | |
def token | |
hub = Pathname(File.expand_path('~/.config/hub')) | |
Psych.load(File.read(hub), symbolize_names: true)[:'github.com'].first[:oauth_token] | |
end | |
def repositories(owner) | |
client = Octokit::Client.new(access_token: token) | |
client.auto_paginate = true | |
client.per_page = 100 | |
client.repositories(owner).reject(&:fork) | |
end | |
def ghq_get(owner) | |
repos = repositories(owner) | |
repos.each.with_index(1) do |repo, idx| | |
puts "[#{'='*idx}#{' '*(repos.size-idx)}]" | |
system('ghq', 'get', repo.ssh_url) | |
end | |
end | |
ARGV.each do |arg| | |
ghq_get arg | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
clone with private repo version