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_hooksObject



64
65
66
67
68
69
# File 'lib/cli/branch_name_cli.rb', line 64

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

#prepare_commit_msgObject



26
27
28
29
30
31
32
33
34
35
36
37
# 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
  name = generator.prepare_message_template_for_type(type: source, cfg_path:, msg_file_path: msg_path)
  File.write_to_file(msg_path, name)
rescue StandardError => e
  raise Thor::Error, e.message
end

#validate_branch_nameObject



41
42
43
44
45
46
47
48
# File 'lib/cli/branch_name_cli.rb', line 41

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_msgObject



54
55
56
57
58
59
60
61
# File 'lib/cli/branch_name_cli.rb', line 54

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