Class: ConventionalCommits::BranchNameCLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/cli/branch_name_cli.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exit_on_failure? ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/cli/branch_name_cli.rb', line 7

def self.exit_on_failure?
  true
end

Instance Method Details

#branch(_name) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/cli/branch_name_cli.rb', line 13

def branch(_name)
  cfg_path = options["cfg_path"] || Configuration::DEFAULT_CONFIGURATION_PATH
  generator = ConventionalCommits::BranchNameGenerator.new
  generated_name = generator.generate_name_for(_name.strip, path: cfg_path.strip)
  Kernel.system("git branch #{generated_name}")
rescue StandardError => e
  raise Thor::Error, e.message
end

#install_hooks ⇒ Object



70
71
72
73
74
75
# File 'lib/cli/branch_name_cli.rb', line 70

def install_hooks
  installer = ConventionalCommits::Configuration::HooksInstaller.new
  installer.install_all
rescue StandardError => e
  raise Thor::Error, e.message
end

#prepare_commit_msg ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/cli/branch_name_cli.rb', line 26

def prepare_commit_msg
  source = options["source"] || ""
  puts source
  msg_path = options["msg_path"] || Configuration::DEFAULT_COMMIT_MSG_PATH
  cfg_path = options["cfg_path"] || Configuration::DEFAULT_CONFIGURATION_PATH

  generator = ConventionalCommits::CommitMessageGenerator.new
  unless generator.should_preserve_original_message(source:)
    puts "Generating message"
    name = generator.prepare_message_template_for_type(type: source, cfg_path:, msg_file_path: msg_path)
    File.write_to_file(msg_path, name)
  end
  
rescue StandardError => e
  raise Thor::Error, e.message
end

#validate_branch_name ⇒ Object



45
46
47
48
49
50
51
52
# File 'lib/cli/branch_name_cli.rb', line 45

def validate_branch_name
  cfg_path = options["cfg_path"] || Configuration::DEFAULT_CONFIGURATION_PATH
  generator = ConventionalCommits::BranchNameGenerator.new
  name = ConventionalCommits::Git.new.current_branch_name
  generator.is_valid_branch(name.strip, path: cfg_path.strip)
rescue StandardError => e
  raise Thor::Error, e.message
end

#validate_commit_msg ⇒ Object



58
59
60
61
62
63
64
65
66
67
# File 'lib/cli/branch_name_cli.rb', line 58

def validate_commit_msg

  msg_path = options["msg_path"] || Configuration::DEFAULT_COMMIT_MSG_PATH
  cfg_path = options["cfg_path"] || Configuration::DEFAULT_CONFIGURATION_PATH
  validator = ConventionalCommits::CommitMessageValidator.new

  validator.validate_commit_msg_from_file(commit_msg_path: msg_path, cfg_path:)
rescue StandardError => e
  raise Thor::Error, e.message
end