class Chid::Commands::Gitflow::Commit

Public Instance Methods

add_commit_description() click to toggle source
# File lib/chid/commands/gitflow/commit.rb, line 98
def add_commit_description
  puts 'Tell me the commit description, one action per line'
  print "> #{} "
  commit_description ="- #{STDIN.gets.strip} \n"
  @commit_lines << commit_description
  add_commit_description unless did_commit_finished?
end
add_commit_kind() click to toggle source
# File lib/chid/commands/gitflow/commit.rb, line 87
def add_commit_kind
  choices = ['Add', 'Remove','Update', 'Refactor','Fix']
  result = prompt.select('Select commit type: ', choices)
end
add_commit_title(kind_title) click to toggle source
# File lib/chid/commands/gitflow/commit.rb, line 92
def add_commit_title(kind_title)
  puts 'Tell me the commit title'
  print "> #{kind_title} "
  commit_title = STDIN.gets.strip
end
branch() click to toggle source
# File lib/chid/commands/gitflow/commit.rb, line 75
def branch
  @branch ||= %x[git rev-parse --abbrev-ref HEAD].strip
end
branch_name() click to toggle source
# File lib/chid/commands/gitflow/commit.rb, line 79
def branch_name
  @branch_name ||= branch[/\w{1,}\/#?\d{1,}/] || branch
end
build_commit() click to toggle source
# File lib/chid/commands/gitflow/commit.rb, line 67
def build_commit
  @commit_lines = "\n"
  commit_kind  = first_option_kind || add_commit_kind
  commit_title = add_commit_title(commit_kind)
  add_commit_description
  commit = "#{branch_name} #{commit_kind} #{commit_title} \n #{@commit_lines}"
end
did_commit_finished?() click to toggle source
# File lib/chid/commands/gitflow/commit.rb, line 112
def did_commit_finished?
  answers = ['Yes','No']
  result_description_finished = prompt.select('more?', answers)
  result_description_finished == 'No'
end
do_push?() click to toggle source
# File lib/chid/commands/gitflow/commit.rb, line 106
def do_push?
  answers = ['Yes','No']
  result_should_push = prompt.select('Push changes?', answers)
  result_should_push == 'Yes'
end
first_option() click to toggle source
# File lib/chid/commands/gitflow/commit.rb, line 52
def first_option
  @first_option ||= self.class.arguments.select { |a| options[a] }.compact.join(' ')
end
first_option_kind() click to toggle source
# File lib/chid/commands/gitflow/commit.rb, line 56
def first_option_kind
  options_titles = {
    '-A' => 'Add',
    '-R' => 'Remove',
    '-Ref' => 'Refactor',
    '-F' => 'Fix'
  }

  options_titles[first_option]
end
prompt() click to toggle source
# File lib/chid/commands/gitflow/commit.rb, line 83
def prompt
  @prompt ||= TTY::Prompt.new
end
run() click to toggle source
# File lib/chid/commands/gitflow/commit.rb, line 46
def run
  commit = build_commit
  system("git commit -sm \"#{commit}\"")
  system("git push origin #{branch}") if do_push?
end