Class: Avm::Git::Issue::Complete
- Inherits:
-
Object
- Object
- 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,
lib/avm/git/issue/complete/_working_tree.rb
Constant Summary collapse
- VALIDATIONS =
{ clean_workspace: 'Clean workspace?', branch_name: 'Branch name', branch_hash: 'Branch hash', follow_master: 'Follow master?', commits: 'Commits?', bifurcations: 'Bifurcations?', dry_push: 'Dry push?' }.with_indifferent_access.freeze
Instance Attribute Summary collapse
-
#skip_validations ⇒ Object
readonly
Returns the value of attribute skip_validations.
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
- #clean_workspace_result ⇒ 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
- #validate_skip_validations ⇒ Object
- #validation_result(key) ⇒ Object
- #validations ⇒ Object
- #validations_banner ⇒ Object
Constructor Details
#initialize(options) ⇒ Complete
Returns a new instance of Complete.
19 20 21 22 23 24 25 |
# File 'lib/avm/git/issue/complete.rb', line 19 def initialize() consumer = ::EacRubyUtils::OptionsConsumer.new() dir, @skip_validations = consumer.consume_all(:dir, :skip_validations) validate_skip_validations consumer.validate @git = ::EacLauncher::Git::Base.new(dir) end |
Instance Attribute Details
#skip_validations ⇒ Object (readonly)
Returns the value of attribute skip_validations.
17 18 19 |
# File 'lib/avm/git/issue/complete.rb', line 17 def skip_validations @skip_validations 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
25 26 27 28 29 30 |
# File 'lib/avm/git/issue/complete/_local_branch.rb', line 25 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 |
# File 'lib/avm/git/issue/complete/_local_branch.rb', line 21 def branch_name_result ::Avm::Result.success_or_error(branch_name, issue_id.present?) 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 |
#clean_workspace_result ⇒ Object
7 8 9 10 |
# File 'lib/avm/git/issue/complete/_working_tree.rb', line 7 def clean_workspace_result r = @git.dirty_files.none? ::Avm::Result.success_or_error(r ? 'yes' : 'no', r) 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
42 43 44 |
# File 'lib/avm/git/issue/complete/_local_branch.rb', line 42 def follow_master? remote_master_hash ? @git.descendant?(branch_hash, remote_master_hash) : true end |
#follow_master_result ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/avm/git/issue/complete/_local_branch.rb', line 32 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
41 42 43 44 |
# File 'lib/avm/git/issue/complete.rb', line 41 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
46 47 48 49 50 51 |
# File 'lib/avm/git/issue/complete/_local_branch.rb', line 46 def remove_local_branch info 'Removendo branch local...' bn = branch_name git(['checkout', branch_hash]) git(['branch', '-D', bn]) end |
#run ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/avm/git/issue/complete.rb', line 31 def run return false unless valid? assert_tag push remove_local_branch true end |
#start_banner ⇒ Object
27 28 29 |
# File 'lib/avm/git/issue/complete.rb', line 27 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
20 21 22 |
# File 'lib/avm/git/issue/complete/_validations.rb', line 20 def valid? validations.map(&:result).none?(&:error?) end |
#validate_skip_validations ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/avm/git/issue/complete/_validations.rb', line 44 def validate_skip_validations skip_validations.each do |validation| next if VALIDATIONS.keys.include?(validation) raise "\"#{validation}\" is not a registered validation" end end |
#validation_result(key) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/avm/git/issue/complete/_validations.rb', line 36 def validation_result(key) if skip_validations.include?(key) ::Avm::Result.neutral('skipped') else send("#{key}_result") end end |
#validations ⇒ Object
30 31 32 33 34 |
# File 'lib/avm/git/issue/complete/_validations.rb', line 30 def validations VALIDATIONS.map do |key, label| ::OpenStruct.new(key: key, label: label, result: validation_result(key)) end end |
#validations_banner ⇒ Object
24 25 26 27 28 |
# File 'lib/avm/git/issue/complete/_validations.rb', line 24 def validations.each do |v| infov "[#{v.key}] #{v.label}", v.result.label end end |