24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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
106
107
108
|
# File 'lib/commitcraft/cli.rb', line 24
def generate
setup_style(options[:style]) if options[:style]
generator = MessageGenerator.new
prompt = TTY::Prompt.new
pastel = Pastel.new
if options[:jira]
validate_jira_key!(options[:jira])
end
if CommitCraft.test_mode?
puts pastel.yellow("⚠️ TEST MODE - Using mock AI (no API calls)")
puts ""
end
spinner = TTY::Spinner.new("[:spinner] Analyzing changes and generating commit messages...", format: :dots)
spinner.auto_spin
begin
result = generator.generate(
all: options[:all],
unstaged: options[:unstaged],
no_context: options[:no_context],
include_history: options[:include_history],
jira: options[:jira]
)
rescue CommitCraft::Error => e
spinner.error("(#{pastel.red("failed")})")
puts pastel.red("Error: #{e.message}")
exit 1
end
spinner.success("(#{pastel.green("done")})")
puts
summary = result[:diff_summary]
puts pastel.dim("Files changed: #{summary[:files_changed]}, ") +
pastel.green("+#{summary[:additions]}") + pastel.dim(" / ") +
pastel.red("-#{summary[:deletions]}")
puts
messages = result[:messages]
if options[:auto_commit]
selected_message = messages.first
puts pastel.cyan("Auto-committing with: ") + pastel.white(selected_message)
else
choices = messages.map.with_index do |msg, _idx|
{ name: msg, value: msg }
end
choices << { name: pastel.dim("✎ Write custom message"), value: :custom }
choices << { name: pastel.dim("✗ Cancel"), value: :cancel }
selected_message = prompt.select("Choose a commit message:", choices, per_page: 10)
case selected_message
when :custom
selected_message = prompt.ask("Enter your commit message:") do |q|
q.required true
q.validate(/\S+/)
end
when :cancel
puts pastel.yellow("Commit cancelled.")
exit 0
end
end
puts
begin
generator.commit_with_message(selected_message, amend: options[:amend])
action = options[:amend] ? "amended" : "created"
puts pastel.green("✓ Commit #{action} successfully!")
puts pastel.dim(" Message: #{selected_message}")
rescue CommitCraft::GitError => e
puts pastel.red("Failed to commit: #{e.message}")
exit 1
end
end
|