avm-tools 0.8.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ec26f5acffe872504b8bb38a3ac9576c5e8a0371ed59bf47291bbaa7ee409e86
4
- data.tar.gz: abff823fcf4d67c8585234b44bc02c09c71f5abfc4c07cb81879c12e6d207f30
3
+ metadata.gz: e8b25be966f98e7a370ad067bda6a661bcc1f88d07dd69bffec2348892398bf7
4
+ data.tar.gz: f3638c69e985e7949e9b46a699aa11ab0d317ac58bccb738af02de82ad822680
5
5
  SHA512:
6
- metadata.gz: 21c93ff405233684dc17a31d1fcecaab294f04de974984745e48539099d88e09f3e1006f9e576a2b34205ebae75668c58a5286de1d7f72ec917ab4c43416e54c
7
- data.tar.gz: 99e36aebae62dfd8d654177019156d9c7ba2dc187b778aad3b206da3e637657eb3f68bc968bb1293d717379d73447d19148d45114f41d738aeb17e48bfef2ddd
6
+ metadata.gz: 8277fe1870b2d7f3d0ef25ae40fec80173ba517cbadae7b738d6c7988ea8e68ead17b3c514b771d6d243bef645143e523c79ed9c74598b00b7e94e19f75432b0
7
+ data.tar.gz: 82c493e6451ab92ff90edc735c23324224ad11e977f852ec052c606df44667f52f46f86bc71ef8f8939c4ccbab9a8b55457cf970197a0adc13daebeeaf5f134e
data/lib/avm.rb CHANGED
@@ -2,7 +2,10 @@
2
2
 
3
3
  module Avm
4
4
  require 'avm/configs'
5
+ require 'avm/git'
5
6
  require 'avm/instances'
7
+ require 'avm/patches'
8
+ require 'avm/result'
6
9
  require 'avm/stereotypes'
7
10
  require 'avm/tools'
8
11
  end
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'eac_ruby_utils/require_sub'
4
+ ::EacRubyUtils.require_sub(__FILE__)
5
+
3
6
  module Avm
4
7
  module Files
5
- Dir["#{File.dirname(__FILE__)}/#{::File.basename(__FILE__, '.*')}/*.rb"].each do |path|
6
- require path
7
- end
8
8
  end
9
9
  end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/require_sub'
