class DTK::Client::Operation::Service::CommitAndPush
Constants
- GITIGNORE_REL_PATH
- PRINT_FN
Public Class Methods
execute(args = Args.new)
click to toggle source
Commits and pushes from service instance directory
# File lib/client/operation/service/commit_and_push.rb, line 22 def self.execute(args = Args.new) wrap_operation(args) do |args| service_instance = args.required(:service_instance) response = rest_get("#{BaseRoute}/#{service_instance}/repo_info") nested_module_args = Args.new( :service_instance => service_instance, :base_module => nil, :nested_modules => nil, :service_instance_dir => args[:service_instance_dir] ) nested_modules_response = ClientModuleDir::ServiceInstance.commit_and_push_nested_modules(nested_module_args) updated_nested_modules = nested_modules_response.data(:nested_modules) unless updated_nested_modules.empty? repo_dir = (args[:service_instance_dir] || ClientModuleDir.ret_base_path(:service, service_instance)) empty_commit_args = Args.new( :repo_dir => repo_dir, :commit_msg => "Nested modules changed" ) ClientModuleDir::GitRepo.create_repo_with_empty_commit(empty_commit_args) # this is used to pick up changes made in nested modules Dir.glob("#{repo_dir}/.nested_modules_changed_*").each { |file| File.delete(file)} Operation::ClientModuleDir.create_file_with_content("#{repo_dir}/.nested_modules_changed_#{Time.now.to_i}", Time.now.to_i) end repo_info_args = Args.new( :service_instance => service_instance, :commit_message => args[:commit_message] || default_commit_message(service_instance), :branch => response.required(:branch, :name), :repo_url => response.required(:repo, :url), :service_instance_dir => args[:service_instance_dir] ) response = ClientModuleDir::GitRepo.commit_and_push_to_service_repo(repo_info_args) commit_sha = response.required(:head_sha) response = rest_post("#{BaseRoute}/#{service_instance}/update_from_repo", { :commit_sha => commit_sha, :updated_nested_modules => updated_nested_modules }) print_msgs_of_type(:error_msgs, response) print_msgs_of_type(:warning_msgs, response) print_msgs_of_type(:info_msgs, response) ClientModuleDir::GitRepo.pull_from_service_repo(repo_info_args) if response.data(:repo_updated) if nested_module_args[:nested_modules_to_delete] = response.data['module_refs_to_delete'] ClientModuleDir::ServiceInstance.remove_nested_module_dirs(nested_module_args) end process_backup_files(repo_info_args, response.data(:backup_files)) process_semantic_diffs(response.data(:semantic_diffs)) nil end end
Private Class Methods
default_commit_message(service_instance)
click to toggle source
# File lib/client/operation/service/commit_and_push.rb, line 77 def self.default_commit_message(service_instance) "Updating changes to service instance '#{service_instance}'" end
head_commit_sha(service_instance)
click to toggle source
# File lib/client/operation/service/commit_and_push.rb, line 81 def self.head_commit_sha(service_instance) raise Error, "Need to write" end
print_msgs_of_type(msg_type, response)
click to toggle source
# File lib/client/operation/service/commit_and_push.rb, line 128 def self.print_msgs_of_type(msg_type, response) msgs = response.data(msg_type) || [] unless msgs.empty? print_fn = PRINT_FN[msg_type] msgs.each { |msg| print_fn.call(msg) } end end
process_backup_files(repo_info_args, backup_files)
click to toggle source
# File lib/client/operation/service/commit_and_push.rb, line 86 def self.process_backup_files(repo_info_args, backup_files) return if (backup_files || {}).empty? backup_files.each_pair do |path, content| ClientModuleDir::GitRepo.add_service_repo_file(repo_info_args.merge(:path => path, :content => content)) end backup_file_paths = backup_files.keys update_gitignore?(repo_info_args, backup_file_paths) ClientModuleDir::GitRepo.commit_and_push_to_service_repo(repo_info_args) end
process_semantic_diffs(semantic_diffs)
click to toggle source
# File lib/client/operation/service/commit_and_push.rb, line 114 def self.process_semantic_diffs(semantic_diffs) return if (semantic_diffs || {}).empty? # TODO: DTK-2663; cleanup so pretty printed' OsUtil.print_info("\nDiffs that were pushed:") # TODO: get rid of use of STDOUT #STDOUT << hash_to_yaml(semantic_diffs).gsub("---\n", "") OsUtil.print(hash_to_yaml(semantic_diffs).gsub("---\n", "")) end
update_gitignore?(repo_info_args, backup_file_paths)
click to toggle source
# File lib/client/operation/service/commit_and_push.rb, line 99 def self.update_gitignore?(repo_info_args, backup_file_paths) response = ClientModuleDir::GitRepo.get_service_repo_file_content(repo_info_args.merge(:path => GITIGNORE_REL_PATH)) gitignore_content = response.data(:content) || '' gitignore_files = gitignore_content.split("\n") to_add = '' backup_file_paths.each do |backup_file_path| to_add << "#{backup_file_path}\n" unless gitignore_files.include?(backup_file_path) end unless to_add.empty? gitignore_content << "\n" unless gitignore_content.empty? or gitignore_content[-1] == "\n" gitignore_content << to_add ClientModuleDir::GitRepo.add_service_repo_file(repo_info_args.merge(:path => GITIGNORE_REL_PATH, :content => gitignore_content)) end end