Class: Avm::Git::Issue::Complete
- Includes:
- EacRubyUtils::Console::Speaker, EacRubyUtils::SimpleCache
- Defined in:
- lib/avm/git/issue/complete.rb,
lib/avm/git/issue/complete/_push.rb,
lib/avm/git/issue/complete/_remote.rb,
lib/avm/git/issue/complete/_commits.rb,
lib/avm/git/issue/complete/_tracker.rb,
lib/avm/git/issue/complete/_local_tag.rb,
lib/avm/git/issue/complete/_validations.rb,
lib/avm/git/issue/complete/_local_branch.rb
Constant Summary collapse
- VALIDATIONS =
{ branch_name: 'Branch name', branch_hash: 'Branch hash', follow_master: 'Follow master?', commits: 'Commits?', bifurcations: 'Bifurcations?', dry_push: 'Dry push?' }.freeze
Instance Attribute Summary collapse
-
#no_validate_branch ⇒ Object
readonly
Returns the value of attribute no_validate_branch.
Instance Method Summary collapse
- #assert_tag ⇒ Object
- #bifurcations_result ⇒ Object
- #branch_hash_result ⇒ Object
- #branch_hash_uncached ⇒ Object
- #branch_name ⇒ Object
- #branch_name_result ⇒ Object
- #branch_uncached ⇒ Object
- #clipboard_copy_tracker_message ⇒ Object
- #commit_parents(commit) ⇒ Object
- #commits_result ⇒ Object
- #commits_uncached ⇒ Object
- #create_tag ⇒ Object
- #delete_tag ⇒ Object
- #dry_push_args ⇒ Object
- #dry_push_result ⇒ Object
- #follow_master? ⇒ Boolean
- #follow_master_result ⇒ Object
-
#initialize(options) ⇒ Complete
constructor
A new instance of Complete.
- #issue_id ⇒ Object
- #master_push ⇒ Object
- #multiple_parents?(commit) ⇒ Boolean
- #push ⇒ Object
- #pushs_uncached ⇒ Object
- #remote_branch_hash ⇒ Object
- #remote_master_hash ⇒ Object
- #remote_tag_hash ⇒ Object
- #remove_branch_push ⇒ Object
- #remove_local_branch ⇒ Object
- #run ⇒ Object
- #start_banner ⇒ Object
- #tag ⇒ Object
- #tag_hash ⇒ Object
- #tag_push ⇒ Object
- #valid? ⇒ Boolean
- #validations ⇒ Object
- #validations_banner ⇒ Object
Constructor Details
#initialize(options) ⇒ Complete
Returns a new instance of Complete.
19 20 21 22 23 24 |
# File 'lib/avm/git/issue/complete.rb', line 19 def initialize() consumer = ::EacRubyUtils::OptionsConsumer.new() dir, @no_validate_branch = consumer.consume_all(:dir, :no_validate_branch) consumer.validate @git = ::EacLauncher::Git::Base.new(dir) end |
Instance Attribute Details
#no_validate_branch ⇒ Object (readonly)
Returns the value of attribute no_validate_branch.
17 18 19 |
# File 'lib/avm/git/issue/complete.rb', line 17 def no_validate_branch @no_validate_branch end |
Instance Method Details
#assert_tag ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'lib/avm/git/issue/complete/_local_tag.rb', line 9 def assert_tag if tag_hash return if tag_hash == branch_hash delete_tag end create_tag end |
#bifurcations_result ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/avm/git/issue/complete/_commits.rb', line 23 def bifurcations_result commits.each do |commit| if multiple_parents?(commit) return ::Avm::Result.error("#{commit} has multiple parents") end end ::Avm::Result.success('no') end |
#branch_hash_result ⇒ Object
28 29 30 31 32 33 |
# File 'lib/avm/git/issue/complete/_local_branch.rb', line 28 def branch_hash_result ::Avm::Result.success_or_error( branch_hash, branch_hash.present? ) end |
#branch_hash_uncached ⇒ Object
13 14 15 |
# File 'lib/avm/git/issue/complete/_local_branch.rb', line 13 def branch_hash_uncached @git.rev_parse("refs/heads/#{branch}") end |
#branch_name ⇒ Object
17 18 19 |
# File 'lib/avm/git/issue/complete/_local_branch.rb', line 17 def branch_name branch.split('/')[-1] end |
#branch_name_result ⇒ Object
21 22 23 24 25 26 |
# File 'lib/avm/git/issue/complete/_local_branch.rb', line 21 def branch_name_result ::Avm::Result.success_or_error( branch_name, issue_id || no_validate_branch ) end |
#branch_uncached ⇒ Object
9 10 11 |
# File 'lib/avm/git/issue/complete/_local_branch.rb', line 9 def branch_uncached @git.current_branch end |
#clipboard_copy_tracker_message ⇒ Object
9 10 11 12 |
# File 'lib/avm/git/issue/complete/_tracker.rb', line 9 def ::Clipboard.copy() infov 'Copied to clipboard', end |
#commit_parents(commit) ⇒ Object
36 37 38 39 |
# File 'lib/avm/git/issue/complete/_commits.rb', line 36 def commit_parents(commit) @git.execute!('log', '--pretty=%P', '-n', '1', commit).split(' ').map(&:strip) .select(&:present?) end |
#commits_result ⇒ Object
9 10 11 12 13 14 |
# File 'lib/avm/git/issue/complete/_commits.rb', line 9 def commits_result ::Avm::Result.success_or_error( commits.any? ? 'yes' : 'none', commits.any? ) end |
#commits_uncached ⇒ Object
16 17 18 19 20 21 |
# File 'lib/avm/git/issue/complete/_commits.rb', line 16 def commits_uncached return [] unless branch_hash && follow_master? interval = remote_master_hash ? "#{remote_master_hash}..#{branch_hash}" : branch_hash @git.execute!('rev-list', interval).each_line.map(&:strip) end |
#create_tag ⇒ Object
31 32 33 |
# File 'lib/avm/git/issue/complete/_local_tag.rb', line 31 def create_tag git(['tag', branch_name, branch_hash]) end |
#delete_tag ⇒ Object
18 19 20 21 |
# File 'lib/avm/git/issue/complete/_local_tag.rb', line 18 def delete_tag info 'Removendo tag...' git(['tag', '-d', branch_name]) end |
#dry_push_args ⇒ Object
7 8 9 |
# File 'lib/avm/git/issue/complete/_push.rb', line 7 def dry_push_args %w[push --dry-run] + [remote_name] + pushs end |
#dry_push_result ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/avm/git/issue/complete/_push.rb', line 11 def dry_push_result return ::Avm::Result.error('Nothing to push') if pushs.empty? r = @git.execute(dry_push_args) = if r.fetch(:exit_code).zero? 'ok' else r.fetch(:stderr) + "\n#{::Shellwords.join(dry_push_args)}" end ::Avm::Result.success_or_error(, r.fetch(:exit_code).zero?) end |
#follow_master? ⇒ Boolean
45 46 47 |
# File 'lib/avm/git/issue/complete/_local_branch.rb', line 45 def follow_master? remote_master_hash ? @git.descendant?(branch_hash, remote_master_hash) : true end |
#follow_master_result ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/avm/git/issue/complete/_local_branch.rb', line 35 def follow_master_result return ::Avm::Result.neutral('No branch hash') unless branch_hash r = follow_master? ::Avm::Result.success_or_error( r ? 'yes' : 'no', r ) end |
#issue_id ⇒ Object
40 41 42 43 |
# File 'lib/avm/git/issue/complete.rb', line 40 def issue_id m = branch_name.match(/\A#{Regexp.quote('issue_')}(\d+)\z/) m ? m[1].to_i : nil end |
#master_push ⇒ Object
36 37 38 |
# File 'lib/avm/git/issue/complete/_push.rb', line 36 def master_push remote_master_hash != branch_hash ? "#{branch_hash}:refs/heads/master" : nil end |
#multiple_parents?(commit) ⇒ Boolean
32 33 34 |
# File 'lib/avm/git/issue/complete/_commits.rb', line 32 def multiple_parents?(commit) commit_parents(commit).count > 1 end |
#push ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/avm/git/issue/complete/_push.rb', line 23 def push if pushs.empty? info 'PUSH: Nada a enviar' else info "PUSH: enviando \"#{pushs}\"..." git(%w[push origin] + pushs) end end |
#pushs_uncached ⇒ Object
32 33 34 |
# File 'lib/avm/git/issue/complete/_push.rb', line 32 def pushs_uncached [master_push, remove_branch_push, tag_push].reject(&:nil?) end |
#remote_branch_hash ⇒ Object
11 12 13 |
# File 'lib/avm/git/issue/complete/_remote.rb', line 11 def remote_branch_hash remote_hashs["refs/heads/#{branch}"] end |
#remote_master_hash ⇒ Object
7 8 9 |
# File 'lib/avm/git/issue/complete/_remote.rb', line 7 def remote_master_hash remote_hashs['refs/heads/master'] end |
#remote_tag_hash ⇒ Object
15 16 17 |
# File 'lib/avm/git/issue/complete/_remote.rb', line 15 def remote_tag_hash remote_hashs[tag] end |
#remove_branch_push ⇒ Object
40 41 42 |
# File 'lib/avm/git/issue/complete/_push.rb', line 40 def remove_branch_push remote_branch_hash ? ":refs/heads/#{branch}" : nil end |
#remove_local_branch ⇒ Object
49 50 51 52 53 54 |
# File 'lib/avm/git/issue/complete/_local_branch.rb', line 49 def remove_local_branch info 'Removendo branch local...' bn = branch_name git(['checkout', branch_hash]) git(['branch', '-D', bn]) end |
#run ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/avm/git/issue/complete.rb', line 30 def run return false unless valid? assert_tag push remove_local_branch true end |
#start_banner ⇒ Object
26 27 28 |
# File 'lib/avm/git/issue/complete.rb', line 26 def end |
#tag ⇒ Object
23 24 25 |
# File 'lib/avm/git/issue/complete/_local_tag.rb', line 23 def tag "refs/tags/#{branch_name}" end |
#tag_hash ⇒ Object
27 28 29 |
# File 'lib/avm/git/issue/complete/_local_tag.rb', line 27 def tag_hash @git.rev_parse(tag) end |
#tag_push ⇒ Object
44 45 46 47 48 |
# File 'lib/avm/git/issue/complete/_push.rb', line 44 def tag_push return nil unless !remote_tag_hash || remote_tag_hash != branch_hash "#{branch_hash}:#{tag}" end |
#valid? ⇒ Boolean
18 19 20 |
# File 'lib/avm/git/issue/complete/_validations.rb', line 18 def valid? validations.values.none?(&:error?) end |
#validations ⇒ Object
28 29 30 31 32 |
# File 'lib/avm/git/issue/complete/_validations.rb', line 28 def validations VALIDATIONS.map do |key, label| [label, send("#{key}_result")] end.to_h end |
#validations_banner ⇒ Object
22 23 24 25 26 |
# File 'lib/avm/git/issue/complete/_validations.rb', line 22 def validations.each do |label, result| infov label, result.label end end |