4
+ ::EacRubyUtils.require_sub(__FILE__)
5
+
6
+ module Avm
7
+ module Git
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/require_sub'
4
+ ::EacRubyUtils.require_sub(__FILE__)
5
+
6
+ module Avm
7
+ module Git
8
+ module Issue
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/patches/eac_launcher_git_base'
4
+ require 'eac_ruby_utils/console/speaker'
5
+ require 'eac_ruby_utils/options_consumer'
6
+ require 'eac_ruby_utils/require_sub'
7
+ require 'eac_ruby_utils/simple_cache'
8
+ ::EacRubyUtils.require_sub(__FILE__)
9
+
10
+ module Avm
11
+ module Git
12
+ module Issue
13
+ class Complete
14
+ include ::EacRubyUtils::SimpleCache
15
+ include ::EacRubyUtils::Console::Speaker
16
+
17
+ attr_reader :no_avm_branch_name
18
+
19
+ def initialize(options)
20
+ consumer = ::EacRubyUtils::OptionsConsumer.new(options)
21
+ dir, @no_avm_branch_name = consumer.consume_all(:dir, :no_avm_branch_name)
22
+ consumer.validate
23
+ @git = ::EacLauncher::Git::Base.new(dir)
24
+ end
25
+
26
+ def start_banner
27
+ validations_banner
28
+ end
29
+
30
+ def run
31
+ return false unless valid?
32
+
33
+ assert_tag
34
+ push
35
+ remove_local_branch
36
+ true
37
+ end
38
+
39
+ def issue_id
40
+ m = branch_name.match(/\A#{Regexp.quote('issue_')}(\d+)\z/)
41
+ m ? m[1].to_i : nil
42
+ end
43
+
44
+ private
45
+
46
+ def git(args, exit_outputs = {})
47
+ r = @git.execute!(args, exit_outputs: exit_outputs)
48
+ r.is_a?(String) ? r.strip : r
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/result'
4
+
5
+ module Avm
6
+ module Git
7
+ module Issue
8
+ class Complete
9
+ def commits_result
10
+ ::Avm::Result.success_or_error(
11
+ commits.any? ? 'yes' : 'none',
12
+ commits.any?
13
+ )
14
+ end
15
+
16
+ def commits_uncached
17
+ return [] unless branch_hash && follow_master?
18
+
19
+ interval = remote_master_hash ? "#{remote_master_hash}..#{branch_hash}" : branch_hash
20
+ @git.execute!('rev-list', interval).each_line.map(&:strip)
21
+ end
22
+
23
+ def bifurcations_result
24
+ commits.each do |commit|
25
+ if multiple_parents?(commit)
26
+ return ::Avm::Result.error("#{commit} has multiple parents")
27
+ end
28
+ end
29
+ ::Avm::Result.success('no')
30
+ end
31
+
32
+ def multiple_parents?(commit)
33
+ commit_parents(commit).count > 1
34
+ end
35
+
36
+ def commit_parents(commit)
37
+ @git.execute!('log', '--pretty=%P', '-n', '1', commit).split(' ').map(&:strip)
38
+ .select(&:present?)
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/result'
4
+
5
+ module Avm
6
+ module Git
7
+ module Issue
8
+ class Complete
9
+ def branch
10
+ @git.current_branch
11
+ end
12
+
13
+ def branch_hash
14
+ @git.rev_parse("refs/heads/#{branch}")
15
+ end
16
+
17
+ def branch_name
18
+ branch.split('/')[-1]
19
+ end
20
+
21
+ def branch_name_result
22
+ ::Avm::Result.success_or_error(
23
+ branch_name,
24
+ issue_id || no_avm_branch_name
25
+ )
26
+ end
27
+
28
+ def branch_hash_result
29
+ ::Avm::Result.success_or_error(
30
+ branch_hash,
31
+ branch_hash.present?
32
+ )
33
+ end
34
+
35
+ def follow_master_result
36
+ return ::Avm::Result.neutral('No branch hash') unless branch_hash
37
+
38
+ r = follow_master?
39
+ ::Avm::Result.success_or_error(
40
+ r ? 'yes' : 'no',
41
+ r
42
+ )
43
+ end
44
+
45
+ def follow_master?
46
+ remote_master_hash ? @git.descendant?(branch_hash, remote_master_hash) : true
47
+ end
48
+
49
+ def remove_local_branch
50
+ info 'Removendo branch local...'
51
+ bn = branch_name
52
+ git(['checkout', branch_hash])
53
+ git(['branch', '-D', bn])
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/result'
4
+
5
+ module Avm
6
+ module Git
7
+ module Issue
8
+ class Complete
9
+ def assert_tag
10
+ if tag_hash
11
+ return if tag_hash == branch_hash
12
+
13
+ delete_tag
14
+ end
15
+ create_tag
16
+ end
17
+
18
+ def delete_tag
19
+ info 'Removendo tag...'
20
+ git(['tag', '-d', branch_name])
21
+ end
22
+
23
+ def tag
24
+ "refs/tags/#{branch_name}"
25
+ end
26
+
27
+ def tag_hash
28
+ @git.rev_parse(tag)
29
+ end
30
+
31
+ def create_tag
32
+ git(['tag', branch_name, branch_hash])
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Avm
4
+ module Git
5
+ module Issue
6
+ class Complete
7
+ def dry_push_args
8
+ %w[push --dry-run] + [remote_name] + pushs
9
+ end
10
+
11
+ def dry_push_result
12
+ return ::Avm::Result.error('Nothing to push') if pushs.empty?
13
+
14
+ r = @git.execute(dry_push_args)
15
+ message = if r.fetch(:exit_code).zero?
16
+ 'ok'
17
+ else
18
+ r.fetch(:stderr) + "\n#{::Shellwords.join(dry_push_args)}"
19
+ end
20
+ ::Avm::Result.success_or_error(message, r.fetch(:exit_code).zero?)
21
+ end
22
+
23
+ def push
24
+ if pushs.empty?
25
+ info 'PUSH: Nada a enviar'
26
+ else
27
+ info "PUSH: enviando \"#{pushs}\"..."
28
+ git(%w[push origin] + pushs)
29
+ end
30
+ end
31
+
32
+ def pushs_uncached
33
+ [master_push, remove_branch_push, tag_push].reject(&:nil?)
34
+ end
35
+
36
+ def master_push
37
+ remote_master_hash != branch_hash ? "#{branch_hash}:refs/heads/master" : nil
38
+ end
39
+
40
+ def remove_branch_push
41
+ remote_branch_hash ? ":refs/heads/#{branch}" : nil
42
+ end
43
+
44
+ def tag_push
45
+ return nil unless !remote_tag_hash || remote_tag_hash != branch_hash
46
+
47
+ "#{branch_hash}:#{tag}"
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Avm
4
+ module Git
5
+ module Issue
6
+ class Complete
7
+ def remote_master_hash
8
+ remote_hashs['refs/heads/master']
9
+ end
10
+
11
+ def remote_branch_hash
12
+ remote_hashs["refs/heads/#{branch}"]
13
+ end
14
+
15
+ def remote_tag_hash
16
+ remote_hashs[tag]
17
+ end
18
+
19
+ private
20
+
21
+ def remote_name
22
+ 'origin'
23
+ end
24
+
25
+ def remote_hashs_uncached
26
+ @git.remote_hashs(remote_name)
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/result'
4
+
5
+ module Avm
6
+ module Git
7
+ module Issue
8
+ class Complete
9
+ VALIDATIONS = {
10
+ branch_name: 'Branch name',
11
+ branch_hash: 'Branch hash',
12
+ follow_master: 'Follow master?',
13
+ commits: 'Commits?',
14
+ bifurcations: 'Bifurcations?',
15
+ dry_push: 'Dry push?'
16
+ }.freeze
17
+
18
+ def valid?
19
+ validations.values.none?(&:error?)
20
+ end
21
+
22
+ def validations_banner
23
+ validations.each do |label, result|
24
+ infov label, result.label
25
+ end
26
+ end
27
+
28
+ def validations
29
+ VALIDATIONS.map do |key, label|
30
+ [label, send("#{key}_result")]
31
+ end.to_h
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/require_sub'
4
+ ::EacRubyUtils.require_sub(__FILE__)
5
+
6
+ module Avm
7
+ module Patches
8
+ end
9
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_launcher/git/base'
4
+ require 'eac_ruby_utils/patch'
5
+ require 'eac_ruby_utils/require_sub'
6
+ ::EacRubyUtils.require_sub(__FILE__)
7
+
8
+ module Avm
9
+ module Patches
10
+ module EacLauncherGitBase
11
+ def execute(*args)
12
+ args, options = build_args(args)
13
+ ::EacRubyUtils::Envs.local.command(*args).execute(options)
14
+ end
15
+ end
16
+ end
17
+ end
18
+
19
+ ::EacRubyUtils.patch(::EacLauncher::Git::Base, ::Avm::Patches::EacLauncherGitBase)
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'colorized_string'
4
+ require 'eac_ruby_utils/listable'
5
+
6
+ module Avm
7
+ class Result < ::SimpleDelegator
8
+ include ::EacRubyUtils::Listable
9
+
10
+ lists.add_string :type, :success, :error, :neutral
11
+
12
+ lists.type.values.each do |type|
13
+ class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
14
+ def self.#{type}(value)
15
+ new(value, TYPE_#{type.upcase})
16
+ end
17
+ RUBY_EVAL
18
+ end
19
+
20
+ TYPE_SUCCESS_COLOR = 'green'
21
+ TYPE_ERROR_COLOR = 'red'
22
+ TYPE_NEUTRAL_COLOR = 'light_black'
23
+
24
+ class << self
25
+ def success_or_error(value, success)
26
+ new(value, success ? ::Avm::Result::TYPE_SUCCESS : ::Avm::Result::TYPE_ERROR)
27
+ end
28
+ end
29
+
30
+ attr_reader :type
31
+
32
+ def initialize(value, type)
33
+ super(value)
34
+ validate_type(type)
35
+ @type = type
36
+ end
37
+
38
+ def label
39
+ label_fg
40
+ end
41
+
42
+ def label_fg
43
+ ColorizedString.new(to_s).send(type_color)
44
+ end
45
+
46
+ def label_bg
47
+ ColorizedString.new(to_s).light_white.send("on_#{type_color}")
48
+ end
49
+
50
+ def type_color
51
+ self.class.const_get("type_#{type}_color".upcase)
52
+ end
53
+
54
+ lists.type.values.each do |type|
55
+ class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
56
+ def #{type}?
57
+ @type == '#{type}'
58
+ end
59
+ RUBY_EVAL
60
+ end
61
+
62
+ private
63
+
64
+ def validate_type(type)
65
+ return if self.class.lists.type.values.include?(type)
66
+
67
+ raise "Tipo desconhecido: \"#{type}\" (Válido: #{self.class.lists.type.values.join(', ')})"
68
+ end
69
+ end
70
+ end
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'eac_ruby_utils/require_sub'
4
+ ::EacRubyUtils.require_sub(__FILE__)
5
+
3
6
  module Avm
4
7
  module Stereotypes
5
- Dir["#{File.dirname(__FILE__)}/#{::File.basename(__FILE__, '.*')}/*.rb"].each do |path|
6
- require path
7
- end
8
8
  end
9
9
  end
@@ -1,11 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'eac_ruby_utils/require_sub'
4
+ ::EacRubyUtils.require_sub(__FILE__)
5
+
3
6
  module Avm
4
7
  module Stereotypes
5
8
  module Postgresql
6
- Dir["#{File.dirname(__FILE__)}/#{::File.basename(__FILE__, '.*')}/*.rb"].each do |path|
7
- require path
8
- end
9
9
  end
10
10
  end
11
11
  end
@@ -1,9 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'eac_ruby_utils/console/docopt_runner'
4
- Dir["#{File.dirname(__FILE__)}/#{::File.basename(__FILE__, '.*')}/*.rb"].each do |path|
5
- require path
6
- end
4
+ require 'eac_ruby_utils/require_sub'
5
+ ::EacRubyUtils.require_sub(__FILE__)
7
6
 
8
7
  module Avm
9
8
  module Tools
@@ -1,9 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'eac_ruby_utils/console/docopt_runner'
4
- Dir["#{File.dirname(__FILE__)}/#{::File.basename(__FILE__, '.*')}/*.rb"].each do |path|
5
- require path
6
- end
4
+ require 'eac_ruby_utils/require_sub'
5
+ ::EacRubyUtils.require_sub(__FILE__)
7
6
 
8
7
  module Avm
9
8
  module Tools
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/console/docopt_runner'
4
+ require 'eac_ruby_utils/require_sub'
5
+ ::EacRubyUtils.require_sub(__FILE__)
6
+
7
+ module Avm
8
+ module Tools
9
+ class Runner < ::EacRubyUtils::Console::DocoptRunner
10
+ class Git < ::EacRubyUtils::Console::DocoptRunner
11
+ class Issue < ::EacRubyUtils::Console::DocoptRunner
12
+ DOC = <<~DOCOPT
13
+ Issue utilities for AVM/Git.
14
+
15
+ Usage:
16
+ __PROGRAM__ [options] __SUBCOMMANDS__
17
+ __PROGRAM__ -h | --help
18
+
19
+ Options:
20
+ -h --help Show this screen.
21
+ DOCOPT
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/console/docopt_runner'
4
+ require 'eac_ruby_utils/console/speaker'
5
+ require 'avm/git/issue/complete'
6
+
7
+ module Avm
8
+ module Tools
9
+ class Runner < ::EacRubyUtils::Console::DocoptRunner
10
+ class Git < ::EacRubyUtils::Console::DocoptRunner
11
+ class Issue < ::EacRubyUtils::Console::DocoptRunner
12
+ class Complete < ::EacRubyUtils::Console::DocoptRunner
13
+ include ::EacRubyUtils::Console::Speaker
14
+
15
+ DOC = <<~DOCOPT
16
+ Closes a issue in a Git repository.
17
+
18
+ Usage:
19
+ __PROGRAM__ [options]
20
+ __PROGRAM__ -h | --help
21
+
22
+ Options:
23
+ -h --help Show this screen.
24
+ -C <path> Path to Git repository [default: .].
25
+ --no-avm Does not require valid AVM issue\'s branch/tag name.
26
+ -y --yes Does not ask for user confirmation.
27
+ DOCOPT
28
+
29
+ def run
30
+ complete = ::Avm::Git::Issue::Complete.new(git_complete_issue_options)
31
+ complete.start_banner
32
+ fatal_error('Some validation did not pass') unless complete.valid?
33
+ complete.run if confirm?
34
+ end
35
+
36
+ private
37
+
38
+ def confirm?
39
+ options.fetch('--yes') || request_input('Confirm issue completion?', bool: true)
40
+ end
41
+
42
+ def git_complete_issue_options
43
+ { dir: options.fetch('-C'), no_avm_branch_name: options.fetch('--no-avm') }
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Avm
4
4
  module Tools
5
- VERSION = '0.8.0'
5
+ VERSION = '0.9.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: avm-tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Esquilo Azul Company
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-08-21 00:00:00.000000000 Z
11
+ date: 2019-08-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: eac_launcher
@@ -17,6 +17,9 @@ dependencies:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0.6'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 0.6.1
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -24,20 +27,23 @@ dependencies:
24
27
  - - "~>"
25
28
  - !ruby/object:Gem::Version
26
29
  version: '0.6'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 0.6.1
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: eac_ruby_utils
29
35
  requirement: !ruby/object:Gem::Requirement
30
36
  requirements:
31
37
  - - "~>"
32
38
  - !ruby/object:Gem::Version
33
- version: '0.10'
39
+ version: '0.11'
34
40
  type: :runtime
35
41
  prerelease: false
36
42
  version_requirements: !ruby/object:Gem::Requirement
37
43
  requirements:
38
44
  - - "~>"
39
45
  - !ruby/object:Gem::Version
40
- version: '0.10'
46
+ version: '0.11'
41
47
  - !ruby/object:Gem::Dependency
42
48
  name: rspec
43
49
  requirement: !ruby/object:Gem::Requirement
@@ -99,10 +105,22 @@ files:
99
105
  - lib/avm/configs.rb
100
106
  - lib/avm/files.rb
101
107
  - lib/avm/files/rotate.rb
108
+ - lib/avm/git.rb
109
+ - lib/avm/git/issue.rb
110
+ - lib/avm/git/issue/complete.rb
111
+ - lib/avm/git/issue/complete/_commits.rb
112
+ - lib/avm/git/issue/complete/_local_branch.rb
113
+ - lib/avm/git/issue/complete/_local_tag.rb
114
+ - lib/avm/git/issue/complete/_push.rb
115
+ - lib/avm/git/issue/complete/_remote.rb
116
+ - lib/avm/git/issue/complete/_validations.rb
102
117
  - lib/avm/instances.rb
103
118
  - lib/avm/instances/application.rb
104
119
  - lib/avm/instances/base.rb
105
120
  - lib/avm/instances/entries.rb
121
+ - lib/avm/patches.rb
122
+ - lib/avm/patches/eac_launcher_git_base.rb
123
+ - lib/avm/result.rb
106
124
  - lib/avm/stereotypes.rb
107
125
  - lib/avm/stereotypes/eac_wordpress_base0/instance.rb
108
126
  - lib/avm/stereotypes/postgresql.rb
@@ -110,7 +128,6 @@ files:
110
128
  - lib/avm/stereotypes/postgresql/instance_with.rb
111
129
  - lib/avm/tools.rb
112
130
  - lib/avm/tools/git.rb
113
- - lib/avm/tools/git/complete_issue.rb
114
131
  - lib/avm/tools/runner.rb
115
132
  - lib/avm/tools/runner/eac_wordpress_base0.rb
116
133
  - lib/avm/tools/runner/eac_wordpress_base0/data.rb
@@ -119,7 +136,8 @@ files:
119
136
  - lib/avm/tools/runner/files.rb
120
137
  - lib/avm/tools/runner/files/rotate.rb
121
138
  - lib/avm/tools/runner/git.rb
122
- - lib/avm/tools/runner/git/complete_issue.rb
139
+ - lib/avm/tools/runner/git/issue.rb
140
+ - lib/avm/tools/runner/git/issue/complete.rb
123
141
  - lib/avm/tools/version.rb
124
142
  homepage:
125
143
  licenses: []
@@ -1,142 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'eac_launcher/git/base'
4
- require 'eac_ruby_utils/console/speaker'
5
- require 'eac_ruby_utils/simple_cache'
6
-
7
- module Avm
8
- module Tools
9
- module Git
10
- class CompleteIssue
11
- include ::EacRubyUtils::SimpleCache
12
- include ::EacRubyUtils::Console::Speaker
13
-
14
- def initialize(options)
15
- @git = ::EacLauncher::Git::Base.new(options.fetch(:dir))
16
- run
17
- end
18
-
19
- def run
20
- check_issue_branch
21
- assert_tag
22
- push
23
- remove_local_branch
24
- end
25
-
26
- def branch
27
- @git.current_branch
28
- end
29
-
30
- def branch_hash
31
- @git.rev_parse("refs/heads/#{branch}")
32
- end
33
-
34
- def branch_name
35
- branch.split('/')[-1]
36
- end
37
-
38
- def issue_id
39
- m = branch_name.match(/\A#{Regexp.quote('issue_')}(\d+)\z/)
40
- m ? m[1].to_i : nil
41
- end
42
-
43
- def remote_master_hash
44
- remote_hashs['refs/heads/master']
45
- end
46
-
47
- def remote_branch_hash
48
- remote_hashs["refs/heads/#{branch}"]
49
- end
50
-
51
- def remote_tag_hash
52
- remote_hashs[tag]
53
- end
54
-
55
- private
56
-
57
- attr_reader :options
58
-
59
- def remote_name
60
- 'origin'
61
- end
62
-
63
- def check_issue_branch
64
- raise "Branch is not a issue branch (\"#{branch}\"|\"#{branch_name}\")" unless
65
- branch_valid?
66
- raise "Hash not found for \"#{branch}\"" unless branch_hash
67
- end
68
-
69
- def branch_valid?
70
- issue_id || options[:no_avm_branch_name]
71
- end
72
-
73
- def assert_tag
74
- if tag_hash
75
- return if tag_hash == branch_hash
76
-
77
- delete_tag
78
- end
79
- create_tag
80
- end
81
-
82
- def delete_tag
83
- info 'Removendo tag...'
84
- git(['tag', '-d', branch_name])
85
- end
86
-
87
- def push
88
- if pushs.empty?
89
- info 'PUSH: Nada a enviar'
90
- else
91
- info "PUSH: enviando \"#{pushs}\"..."
92
- git(%w[push origin] + pushs)
93
- end
94
- end
95
-
96
- def pushs_uncached
97
- [master_push, remove_branch_push, tag_push].reject(&:nil?)
98
- end
99
-
100
- def master_push
101
- remote_master_hash != branch_hash ? "#{branch_hash}:refs/heads/master" : nil
102
- end
103
-
104
- def remove_branch_push
105
- remote_branch_hash ? ":refs/heads/#{branch}" : nil
106
- end
107
-
108
- def tag_push
109
- !remote_tag_hash || remote_tag_hash != branch_hash ? tag : nil
110
- end
111
-
112
- def remove_local_branch
113
- info 'Removendo branch local...'
114
- bn = branch_name
115
- git(['checkout', branch_hash])
116
- git(['branch', '-D', bn])
117
- end
118
-
119
- def tag
120
- "refs/tags/#{branch_name}"
121
- end
122
-
123
- def tag_hash
124
- @git.rev_parse(tag)
125
- end
126
-
127
- def create_tag
128
- git(['tag', branch_name, branch_hash])
129
- end
130
-
131
- def remote_hashs_uncached
132
- @git.remote_hashs(remote_name)
133
- end
134
-
135
- def git(args, exit_outputs = {})
136
- r = @git.execute!(args, exit_outputs: exit_outputs)
137
- r.is_a?(String) ? r.strip : r
138
- end
139
- end
140
- end
141
- end
142
- end
@@ -1,36 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'eac_ruby_utils/console/docopt_runner'
4
- require 'avm/tools/git/complete_issue'
5
-
6
- module Avm
7
- module Tools
8
- class Runner < ::EacRubyUtils::Console::DocoptRunner
9
- class Git < ::EacRubyUtils::Console::DocoptRunner
10
- class CompleteIssue < ::EacRubyUtils::Console::DocoptRunner
11
- DOC = <<~DOCOPT
12
- Closes a issue in a Git repository.
13
-
14
- Usage:
15
- __PROGRAM__ [options]
16
- __PROGRAM__ -h | --help
17
-
18
- Options:
19
- -h --help Show this screen.
20
- -C <path> Path to Git repository [default: .].
21
- DOCOPT
22
-
23
- def run
24
- ::Avm::Tools::Git::CompleteIssue.new(git_complete_issue_options)
25
- end
26
-
27
- private
28
-
29
- def git_complete_issue_options
30
- { dir: options.fetch('-C') }
31
- end
32
- end
33
- end
34
- end
35
- end
36
- end