Sha256: a1d3654821679c1c6543ab2191276bb75902e422e282a225bf8057fd0419e173

Contents?: true

Size: 1.91 KB

Versions: 1

Compression:

Stored size: 1.91 KB

Contents

#!/usr/bin/env ruby
require_relative '../lib/github_copier'

if ARGV.empty?
  OptParser.parse(%w[--help])
end

include GithubCopier

# Now we are ready to take the order
# Show help if user forgot to type anything
options = OptParser.parse(ARGV)

# Mandatory options
raise "base_dir is required" if options.base_dir.nil?
raise "user is required"     if options.user.nil?

# Make use of the user name
gh_id = options.user

# Note: set to specific language to limit the cloning
if options.language
  language = options.language #'Emacs Lisp'
end

args = {
  base_dir:    options.base_dir,    # mandatory
  oauth_token: options.oauth_token, # optional
  user:        options.user,        # optional if org is used?
  org:         options.org,         # optional if user is used?
  all_repos:   options.all_repos,   # optional
  clone_repos: options.clone_repos  # optional
}

repos = GithubCopier::GithubUtils.list_all(args)

# List of language that have been used by the given user/organization
languages = repos.map(&:language).uniq.compact
puts "------------------------------------------"
puts "List of languages by #{gh_id}"
puts languages
puts "------------------------------------------"

repos_hash = GithubCopier::GithubUtils.repos_by_language(repos, languages)

result = GithubCopier::GithubUtils.repos_as_list(repos_hash)

if result && !result.empty?
  puts "------------------------------------------"
  puts "List of all repositories by #{gh_id}"
  result.each_with_index do |r,i|
    puts "#{i+1}/#{result.size}: #{r}"
  end
  puts "------------------------------------------"

  if args[:clone_repos]
    if language
      GithubCopier::GithubUtils.clone_all(result.keep_if { |i| i.split(File::SEPARATOR)[1] == language }, options.base_dir)
    else
      GithubCopier::GithubUtils.clone_all(result, options.base_dir)
    end
  else
    puts "Dry-run only, no action taken!"
    puts "------------------------------------------"
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
github_copier-0.1.0 bin/github_copier