class DTK::Client::Operation::Module::PushDtkn::ConvertSource
Attributes
info_processor[R]
parent[R]
target_repo_dir[R]
Public Class Methods
new(transform_helper, info_type, remote_repo_url, parent)
click to toggle source
# File lib/client/operation/module/push_dtkn/convert_source.rb, line 24 def initialize(transform_helper, info_type, remote_repo_url, parent) @info_processor = transform_helper.info_processor(info_type) @info_type = info_type @remote_repo_url = remote_repo_url @target_repo_dir = parent.target_repo_dir @version = parent.version end
transform_and_commit(remote_module_info, parent)
click to toggle source
# File lib/client/operation/module/push_dtkn/convert_source.rb, line 33 def self.transform_and_commit(remote_module_info, parent) target_repo_dir = parent.target_repo_dir parsed_common_module = parent.base_dsl_file_obj.parse_content(:common_module) current_branch = Operation::ClientModuleDir::GitRepo.current_branch(:path => target_repo_dir).data(:branch) if service_info = remote_module_info.data(:service_info) transform_service_info(target_repo_dir, parent, service_info, parsed_common_module, current_branch) end if component_info = remote_module_info.data(:component_info) transform_component_info(target_repo_dir, parent, component_info, parsed_common_module, current_branch) end end
transform_component_info(target_repo_dir, parent, component_info, parsed_common_module, current_branch)
click to toggle source
# File lib/client/operation/module/push_dtkn/convert_source.rb, line 67 def self.transform_component_info(target_repo_dir, parent, component_info, parsed_common_module, current_branch) transform_helper = ServiceAndComponentInfo::TransformTo.new(target_repo_dir, parent.module_ref, parent.version, parsed_common_module) component_file_path__content_array = ComponentInfo.transform_info(transform_helper, component_info['remote_repo_url'], parent) component_info_remote = "remotes/dtkn-component-info/master" create_and_checkout_branch?(current_branch, target_repo_dir, component_info_remote) do |repo| # find deleted files from master branch and delete them in component info cached branch ("remotes/dtkn-component-info/master") delete_diffs(repo, component_info_remote, current_branch, target_repo_dir) component_file_path__content_array.each { |file| Operation::ClientModuleDir.create_file_with_content("#{file_path(target_repo_dir, file)}", file[:content]) } commit_and_push_to_remote(repo, target_repo_dir, "master", "dtkn-component-info") end end
transform_info(transform_helper, remote_repo_url, parent)
click to toggle source
# File lib/client/operation/module/push_dtkn/convert_source.rb, line 47 def self.transform_info(transform_helper, remote_repo_url, parent) new(transform_helper, info_type, remote_repo_url, parent).transform_info end
transform_service_info(target_repo_dir, parent, service_info, parsed_common_module, current_branch)
click to toggle source
# File lib/client/operation/module/push_dtkn/convert_source.rb, line 51 def self.transform_service_info(target_repo_dir, parent, service_info, parsed_common_module, current_branch) transform_helper = ServiceAndComponentInfo::TransformTo.new(target_repo_dir, parent.module_ref, parent.version, parsed_common_module) service_file_path__content_array = ServiceInfo.transform_info(transform_helper, service_info['remote_repo_url'], parent) create_and_checkout_branch?(current_branch, target_repo_dir, "remotes/dtkn/master") do |repo| FileUtils.mkdir_p("#{target_repo_dir}/assemblies") unless File.exists?("#{target_repo_dir}/assemblies") args = [transform_helper, ServiceInfo.info_type, service_info['remote_repo_url'], parent] service_file_path__content_array.each { |file| Operation::ClientModuleDir.create_file_with_content("#{service_file_path(target_repo_dir, file, *args)}", file[:content]) } delete_assemblies?(service_file_path__content_array, target_repo_dir) commit_and_push_to_remote(repo, target_repo_dir, "master", "dtkn") end end
Private Class Methods
commit_and_push_to_remote(repo, target_repo_dir, branch, remote)
click to toggle source
# File lib/client/operation/module/push_dtkn/convert_source.rb, line 147 def self.commit_and_push_to_remote(repo, target_repo_dir, branch, remote) repo.stage_and_commit("Add auto-generated files from push-dtkn") repo.push_from_cached_branch(remote, branch, { :force => true }) end
commit_msg(info_types_processed)
click to toggle source
# File lib/client/operation/module/push_dtkn/convert_source.rb, line 161 def self.commit_msg(info_types_processed) msg = "Added " count = 0 types = info_types_processed #info if types.include?(ServiceInfo.info_type) msg << 'service ' count +=1 end if types.include?(ComponentInfo.info_type) msg << 'and ' if count > 0 msg << 'component' count +=1 end msg << 'info' msg end
convert_to_legacy_assebmly(target_repo_dir, file)
click to toggle source
# File lib/client/operation/module/push_dtkn/convert_source.rb, line 113 def self.convert_to_legacy_assebmly(target_repo_dir, file) return file[:path] if file[:full_path] file_path = file[:path] file_name = file_path.split('/').last assembly_name = file_name.split('.').first "#{target_repo_dir}/assemblies/#{assembly_name}/assembly.yaml" end
create_and_checkout_branch?(current_branch, target_repo_dir, branch_to_checkout, &body)
click to toggle source
# File lib/client/operation/module/push_dtkn/convert_source.rb, line 135 def self.create_and_checkout_branch?(current_branch, target_repo_dir, branch_to_checkout, &body) repo = git_repo_operation.create_empty_git_repo?(:repo_dir => target_repo_dir, :branch => branch_to_checkout).data(:repo) checkout_branch_args = { :repo => repo, :current_branch => current_branch, :branch_to_checkout => branch_to_checkout } git_repo_operation.checkout_branch(checkout_branch_args) { body.call(repo) } end
delete_assemblies?(service_file_path__content_array, target_repo_dir)
click to toggle source
# File lib/client/operation/module/push_dtkn/convert_source.rb, line 178 def self.delete_assemblies?(service_file_path__content_array, target_repo_dir) assembly_regex = Regexp.new("\.dtk\.assembly\.(yml|yaml)$") assemblies = Dir.entries("#{target_repo_dir}/assemblies/").select { |file| file.match(assembly_regex) } current_assemblies = assemblies.map { |assembly| "assemblies/#{assembly}" } to_delete = current_assemblies - service_file_path__content_array.map { |file| file[:path] } to_delete.each { |file| Operation::ClientModuleDir.rm_f("#{target_repo_dir}/#{file}") } end
delete_diffs(repo, component_info_remote, current_branch, target_repo_dir)
click to toggle source
# File lib/client/operation/module/push_dtkn/convert_source.rb, line 85 def self.delete_diffs(repo, component_info_remote, current_branch, target_repo_dir) if diffs = repo.diff_name_status(component_info_remote, current_branch) deletes_and_renames = diffs.select{ |k,v| v.eql?('D') || v.start_with?('R') } unless deletes_and_renames.empty? to_delete = deletes_and_renames.keys.select { |key| !key.include?('dtk.model.yaml') && !key.include?('module_refs.yaml') } to_delete.each { |file| Operation::ClientModuleDir.rm_f("#{target_repo_dir}/#{file}") } end end end
file_path(target_repo_dir, file)
click to toggle source
# File lib/client/operation/module/push_dtkn/convert_source.rb, line 98 def self.file_path(target_repo_dir, file) file[:full_path] ? file[:path] : "#{target_repo_dir}/#{file[:path]}" end
git_repo_operation()
click to toggle source
# File lib/client/operation/module/push_dtkn/convert_source.rb, line 186 def self.git_repo_operation Operation::ClientModuleDir::GitRepo end
service_file_path(target_repo_dir, file, *args)
click to toggle source
# File lib/client/operation/module/push_dtkn/convert_source.rb, line 102 def self.service_file_path(target_repo_dir, file, *args) @new_service_info ||= ServiceInfo.new(*args) @legacy_assemblies ||= @new_service_info.legacy_assemblies? if @legacy_assemblies && !file[:path].include?('module_refs.yaml') convert_to_legacy_assebmly(target_repo_dir, file) else file_path(target_repo_dir, file) end end
stage_and_commit(target_repo_dir, commit_msg = nil)
click to toggle source
# File lib/client/operation/module/push_dtkn/convert_source.rb, line 152 def self.stage_and_commit(target_repo_dir, commit_msg = nil) git_repo_args = { :repo_dir => target_repo_dir, :commit_msg => commit_msg, :local_branch_type => :dtkn } git_repo_operation.stage_and_commit(git_repo_args) end
write_output_path_text_pairs(transform_helper, target_repo_dir, info_types_processed)
click to toggle source
# File lib/client/operation/module/push_dtkn/convert_source.rb, line 95 def self.write_output_path_text_pairs(transform_helper, target_repo_dir, info_types_processed) end
Private Instance Methods
common_git_repo_args()
click to toggle source
# File lib/client/operation/module/push_dtkn/convert_source.rb, line 128 def common_git_repo_args { :info_type => @info_type, :repo_dir => @target_repo_dir } end
fetch_remote()
click to toggle source
# File lib/client/operation/module/push_dtkn/convert_source.rb, line 123 def fetch_remote git_repo_args = common_git_repo_args.merge(:add_remote => @remote_repo_url) git_repo_operation.fetch_dtkn_remote(git_repo_args) end
git_repo_operation()
click to toggle source
# File lib/client/operation/module/push_dtkn/convert_source.rb, line 189 def git_repo_operation self.class.git_repo_operation end