Module: Commiti::CommitExecution

Defined in:
lib/services/git/commit/commit_execution.rb

Class Method Summary collapse

Class Method Details

.maybe_commit(initial_message, run_stage:, print_message:) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/services/git/commit/commit_execution.rb', line 5

def self.maybe_commit(initial_message, run_stage:, print_message:)
  working_message = initial_message

  loop do
    action = Commiti::InteractivePrompt.ask_commit_action

    case action
    when :yes
      result, next_message = handle_yes_action(
        working_message,
        run_stage: run_stage,
        print_message: print_message
      )
      return result if result

      working_message = next_message
    when :edit
      edited = edit_message_until_valid(working_message)
      if edited.nil?
        puts "\n#{Commiti::TerminalUI.status(:fail, 'Editor did not exit successfully.')}\n\n"
        next
      end

      working_message = edited
      print_message.call(working_message)
    else
      print_skip_message
      return :skipped
    end
  end
end