class Object
Constants
- COMMANDS
- ERROR_CODE
color codes
- INFO_CODE
- SUCCESS_CODE
- WARNING_CODE
Public Instance Methods
build_item_table(item, pattern)
click to toggle source
# File lib/helpers.rb, line 19 def build_item_table(item, pattern) matches = 0 rows = [] item.each do |i, v| if pattern.match(i) rows << [i, v] matches += 1 end end table = Terminal::Table.new headings: ['Github ID', 'Role'], rows: rows puts table matches end
build_regexp_from_string(string)
click to toggle source
# File lib/helpers.rb, line 44 def build_regexp_from_string(string) str = eval(string) # string.gsub(/\//, '') Regexp.new(str) rescue SyntaxError => e puts Rainbow('Error building Regexp, check syntax.').color('#cc0000') puts end
custom_spinner(message)
click to toggle source
colors: error: .color('#cc0000') command not found: .yellow warning: .color('#9f6000') info: .color(#00529B) success: .color(79, 138, 16)
# File lib/helpers.rb, line 15 def custom_spinner(message) TTY::Spinner.new(Rainbow(message.to_s).color(79, 138, 16), format: :bouncing_ball) end
is_file?(path)
click to toggle source
# File lib/helpers.rb, line 52 def is_file?(path) path = path.delete('"') File.file?("#{Dir.home}#{path}") ? true : false end
open_url(url)
click to toggle source
# File lib/helpers.rb, line 140 def open_url(url) os = RbConfig::CONFIG['host_os'] if os.downcase.include?('linux') system("xdg-open #{url}") elsif os.downcase.include?('darwin') system("open #{url}") end end
perform_git_clone(repos_to_clone, custom_path)
click to toggle source
# File lib/helpers.rb, line 101 def perform_git_clone(repos_to_clone, custom_path) begin dir_path = if custom_path.nil? Dir.pwd.to_s else "#{Dir.home}#{custom_path}" end FileUtils.mkdir_p(dir_path) rescue StandardError => exception puts Rainbow(exception.message.to_s).color('#cc0000') end repos_to_clone.each do |repos| FileUtils.cd(dir_path) do if !Dir.exist?("#{dir_path}/#{repos[:name]}") || Dir.empty?("#{dir_path}/#{repos[:name]}") system("git clone --recurse-submodules --progress #{repos[:ssh_url]}") puts else FileUtils.cd("#{dir_path}/#{repos[:name]}") do puts repos[:name] system('git pull --all --recurse-submodules') puts end end end end rescue StandardError => exception puts Rainbow(exception.message.to_s).color('#cc0000') puts end
repo_creation_guide()
click to toggle source
# File lib/helpers.rb, line 57 def repo_creation_guide puts Rainbow("Select 'Default' to create a quick public repo.").color('#f18973') puts Rainbow("Select 'Custom' for private/public repo whith specific options.").color('#f18973') puts Rainbow('To skip any option just hit Enter (Default options).').color('#f18973') puts choices = %w[Default Custom] prompt = TTY::Prompt.new answer = prompt.select('Select configuration', choices) if answer == 'Default' return answer else puts Rainbow('Answer questions with yes/true or no/false').color('#f18973') custom_options = prompt.collect do key(:private).ask('Private repo? (Default: false) [yes/true, no/false]', convert: :bool) key(:description).ask('Write description of the repo') key(:has_issues).ask('Has issues? (Default:true) [yes/true, no/false]', convert: :bool) key(:has_wiki).ask('Has wiki? (Default: true) [yes/true, no/false]', convert: :bool) key(:auto_init).ask('Create an initial commit with empty README? (Default: false) (if you want .gitignore template must be yes/true)', convert: :bool) key(:gitignore_template).ask('Desired language or platform for .gitignore template') end return custom_options = custom_options.compact end end
select_member(config, pattern, client)
click to toggle source
# File lib/helpers.rb, line 82 def select_member(config, pattern, client) members = [] members_url = {} client.organization_members(config['Org'].to_s).each do |member| if pattern.match(member[:login].to_s) members << member[:login] members_url[member[:login]] = member[:html_url] end end if members.empty? puts Rainbow("No member matched with #{pattern.source} inside organization #{config['Org']}").color('#9f6000') puts else prompt = TTY::Prompt.new answer = prompt.select('Select desired organization member', members) end members_url[answer] end
show_matching_items(item, pattern)
click to toggle source
# File lib/helpers.rb, line 33 def show_matching_items(item, pattern) occurrences = 0 item.each do |i| if pattern.match(i) puts i occurrences += 1 end end occurrences end
split_members(members_list)
click to toggle source
# File lib/helpers.rb, line 131 def split_members(members_list) members = [] members_list.each do |i| string = i.split(/[,(\s)?]/) members.push(string) end members = members.flatten end