56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
# File 'lib/comito.rb', line 56
def self.run
types, scopes, msg_length, confirn_commit_message = load_config
staged_files = `git diff --cached --name-only`.split("\n")
if staged_files.empty?
puts "#{RED}\nNo files staged for commit.\n#{RESET}"
return
end
prompt = TTY::Prompt.new
type = prompt.select("#{YELLOW}Select commit type:#{RESET}") do ||
types.each do |key, desc|
.choice("#{GREEN}#{key} — #{desc}#{RESET}", key)
end
end
scope = prompt.select("#{YELLOW}Select scope:#{RESET}") do ||
scopes.each do |key, desc|
.choice("#{GREEN}#{key} — #{desc}#{RESET}", key)
end
end
message = prompt.ask("#{YELLOW}Your commit message:#{RESET}", default: "")
commit_msg = "#{type}#{scope.to_s.empty? ? '' : "(#{scope})"}: #{message}"
if commit_msg.length > msg_length
puts "#{RED}\nError: Commit message exceeds #{msg_length} characters limit.\n#{RESET}"
puts "#{RED}\nYour full commit message: \n#{commit_msg}\n#{RESET}"
end
puts "#{YELLOW}\nFinal full commit message:#{RESET}"
puts "--------------------------------"
puts "\n#{BLUE}#{commit_msg[0..msg_length]}#{RESET}\n\n"
puts "--------------------------------"
confirm = true
if confirn_commit_message
confirm = prompt.yes?("#{YELLOW}Commit with this message?#{RESET}")
end
if confirm
system("git commit -m \"#{commit_msg}\"")
else
puts "#{RED}\nAborted.#{RESET}"
end
end
|