Module: DTK::Client::ListDiffsMixin

Included in:
AssemblyWorkspaceMixin, ModuleMixin
Defined in:
lib/commands/common/thor/list_diffs.rb

Instance Method Summary collapse

Instance Method Details

#list_component_module_diffs(module_id, assembly_name, workspace_branch, commit_sha, module_branch_id, repo_id) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/commands/common/thor/list_diffs.rb', line 85

def list_component_module_diffs(module_id, assembly_name, workspace_branch, commit_sha, module_branch_id, repo_id)
  post_body = {
    :module_id => module_id,
    :assembly_name => assembly_name,
    :workspace_branch => workspace_branch,
    :module_branch_id => module_branch_id,
    :repo_id => repo_id
  }

  response = post(rest_url("assembly/list_component_module_diffs"),post_body)
  return response unless response.ok?

  raise DTK::Client::DtkValidationError, "There are no diffs between module in service instance and base module!" if response.data.empty?
  response
end

#list_diffs_aux(module_type, module_id, remote, version = nil) ⇒ 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/commands/common/thor/list_diffs.rb', line 20

def list_diffs_aux(module_type,module_id,remote,version=nil)
	id_field    = "#{module_type}_id"
   path_to_key = SSHUtil.default_rsa_pub_key_path()
   rsa_pub_key = File.file?(path_to_key) && File.open(path_to_key){|f|f.read}.chomp

   post_body = {
     id_field => module_id,
     :access_rights => "r",
     :action => "pull"
   }
   post_body.merge!(:version => version) if version
   post_body.merge!(:rsa_pub_key => rsa_pub_key) if rsa_pub_key

   response = post(rest_url("#{module_type}/get_remote_module_info"),post_body)
   return response unless response.ok?

   module_name = response.data(:full_module_name)

   opts = {
     :remote_repo_url => response.data(:remote_repo_url),
     :remote_repo => response.data(:remote_repo),
     :remote_branch => response.data(:remote_branch),
     :local_branch => response.data(:workspace_branch)
   }
   version = response.data(:version)

   # response = Helper(:git_repo).get_diffs(module_type,module_name,version,opts)
   response = Helper(:git_repo).get_remote_diffs(module_type,module_name,version,opts)
   return response unless response.ok?

   added, deleted, modified = print_diffs(response.data(:status), remote)
   diffs = response.data(:diffs)

   raise DTK::Client::DtkValidationError, "There are no changes in current workspace!" if(added.empty? && deleted.empty? && modified.empty? && diffs.empty?)
   puts "#{diffs}" unless (diffs||"").empty?

   unless added.empty?
     puts "\nNew file(s):"
     added.each do |a|
       puts "\t #{a.inspect}"
     end
   end

   unless deleted.empty?
     puts "\nDeleted file(s):"
     deleted.each do |d|
       puts "\t #{d.inspect}"
     end
   end
end

#list_remote_diffs_aux(module_type, module_id) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/commands/common/thor/list_diffs.rb', line 71

def list_remote_diffs_aux(module_type, module_id)
  id_field = "#{module_type}_id"

  post_body = {
    id_field => module_id
  }

  response = post(rest_url("#{module_type}/list_remote_diffs"),post_body)
  return response unless response.ok?

  raise DTK::Client::DtkValidationError, "There are no diffs between module on server and remote repo!" if response.data.empty?
  response
end


101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/commands/common/thor/list_diffs.rb', line 101

def print_diffs(response, remote)
  added    = []
  deleted  = []
  modified = []

  unless response[:files_modified].nil?
    response[:files_modified].each do |file|
      modified << file[:path]
    end
  end

  unless response[:files_deleted].nil?
    response[:files_deleted].each do |file|
      deleted << file[:path]
    end
  end

  unless response[:files_added].nil?
    response[:files_added].each do |file|
      added << file[:path]
    end
  end

  return added, deleted, modified
end