Module: DTK::Client::PurgeCloneMixin

Included in:
ModuleMixin
Defined in:
lib/commands/common/thor/purge_clone.rb

Instance Method Summary collapse

Instance Method Details

#check_if_unsaved_assembly_changes(assembly_or_workspace_id, assembly_name, opts = {}) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/commands/common/thor/purge_clone.rb', line 63

def check_if_unsaved_assembly_changes(assembly_or_workspace_id, assembly_name, opts={})
  post_body = {
    :assembly_id => assembly_or_workspace_id,
    :module_type => 'service_module',
    :modification_type => 'workflow'
  }
  response = post rest_url("assembly/prepare_for_edit_module"), post_body
  return unless response.ok?
  assembly_name,service_module_id,service_module_name,version,repo_url,branch,branch_head_sha,edit_file = response.data(:assembly_name,:module_id,:full_module_name,:version,:repo_url,:workspace_branch,:branch_head_sha,:edit_file)

  edit_opts = {
    :automatically_clone => true,
    :assembly_module => {
      :assembly_name => assembly_name,
      :version => version
    },
    :workspace_branch_info => {
      :repo_url => repo_url,
      :branch => branch,
      :module_name => service_module_name
    },
    :commit_sha => branch_head_sha,
    :pull_if_needed => true,
    :modification_type => :workflow,
    :edit_file => edit_file
  }

  version = nil #TODO: version associated with assembly is passed in edit_opts, which is a little confusing
  module_location  = OsUtil.module_location(:service_module,service_module_name,version,edit_opts)
  return unless File.directory?(module_location)

  grit_adapter = Helper(:git_repo).create(module_location)
  return unless grit_adapter.repo_exists?

  grit_adapter.changed?
end

#check_if_unsaved_cmp_module_changes(assembly_or_workspace_id, opts = {}) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/commands/common/thor/purge_clone.rb', line 45

def check_if_unsaved_cmp_module_changes(assembly_or_workspace_id, opts={})
  unsaved_modules = []
  post_body = {
    :assembly_id => assembly_or_workspace_id,
    :subtype     => 'instance'
  }
  response = post rest_url("assembly/get_component_modules"), post_body

  if response.ok?
    response.data.each do |cmp_mod|
      branch_relationship = cmp_mod['branch_relationship']||''
      unsaved_modules << "#{cmp_mod['namespace_name']}:#{cmp_mod['display_name']}" if (cmp_mod['local_copy_diff'] && branch_relationship.eql?('local_ahead'))
    end
  end

  unsaved_modules
end

#purge_clone_aux(module_type, opts = {}) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/commands/common/thor/purge_clone.rb', line 20

def purge_clone_aux(module_type, opts = {})
  module_name = opts[:module_name]
  version = opts[:version]
  opts_module_loc = (opts[:assembly_module] ? {:assembly_module => opts[:assembly_module]} : Hash.new)
  module_location = OsUtil.module_location(module_type, module_name, version, opts_module_loc)
  dirs_to_delete = [module_location]
  if opts[:delete_all_versions]
    dirs_to_delete += OsUtil.module_version_locations(module_type, module_name, version, opts)
  elsif opts[:all_except_base]
    dirs_to_delete = OsUtil.module_version_locations(module_type, module_name, version, opts)
  end
  response = Response::Ok.new()
  pwd = Dir.getwd()
  dirs_to_delete.each do |dir|
    if File.directory?(dir)
      if ((pwd == dir) || (pwd.include?("#{dir}/")))
        OsUtil.print("Local directory '#{dir}' is not deleted because it is your current working directory.", :yellow)
      else
        FileUtils.rm_rf(dir)
      end
    end
  end
  response
end