Class: LgPodPlugin::LRequest

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/lg_pod_plugin/request.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.sharedObject



148
149
150
# File 'lib/lg_pod_plugin/request.rb', line 148

def self.shared
  return LRequest.instance
end

Instance Method Details

#get_cache_key_paramsObject

获取缓存用的hash_map



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
# File 'lib/lg_pod_plugin/request.rb', line 44

def get_cache_key_params
  hash_map = Hash.new
  git = self.checkout_options[:git] ||= self.request_params[:git]
  tag = self.checkout_options[:tag] ||= self.request_params[:tag]
  branch = self.checkout_options[:branch] ||= self.request_params[:branch]
  commit = self.checkout_options[:commit] ||= self.request_params[:commit]
  return hash_map unless git
  hash_map[:git] = git
  if git && commit
    hash_map[:commit] = commit
  elsif git && tag
    hash_map[:tag] = tag
  elsif git && branch
    if commit
      hash_map[:commit] = commit
    else
      _, new_commit_id = LGitUtil.git_ls_remote_refs(git, branch, nil, commit)
      hash_map[:commit] = new_commit_id if new_commit_id
    end
  else
    _, new_commit_id = LGitUtil.git_ls_remote_refs(git, branch, nil, commit)
    hash_map[:commit] = new_commit_id if new_commit_id
  end
  hash_map
end

#get_lock_infoObject



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/lg_pod_plugin/request.rb', line 31

def get_lock_info
  lock_file = self.workspace.join("Podfile.lock")
  if lock_file.exist?
    json = YAML.load_file(lock_file.to_path)
    external_source = json["EXTERNAL SOURCES"]
    checkout_options = json["CHECKOUT OPTIONS"]
    { "external_source" => external_source, "checkout_options" => checkout_options }
  else
    nil
  end
end

#is_update_podObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/lg_pod_plugin/request.rb', line 15

def is_update_pod
  cgi = CGI.new
  command_keys = cgi.keys
  unless command_keys.count > 0
    return false
  end
  first_key = command_keys[0].to_s ||= ""
  if first_key.include?("install")
    false
  elsif first_key.include?("update")
    true
  else
    false
  end
end

#request_gitlab_token(git) ⇒ Object



152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/lg_pod_plugin/request.rb', line 152

def request_gitlab_token(git)
  if git == nil
    return nil
  end
  begin
    #81.69.242.162
    uri = URI('http://81.69.242.162:8080/v1/member/user/gitlab/token')
    # uri = URI('http://127.0.0.1:8080/v1/member/user/gitlab/token')
    params = { "url" => git }
    res = Net::HTTP.post_form(uri, params)
    json = JSON.parse(res.body)
  rescue
    return nil
  end
  unless json
    return nil
  end
  json["data"]["token"]
end

#setup_pod_info(name, workspace, options = {}) ⇒ Object



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/lg_pod_plugin/request.rb', line 126

def setup_pod_info(name, workspace, options = {})
  self.name = name
  tag = options[:tag]
  git = options[:git]
  commit = options[:commit]
  branch = options[:branch]
  self.workspace = workspace
  if (git && branch) || (git && commit) || (git && tag)
    self.single_git = false
  else
    self.single_git = true
  end
  self.checkout_options = Hash.new.deep_merge(options)
  self.request_params = self.get_request_params
  if self.token == nil
    self.token = self.request_gitlab_token(git)
  end
  self.cache = LCache.new(self.workspace)
  self.git_util = LGitUtil.new(name, self.checkout_options)
  self.downloader = LDownloader.new(name, self.checkout_options)
end