Class: GitCLI::Git

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/thorium/tasks/git.rb

Overview

Git tasks package Listing and cloning of repositories (Github support included)

Constant Summary collapse

GH_API_URL =
'https://api.github.com'
GITIGNORE_REPO =
'https://raw.githubusercontent.com/github/gitignore/master/'

Instance Method Summary collapse

Instance Method Details

#clone(username = nil) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/thorium/tasks/git.rb', line 30

def clone(username = nil)
  list(username)
  # Do not do anything if list is empty
  ask_options = { limited_to: ('1'..@repos.size.to_s).to_a, skip: '', mute_limit_set: true }
  answer = ask('Which repository would you like to clone?', :green, ask_options)
  abort if answer == ask_options[:skip]
  protocol = ask('Select a protocol (ssh or https)?', :green, limited_to: %w(s h))
  url = if protocol == 's'
    @repos[answer.to_i - 1][2]
  else
    @repos[answer.to_i - 1][3]
  end
  run "git clone #{url}"
end

#ignoreObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/thorium/tasks/git.rb', line 47

def ignore
  say msg = 'Fetching a list of gitignore files...' and say '-' * msg.size
  files = get_gitignore_list.map { |e| e['name'] }
  gitignore_files = files.each_with_index.map do |e, i|
    "[#{i + 1}] #{File.basename(e, '.*')}"
  end
  print_in_columns gitignore_files
  ask_options = {
    mute_limit_set: true,
    limited_to:     ('1'..files.size.to_s).to_a,
    skip:           ''
  }
  answer = ask('Which file would you like to copy?', :green, ask_options)
  abort if answer == ask_options[:skip]
  create_gitignore(Dir.pwd + '/.gitignore', files[answer.to_i - 1])
end

#list(username = nil) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/thorium/tasks/git.rb', line 15

def list(username = nil)
  if username.nil?
    gh_uname = ask('Enter Github username: ', :green)
    abort if gh_uname.empty?
  else
    gh_uname = username
  end
  say msg = "Fetching Github repositories (#{gh_uname})..." and say '-' * msg.size
  @repos = get_gh_repos(gh_uname).each_with_index.map do |e, i|
    e.values_at('name', 'ssh_url', 'clone_url').unshift("[#{i + 1}]")
  end
  print_table @repos
end