class GitCLI::Git
Git
tasks package Listing and cloning of repositories (Github support included)
Constants
- GH_API_URL
- GITIGNORE_REPO
Public Instance Methods
clone(username = nil)
click to toggle source
# 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
create_gitignore(file_path, file_url)
click to toggle source
Fetch gitignore file
# File lib/thorium/tasks/git.rb, line 85 def create_gitignore(file_path, file_url) url = GITIGNORE_REPO + file_url get url, file_path end
get_gh_repos(uname)
click to toggle source
Fetches Github repositories for a given user
# File lib/thorium/tasks/git.rb, line 69 def get_gh_repos(uname) url = "#{GH_API_URL}/users/#{uname}/repos" gh_repos_filepath = ENV['HOME'] + "/.thorium/gh_repos_#{uname}.json" get url, gh_repos_filepath, verbose: false JSON.parse File.read(gh_repos_filepath) end
get_gitignore_list()
click to toggle source
Fetches a list of predefined gitignore files from github/gitignore repo
# File lib/thorium/tasks/git.rb, line 77 def get_gitignore_list url = "#{GH_API_URL}/repos/github/gitignore/contents" gitignore_list_filepath = ENV['HOME'] + '/.thorium/gh_gitignore_list.json' get url, gitignore_list_filepath, verbose: false JSON.parse File.read(gitignore_list_filepath) end
ignore()
click to toggle source
# 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)
click to toggle source
# 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