Top Level Namespace
Defined Under Namespace
Modules: Ghedsh
Classes: Commands, Interface, Organization, PluginLoader, ShellContext, Sys, Team, User
Constant Summary
collapse
- ERROR_CODE =
'#cc0000'
- WARNING_CODE =
'#9f6000'
- INFO_CODE =
'#00529B'
- SUCCESS_CODE =
'#4f8a10'
- COMMANDS =
{}
Instance Method Summary
collapse
Instance Method Details
#build_item_table(item, pattern) ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# 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) ⇒ Object
44
45
46
47
48
49
50
|
# File 'lib/helpers.rb', line 44
def build_regexp_from_string(string)
str = eval(string) Regexp.new(str)
rescue SyntaxError => e
puts Rainbow('Error building Regexp, check syntax.').color('#cc0000')
puts
end
|
#custom_spinner(message) ⇒ Object
colors: error: .color(‘#cc0000’) command not found: .yellow warning: .color(‘#9f6000’) info: .color(#00529B) success: .color(79, 138, 16)
15
16
17
|
# 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) ⇒ Boolean
52
53
54
55
|
# File 'lib/helpers.rb', line 52
def is_file?(path)
path = path.delete('"')
File.file?("#{Dir.home}#{path}") ? true : false
end
|
#open_url(url) ⇒ Object
140
141
142
143
144
145
146
147
|
# 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
|
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
# 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 ⇒ Object
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# 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) ⇒ Object
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
# 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) ⇒ Object
33
34
35
36
37
38
39
40
41
42
|
# 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) ⇒ Object
131
132
133
134
135
136
137
138
|
# 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
|