Class: Chid::Commands::Gitflow::Commit
Constant Summary
Chid::Command::COMMANDS
Instance Attribute Summary
#options
Instance Method Summary
collapse
command, help, #initialize, map_options_with_values, run
Constructor Details
This class inherits a constructor from Chid::Command
Instance Method Details
#add_commit_description ⇒ Object
98
99
100
101
102
103
104
|
# 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 ⇒ Object
87
88
89
90
|
# 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) ⇒ Object
92
93
94
95
96
|
# 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 ⇒ Object
75
76
77
|
# File 'lib/chid/commands/gitflow/commit.rb', line 75
def branch
@branch ||= %x[git rev-parse --abbrev-ref HEAD].strip
end
|
#branch_name ⇒ Object
79
80
81
|
# File 'lib/chid/commands/gitflow/commit.rb', line 79
def branch_name
@branch_name ||= branch[/\w{1,}\/#?\d{1,}/] || branch
end
|
#build_commit ⇒ Object
67
68
69
70
71
72
73
|
# 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? ⇒ Boolean
112
113
114
115
116
|
# 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? ⇒ Boolean
106
107
108
109
110
|
# 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 ⇒ Object
52
53
54
|
# 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 ⇒ Object
56
57
58
59
60
61
62
63
64
65
|
# 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 ⇒ Object
83
84
85
|
# File 'lib/chid/commands/gitflow/commit.rb', line 83
def prompt
@prompt ||= TTY::Prompt.new
end
|
#run ⇒ Object
46
47
48
49
50
|
# 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
|