Skip to content

Instantly share code, notes, and snippets.

@pocke
Created December 10, 2017 14:07
Show Gist options
  • Save pocke/ce2d7a49591f212c4852f217637270b1 to your computer and use it in GitHub Desktop.
Save pocke/ce2d7a49591f212c4852f217637270b1 to your computer and use it in GitHub Desktop.
# 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
@pocke
Copy link
Author

pocke commented Dec 15, 2017

clone with private repo version

# 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
  client = Octokit::Client.new(access_token: token)
  client.auto_paginate = true
  client.per_page = 100
  client.repositories.reject(&:fork)
end

def ghq_get
  repos = repositories
  repos.each.with_index(1) do |repo, idx|
    puts "[#{'='*idx}#{' '*(repos.size-idx)}]"
    system('ghq', 'get', repo.ssh_url)
  end
end

ghq_get

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment