avm-tools 0.85.1 → 0.89.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. checksums.yaml +4 -4
  2. data/lib/avm/eac_rails_base1/runner/log.rb +43 -0
  3. data/lib/avm/eac_rails_base1/runner_with/bundle.rb +2 -32
  4. data/lib/avm/eac_rails_base1/runner_with/rails_environment.rb +47 -0
  5. data/lib/avm/eac_webapp_base0/deploy.rb +16 -4
  6. data/lib/avm/eac_webapp_base0/deploy/appended_directories.rb +1 -1
  7. data/lib/avm/eac_webapp_base0/deploy/git_info.rb +1 -1
  8. data/lib/avm/eac_webapp_base0/instance.rb +2 -0
  9. data/lib/avm/eac_webapp_base0/runner/deploy.rb +13 -21
  10. data/lib/avm/git/file_auto_fixup.rb +22 -3
  11. data/lib/avm/instances/base/auto_values/filesystem.rb +12 -0
  12. data/lib/avm/instances/runner.rb +3 -5
  13. data/lib/avm/projects/stereotypes/git/update.rb +42 -0
  14. data/lib/avm/projects/stereotypes/git/update/subrepo.rb +85 -0
  15. data/lib/avm/tools/runner.rb +2 -4
  16. data/lib/avm/tools/runner/eac_rails_base0.rb +1 -1
  17. data/lib/avm/tools/runner/eac_rails_base0/apache_path.rb +1 -1
  18. data/lib/avm/tools/runner/eac_redmine_base0.rb +1 -1
  19. data/lib/avm/tools/runner/eac_redmine_base0/core_update.rb +1 -1
  20. data/lib/avm/tools/runner/eac_redmine_base0/docker.rb +1 -1
  21. data/lib/avm/tools/runner/eac_redmine_base0/project_rename.rb +1 -1
  22. data/lib/avm/tools/runner/eac_webapp_base0.rb +14 -0
  23. data/lib/avm/tools/runner/eac_wordpress_base0.rb +1 -1
  24. data/lib/avm/tools/runner/eac_writings_base0.rb +1 -1
  25. data/lib/avm/tools/runner/eac_writings_base1.rb +1 -1
  26. data/lib/avm/tools/runner/files.rb +7 -15
  27. data/lib/avm/tools/runner/files/format.rb +18 -27
  28. data/lib/avm/tools/runner/files/rotate.rb +11 -21
  29. data/lib/avm/tools/runner/git.rb +10 -15
  30. data/lib/avm/tools/runner/git/auto_commit.rb +2 -2
  31. data/lib/avm/tools/runner/git/auto_fixup.rb +23 -16
  32. data/lib/avm/tools/runner/git/commit.rb +2 -2
  33. data/lib/avm/tools/runner/git/deploy.rb +18 -28
  34. data/lib/avm/tools/runner/git/dirty_files.rb +2 -2
  35. data/lib/avm/tools/runner/git/issue.rb +2 -2
  36. data/lib/avm/tools/runner/git/organize.rb +2 -2
  37. data/lib/avm/tools/runner/git/revisions_test.rb +2 -2
  38. data/lib/avm/tools/runner/git/subrepo.rb +2 -2
  39. data/lib/avm/tools/runner/git/subrepo/check.rb +2 -2
  40. data/lib/avm/tools/runner/git/subrepo/clone.rb +2 -2
  41. data/lib/avm/tools/runner/git/subrepo/fix.rb +4 -3
  42. data/lib/avm/tools/runner/instance.rb +4 -7
  43. data/lib/avm/tools/runner/instance/info.rb +5 -8
  44. data/lib/avm/tools/runner/launcher.rb +1 -1
  45. data/lib/avm/tools/runner/launcher/instances.rb +1 -1
  46. data/lib/avm/tools/runner/launcher/projects.rb +1 -1
  47. data/lib/avm/tools/runner/launcher/publish.rb +1 -1
  48. data/lib/avm/tools/runner/local_project.rb +5 -8
  49. data/lib/avm/tools/runner/local_project/eac_writings_base0.rb +2 -2
  50. data/lib/avm/tools/runner/local_project/eac_writings_base0/build_chapters.rb +2 -2
  51. data/lib/avm/tools/runner/local_project/eac_writings_base0/build_single.rb +2 -2
  52. data/lib/avm/tools/runner/local_project/eac_writings_base0/info.rb +2 -2
  53. data/lib/avm/tools/runner/local_project/eac_writings_base1.rb +2 -2
  54. data/lib/avm/tools/runner/local_project/eac_writings_base1/build.rb +2 -2
  55. data/lib/avm/tools/runner/local_project/info.rb +2 -2
  56. data/lib/avm/tools/runner/local_project/ruby.rb +2 -2
  57. data/lib/avm/tools/runner/local_project/ruby/bundler.rb +2 -2
  58. data/lib/avm/tools/runner/local_project/ruby/bundler/gemfile_lock.rb +2 -2
  59. data/lib/avm/tools/runner/local_project/test.rb +2 -2
  60. data/lib/avm/tools/runner/local_project/update.rb +2 -2
  61. data/lib/avm/tools/runner/local_project/version_bump.rb +10 -13
  62. data/lib/avm/tools/runner/ruby.rb +1 -1
  63. data/lib/avm/tools/runner/ruby/gems.rb +1 -1
  64. data/lib/avm/tools/runner/ruby/gems/generate.rb +1 -1
  65. data/lib/avm/tools/runner/ruby/rubocop.rb +1 -1
  66. data/lib/avm/tools/runner/self.rb +1 -1
  67. data/lib/avm/tools/runner/self/docker.rb +1 -1
  68. data/lib/avm/tools/version.rb +1 -1
  69. data/vendor/eac_cli/lib/eac_cli/docopt/runner_context_replacement.rb +15 -0
  70. data/vendor/eac_cli/lib/eac_cli/docopt/runner_extension.rb +5 -0
  71. data/vendor/eac_cli/lib/eac_cli/parser/alternative.rb +4 -4
  72. data/vendor/eac_cli/lib/eac_cli/parser/alternative/long_options.rb +37 -0
  73. data/vendor/eac_cli/lib/eac_cli/parser/alternative/option_argument.rb +29 -0
  74. data/vendor/eac_cli/lib/eac_cli/parser/alternative/options.rb +7 -36
  75. data/vendor/eac_cli/lib/eac_cli/parser/alternative/short_options.rb +45 -0
  76. data/vendor/eac_cli/lib/eac_cli/runner.rb +0 -48
  77. data/vendor/eac_cli/lib/eac_cli/runner/after_class_methods.rb +29 -0
  78. data/vendor/eac_cli/lib/eac_cli/runner/instance_methods.rb +31 -0
  79. data/vendor/eac_cli/lib/eac_cli/runner_with/subcommands.rb +15 -3
  80. data/vendor/eac_cli/lib/eac_cli/version.rb +1 -1
  81. data/vendor/eac_cli/spec/lib/eac_cli/runner_spec.rb +22 -1
  82. data/vendor/eac_ruby_base0/lib/eac_ruby_base0/application.rb +1 -0
  83. data/vendor/eac_ruby_base0/lib/eac_ruby_base0/runner.rb +9 -6
  84. data/vendor/eac_ruby_base0/lib/eac_ruby_base0/runner/test_all.rb +4 -9
  85. data/vendor/eac_ruby_base0/lib/eac_ruby_base0/version.rb +1 -1
  86. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/fs/traverser.rb +0 -2
  87. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/inflector.rb +4 -1
  88. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/local_time_zone.rb +38 -0
  89. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/kernel.rb +4 -0
  90. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/kernel/nyi.rb +8 -0
  91. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module/template.rb +10 -0
  92. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/template.rb +1 -8
  93. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/time/default_time_zone_set.rb +3 -2
  94. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/version.rb +1 -1
  95. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/yaml.rb +8 -0
  96. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/inflector_spec.rb +2 -1
  97. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/local_time_zone_spec.rb +17 -0
  98. metadata +18 -3
  99. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/time/local_time_zone.rb +0 -25
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 43d475cc5c1bf70580258451dfada46e601167d1b4304f102fd334b21862a922
4
- data.tar.gz: 0b2230eb8368b7315e437d7218144bbeaffe735887fa86fd6dec6647c545bd4a
3
+ metadata.gz: 9acbf7ad72627c97018d603c65da21c1875efea79caa7569059d5fd1aeb083e2
4
+ data.tar.gz: 8d0bb06826ece8223ed806348cf91f36c8117ebba3ceb05247b6947b54da44f0
5
5
  SHA512:
6
- metadata.gz: 3d45fbfd1797ba0e24a1c44cec1a260c1a12b457f486991f55befde788de312959084d78717fedb7ef593731399aa9be9534512e3e9af1c71c7ac706cde3b262
7
- data.tar.gz: 5d539d2be00bfc34491192fe927b98ec977af4f474790afaf03eda326b5db8749cbfa8e97ef98981c5663a444f3a703c6189a5b7688582b95cef44458648d7e1
6
+ metadata.gz: f249739403ccc5346e161f6481acd020d369a02b00b01da1b6c80addc6bcce58d2dc7724cf923929e146e3cac1b8e5e557e82f66cb9f501da8e44f30f358b5c8
7
+ data.tar.gz: a47f7c215bedfe5f870ba8a6bbbaf2e579c0c31b017546894c43e0421d75362b366dace3cfcd2bb9f72df7a3037866385b9c928e9389d558d0c39c1939928ea1
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/eac_rails_base1/runner_with/rails_environment'
4
+ require 'avm/eac_webapp_base0/runner'
5
+
6
+ module Avm
7
+ module EacRailsBase1
8
+ class Runner < ::Avm::EacWebappBase0::Runner
9
+ class Log
10
+ runner_with :help, ::Avm::EacRailsBase1::RunnerWith::RailsEnvironment do
11
+ desc 'Read application\'s log.'
12
+ bool_opt '-f', '--follow', 'Output appended data as the log grows.'
13
+ end
14
+
15
+ def run
16
+ start_banner
17
+ tail_command.system
18
+ end
19
+
20
+ private
21
+
22
+ def log_path
23
+ ::File.join(rails_instance.read_entry('fs_path'), 'log', "#{rails_environment}.log")
24
+ end
25
+
26
+ def start_banner
27
+ infov 'Environment', rails_environment
28
+ infov 'Log path', log_path
29
+ end
30
+
31
+ def tail_command
32
+ rails_instance.host_env.command(*tail_command_args)
33
+ end
34
+
35
+ def tail_command_args
36
+ r = %w[tail]
37
+ r << '--follow' if parsed.follow?
38
+ r + [log_path]
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -1,29 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'avm/eac_rails_base1/instance'
4
+ require 'avm/eac_rails_base1/runner_with/rails_environment'
4
5
  require 'eac_cli/runner'
5
6
 
6
7
  module Avm
7
8
  module EacRailsBase1
8
9
  module RunnerWith
9
10
  module Bundle
10
- DEFAULT_RAILS_ENVIRONMENT_CONSTANT = 'DEFAULT_RAILS_ENVIRONMENT'
11
-
12
11
  common_concern do
13
- include ::EacCli::Runner
14
-
15
- runner_definition do
16
- arg_opt '-e', '--environment', 'Specifies the environment for the runner to operate' \
17
- ' (test/development/production). Default: "development".'
18
- end
19
- end
20
-
21
- module ClassMethods
22
- def default_rails_environment
23
- const_get(DEFAULT_RAILS_ENVIRONMENT_CONSTANT)
24
- rescue ::NameError
25
- ::Avm::EacRailsBase1::Instance::DEFAULT_RAILS_ENVIRONMENT
26
- end
12
+ include ::Avm::EacRailsBase1::RunnerWith::RailsEnvironment
27
13
  end
28
14
 
29
15
  def bundle_command
@@ -35,22 +21,6 @@ module Avm
35
21
  infov 'Rails environment', rails_environment
36
22
  bundle_command.system!
37
23
  end
38
-
39
- def default_rails_environment
40
- self.class.default_rails_environment
41
- end
42
-
43
- def rails_instance
44
- if respond_to?(:runner_context)
45
- runner_context.call(:instance)
46
- else
47
- context(:instance)
48
- end
49
- end
50
-
51
- def rails_environment
52
- parsed.environment.presence || default_rails_environment
53
- end
54
24
  end
55
25
  end
56
26
  end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/eac_rails_base1/instance'
4
+ require 'eac_cli/runner'
5
+
6
+ module Avm
7
+ module EacRailsBase1
8
+ module RunnerWith
9
+ module RailsEnvironment
10
+ DEFAULT_RAILS_ENVIRONMENT_CONSTANT = 'DEFAULT_RAILS_ENVIRONMENT'
11
+
12
+ common_concern do
13
+ include ::EacCli::Runner
14
+
15
+ runner_definition do
16
+ arg_opt '-e', '--environment', 'Specifies the environment for the runner to operate' \
17
+ ' (test/development/production). Default: "development".'
18
+ end
19
+ end
20
+
21
+ module ClassMethods
22
+ def default_rails_environment
23
+ const_get(DEFAULT_RAILS_ENVIRONMENT_CONSTANT)
24
+ rescue ::NameError
25
+ ::Avm::EacRailsBase1::Instance::DEFAULT_RAILS_ENVIRONMENT
26
+ end
27
+ end
28
+
29
+ def default_rails_environment
30
+ self.class.default_rails_environment
31
+ end
32
+
33
+ def rails_environment
34
+ parsed.environment.presence || default_rails_environment
35
+ end
36
+
37
+ def rails_instance
38
+ if respond_to?(:runner_context)
39
+ runner_context.call(:instance)
40
+ else
41
+ context(:instance)
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -17,10 +17,16 @@ module Avm
17
17
 
18
18
  enable_console_speaker
19
19
  enable_simple_cache
20
- common_constructor :instance, :options, default: [{}]
20
+ enable_listable
21
+ lists.add_symbol :option, :appended_directories, :no_request_test, :reference
22
+ common_constructor :instance, :options, default: [{}] do
23
+ self.options = ::Avm::EacWebappBase0::Deploy.lists.option
24
+ .hash_keys_validate!(options.symbolize_keys)
25
+ end
21
26
 
22
- JOBS = %w[create_build_dir build_content append_instance_content write_on_target
23
- setup_files_units assert_instance_branch request_test].freeze
27
+ REQUEST_TEST_JOB = 'request_test'
28
+ JOBS = (%w[create_build_dir build_content append_instance_content write_on_target
29
+ setup_files_units assert_instance_branch] + [REQUEST_TEST_JOB]).freeze
24
30
  define_callbacks(*JOBS)
25
31
 
26
32
  def run
@@ -67,8 +73,14 @@ module Avm
67
73
 
68
74
  private
69
75
 
76
+ def jobs
77
+ r = JOBS.dup
78
+ r.delete(REQUEST_TEST_JOB) if options[OPTION_NO_REQUEST_TEST]
79
+ r
80
+ end
81
+
70
82
  def run_jobs
71
- JOBS.each do |job|
83
+ jobs.each do |job|
72
84
  run_callbacks job do
73
85
  send(job)
74
86
  end
@@ -17,7 +17,7 @@ module Avm
17
17
  end
18
18
 
19
19
  def appended_directories_from_options
20
- options[:appended_directories] || []
20
+ options[OPTION_APPENDED_DIRECTORIES] || []
21
21
  end
22
22
  end
23
23
  end
@@ -18,7 +18,7 @@ module Avm
18
18
  end
19
19
 
20
20
  def git_reference
21
- options[:reference] || DEFAULT_REFERENCE
21
+ options[OPTION_REFERENCE] || DEFAULT_REFERENCE
22
22
  end
23
23
 
24
24
  def git_reference_found_uncached
@@ -11,6 +11,8 @@ module Avm
11
11
  class Instance < ::Avm::Instances::Base
12
12
  include ::Avm::Postgresql::InstanceWith
13
13
 
14
+ FILES_UNITS = [].freeze
15
+
14
16
  def stereotype_name
15
17
  self.class.name.desconstantize.demodulize
16
18
  end
@@ -2,34 +2,25 @@
2
2
 
3
3
  require 'avm/instances/runner'
4
4
  require 'avm/path_string'
5
- require 'eac_ruby_utils/console/docopt_runner'
6
- require 'eac_ruby_utils/console/speaker'
5
+ require 'eac_cli/core_ext'
7
6
 
8
7
  module Avm
9
8
  module EacWebappBase0
10
9
  class Runner < ::Avm::Instances::Runner
11
- class Deploy < ::EacRubyUtils::Console::DocoptRunner
12
- include ::EacRubyUtils::Console::Speaker
13
-
14
- DOC = <<~DOCOPT
15
- Deploy for instance.
16
-
17
- Usage:
18
- __PROGRAM__ [options]
19
- __PROGRAM__ -h | --help
20
-
21
- Options:
22
- -h --help Show this screen.
23
- -r --reference=<git-reference> Git reference to deploy.
24
- -a --append-dirs=<append-dirs> Append directories to deploy (List separated by ":").
25
- DOCOPT
10
+ class Deploy
11
+ runner_with :help do
12
+ desc 'Deploy for instance.'
13
+ arg_opt '-r', '--reference', 'Git reference to deploy.'
14
+ arg_opt '-a', '--append-dirs', 'Append directories to deploy (List separated by ":").'
15
+ bool_opt '-T', '--no-request-test', 'Do not test web interface after deploy.'
16
+ end
26
17
 
27
18
  def deploy_class
28
- context(:stereotype_module).const_get('Deploy')
19
+ runner_context.call(:stereotype_module).const_get('Deploy')
29
20
  end
30
21
 
31
22
  def run
32
- result = deploy_class.new(context(:instance), deploy_options).run
23
+ result = deploy_class.new(runner_context.call(:instance), deploy_options).run
33
24
  if result.error?
34
25
  fatal_error result.to_s
35
26
  else
@@ -38,8 +29,9 @@ module Avm
38
29
  end
39
30
 
40
31
  def deploy_options
41
- { reference: options.fetch('--reference'),
42
- appended_directories: ::Avm::PathString.paths(options.fetch('--append-dirs')) }
32
+ { reference: parsed.reference,
33
+ appended_directories: ::Avm::PathString.paths(parsed.append_dirs),
34
+ no_request_test: parsed.no_request_test? }
43
35
  end
44
36
  end
45
37
  end
@@ -7,8 +7,12 @@ module Avm
7
7
  class FileAutoFixup
8
8
  enable_console_speaker
9
9
  enable_simple_cache
10
+ enable_listable
11
+ lists.add_symbol :option, :select, :unique
10
12
 
11
- common_constructor :git, :path
13
+ common_constructor :git, :path, :options, default: [{}] do
14
+ self.options = self.class.lists.option.hash_keys_validate!(options.symbolize_keys)
15
+ end
12
16
 
13
17
  COMMIT_FORMAT = '%h - %s (%cr)'
14
18
  COMMITS_SEARCH_INTERVAL = 'origin/master..HEAD'
@@ -18,8 +22,8 @@ module Avm
18
22
  start_banner
19
23
  if commits.count.zero?
20
24
  run_no_commits_found
21
- elsif commits.count == 1
22
- fixup_commit(commits.first)
25
+ elsif auto_selected_commit.present?
26
+ fixup_commit(auto_selected_commit)
23
27
  else
24
28
  run_commits_selection
25
29
  end
@@ -27,6 +31,10 @@ module Avm
27
31
 
28
32
  private
29
33
 
34
+ def auto_selected_commit_uncached
35
+ selected_commit_by_unique || select_commit_by_select
36
+ end
37
+
30
38
  def start_banner
31
39
  infov 'Path', path
32
40
  infov ' Commits found', commits.count
@@ -56,6 +64,17 @@ module Avm
56
64
  request_input('Which commit?', list: commits_by_position)
57
65
  end
58
66
 
67
+ def selected_commit_by_unique
68
+ return unless options[OPTION_UNIQUE]
69
+ return commits.first if commits.first
70
+ end
71
+
72
+ def select_commit_by_select
73
+ options[OPTION_SELECT].if_present(&:to_i).if_present do |v|
74
+ commits.find { |commit| commit.position == v }
75
+ end
76
+ end
77
+
59
78
  def commits_banner
60
79
  commits.each_with_index do |commit, _index|
61
80
  infov " #{commit.position}", format_commit(commit)
@@ -20,12 +20,24 @@ module Avm
20
20
  end
21
21
 
22
22
  def auto_fs_url
23
+ auto_fs_url_with_ssh || auto_fs_url_without_ssh
24
+ end
25
+
26
+ def auto_fs_url_with_ssh
23
27
  read_entry_optional('ssh.url').if_present do |ssh_url|
24
28
  read_entry_optional('fs_path').if_present do |fs_path|
25
29
  "#{ssh_url}#{fs_path}"
26
30
  end
27
31
  end
28
32
  end
33
+
34
+ def auto_fs_url_without_ssh
35
+ return nil if read_entry_optional('ssh.url').present?
36
+
37
+ read_entry_optional('fs_path').if_present do |fs_path|
38
+ "file://#{fs_path}"
39
+ end
40
+ end
29
41
  end
30
42
  end
31
43
  end
@@ -1,11 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'eac_cli/core_ext'
4
- require 'eac_ruby_utils/console/docopt_runner'
5
4
 
6
5
  module Avm
7
6
  module Instances
8
- class Runner < ::EacRubyUtils::Console::DocoptRunner
7
+ class Runner
9
8
  class << self
10
9
  def instance_class
11
10
  ::Avm.const_get(stereotype_name).const_get('Instance')
@@ -20,9 +19,8 @@ module Avm
20
19
  end
21
20
  end
22
21
 
23
- runner_with
24
22
  description = "Utilities for #{stereotype_name} instances."
25
- runner_definition do
23
+ runner_with :help, :subcommands do
26
24
  desc description
27
25
  pos_arg 'instance-id'
28
26
  subcommands
@@ -33,7 +31,7 @@ module Avm
33
31
  private
34
32
 
35
33
  def instance_uncached
36
- self.class.instance_class.by_id(options.fetch('<instance-id>'))
34
+ self.class.instance_class.by_id(parsed.instance_id)
37
35
  end
38
36
  end
39
37
  end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'avm/patches/class/i18n'
5
+
6
+ module Avm
7
+ module Projects
8
+ module Stereotypes
9
+ class Git
10
+ class Update
11
+ require_sub __FILE__
12
+ enable_simple_cache
13
+ enable_console_speaker
14
+ common_constructor :instance
15
+
16
+ delegate :git_repo, to: :instance
17
+
18
+ def run
19
+ clean_all
20
+ selected_subrepos.map do |f|
21
+ infov 'Subrepo', f
22
+ on_speaker_node do |node|
23
+ node.stderr_line_prefix = ' '
24
+ ::Avm::Projects::Stereotypes::Git::Update::Subrepo.new(self, f).run
25
+ end
26
+ end
27
+ end
28
+
29
+ def selected_subrepos_uncached
30
+ git_repo.command('subrepo', '-q', 'status').execute!.split("\n").map(&:strip)
31
+ .select(&:present?).map(&:to_pathname)
32
+ end
33
+
34
+ def clean_all
35
+ infom 'Cleaning'
36
+ git_repo.command('subrepo', 'clean', '--all').execute!
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,85 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_launcher/git/base'
4
+ require 'avm/git/commit'
5
+
6
+ module Avm
7
+ module Projects
8
+ module Stereotypes
9
+ class Git
10
+ class Update
11
+ class Subrepo
12
+ TRANSLATE_CLASS = self
13
+
14
+ require_sub __FILE__, include_modules: true
15
+ enable_simple_cache
16
+ enable_console_speaker
17
+ common_constructor :parent_update, :subpath do
18
+ self.subpath = subpath.to_pathname
19
+ end
20
+
21
+ delegate :git_repo, :instance, to: :parent_update
22
+
23
+ def run
24
+ run_banner
25
+ if base_commit.sha1 == pull_commit.sha1
26
+ infom 'No new commit (No changes)'
27
+ elsif fix_message.present?
28
+ on_fix_message_present
29
+ else
30
+ warn 'No fix message found'
31
+ end
32
+ end
33
+
34
+ private
35
+
36
+ def base_commit_uncached
37
+ ::Avm::Git::Commit.new(git_repo, git_repo.rev_parse('HEAD'))
38
+ end
39
+
40
+ def on_fix_message_present
41
+ infom 'Fixing message...'
42
+ infov 'Message', fix_message
43
+ git_repo.command('commit', '--amend', '-m', fix_message).execute!
44
+ end
45
+
46
+ def pull_commit_uncached
47
+ base_commit
48
+ infom 'Pulling subrepo...'
49
+ git_repo.command('subrepo', 'pull', '--force', subpath).execute!
50
+ ::Avm::Git::Commit.new(
51
+ ::EacLauncher::Git::Base.new(git_repo.root_path.to_path),
52
+ git_repo.rev_parse('HEAD')
53
+ )
54
+ end
55
+
56
+ def run_banner
57
+ infov 'Base SHA1', base_commit.sha1
58
+ infov 'Pull SHA1', pull_commit.sha1
59
+ end
60
+
61
+ def fix_message
62
+ TRANSLATE_CLASS.translate(
63
+ fix_message_translate_key, subpath: subpath, name: subpath.basename,
64
+ __locale: instance.locale
65
+ )
66
+ end
67
+
68
+ def fix_message_translate_key
69
+ if gitrepo_only_changed?
70
+ :gitrepo_only_changed_fix_message
71
+ else
72
+ :content_updated_fix_message
73
+ end
74
+ end
75
+
76
+ def gitrepo_only_changed?
77
+ pull_commit.files.count == 1 &&
78
+ ::File.basename(pull_commit.files.first.path) == '.gitrepo'
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end