lg_pod_plugin 1.1.7.3 → 1.1.8.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
- require 'cocoapods'
4
1
  require 'fileutils'
5
2
  require 'tmpdir'
6
3
 
@@ -10,155 +7,9 @@ module Pod
10
7
  # them in a cache directory.
11
8
  #
12
9
  class Cache
13
- # @return [Pathname] The root directory where this cache store its
14
- # downloads.
15
- #
16
- attr_reader :root
17
-
18
- # Initialize a new instance
19
- #
20
- # @param [Pathname,String] root
21
- # see {#root}
22
- #
23
- def initialize(root)
24
- @root = Pathname(root)
25
- ensure_matching_version
26
- end
27
-
28
- # Downloads the Pod from the given `request`
29
- #
30
- # @param [Request] request
31
- # the request to be downloaded.
32
- #
33
- # @return [Response] the response from downloading `request`
34
- #
35
- def download_pod(request)
36
- cached_pod(request) || uncached_pod(request)
37
- rescue Informative
38
- raise
39
- rescue
40
- UI.puts("\n[!] Error installing #{request.name}".red)
41
- raise
42
- end
43
-
44
- # @return [Hash<String, Hash<Symbol, String>>]
45
- # A hash whose keys are the pod name
46
- # And values are a hash with the following keys:
47
- # :spec_file : path to the spec file
48
- # :name : name of the pod
49
- # :version : pod version
50
- # :release : boolean to tell if that's a release pod
51
- # :slug : the slug path where the pod cache is located
52
- #
53
- def cache_descriptors_per_pod
54
- specs_dir = root + 'Specs'
55
- release_specs_dir = specs_dir + 'Release'
56
- return {} unless specs_dir.exist?
57
-
58
- spec_paths = specs_dir.find.select { |f| f.fnmatch('*.podspec.json') }
59
- spec_paths.reduce({}) do |hash, spec_path|
60
- spec = Specification.from_file(spec_path)
61
- hash[spec.name] ||= []
62
- is_release = spec_path.to_s.start_with?(release_specs_dir.to_s)
63
- request = Downloader::Request.new(:spec => spec, :released => is_release)
64
- hash[spec.name] << {
65
- :spec_file => spec_path,
66
- :name => spec.name,
67
- :version => spec.version,
68
- :release => is_release,
69
- :slug => root + request.slug,
70
- }
71
- hash
72
- end
73
- end
74
10
 
75
- # Convenience method for acquiring a shared lock to safely read from the
76
- # cache. See `Cache.lock` for more details.
77
- #
78
- # @param [Pathname] location
79
- # the path to require a lock for.
80
- #
81
- # @param [block] &block
82
- # the block to execute inside the lock.
83
- #
84
- # @return [void]
85
- #
86
- def self.read_lock(location, &block)
87
- Cache.lock(location, File::LOCK_SH, &block)
88
- end
89
-
90
- # Convenience method for acquiring an exclusive lock to safely write to
91
- # the cache. See `Cache.lock` for more details.
92
- #
93
- # @param [Pathname] location
94
- # the path to require a lock for.
95
- #
96
- # @param [block] &block
97
- # the block to execute inside the lock.
98
- #
99
- # @return [void]
100
- #
101
- def self.write_lock(location, &block)
102
- Cache.lock(location, File::LOCK_EX, &block)
103
- end
104
-
105
- # Creates a .lock file at `location`, aquires a lock of type
106
- # `lock_type`, checks that it is valid, and executes passed block while
107
- # holding on to that lock. Afterwards, the .lock file is deleted, which is
108
- # why validation of the lock is necessary, as you might have a lock on a
109
- # file that doesn't exist on the filesystem anymore.
110
- #
111
- # @param [Pathname] location
112
- # the path to require a lock for.
113
- #
114
- # @param [locking_constant] lock_type
115
- # the type of lock, either exclusive (File::LOCK_EX) or shared
116
- # (File::LOCK_SH).
117
- #
118
- # @return [void]
119
- #
120
- def self.lock(location, lock_type)
121
- raise ArgumentError, 'no block given' unless block_given?
122
- lockfile = "#{location}.lock"
123
- f = nil
124
- loop do
125
- f.close if f
126
- f = File.open(lockfile, File::CREAT, 0o644)
127
- f.flock(lock_type)
128
- break if Cache.valid_lock?(f, lockfile)
129
- end
130
- begin
131
- yield location
132
- ensure
133
- if lock_type == File::LOCK_SH
134
- f.flock(File::LOCK_EX)
135
- File.delete(lockfile) if Cache.valid_lock?(f, lockfile)
136
- else
137
- File.delete(lockfile)
138
- end
139
- f.close
140
- end
141
- end
142
-
143
- # Checks that the lock is on a file that still exists on the filesystem.
144
- #
145
- # @param [File] file
146
- # the actual file that we have a lock for.
147
- #
148
- # @param [String] filename
149
- # the filename of the file that we have a lock for.
150
- #
151
- # @return [Boolean]
152
- # true if `filename` still exists and is the same file as `file`
153
- #
154
- def self.valid_lock?(file, filename)
155
- file.stat.ino == File.stat(filename).ino
156
- rescue Errno::ENOENT
157
- false
158
- end
159
11
 
160
12
  private
161
-
162
13
  # Ensures the cache on disk was created with the same CocoaPods version as
163
14
  # is currently running.
164
15
  #
@@ -178,152 +29,31 @@ module Pod
178
29
  end
179
30
  end
180
31
 
181
- # @param [Request] request
182
- # the request to be downloaded.
183
- #
184
- # @param [Hash<Symbol,String>] slug_opts
185
- # the download options that should be used in constructing the
186
- # cache slug for this request.
187
- #
188
- # @return [Pathname] The path for the Pod downloaded from the given
189
- # `request`.
190
- #
191
- def path_for_pod(request, slug_opts = {})
192
- root + request.slug(**slug_opts)
193
- end
194
-
195
- # @param [Request] request
196
- # the request to be downloaded.
197
- #
198
- # @param [Hash<Symbol,String>] slug_opts
199
- # the download options that should be used in constructing the
200
- # cache slug for this request.
201
- #
202
- # @return [Pathname] The path for the podspec downloaded from the given
203
- # `request`.
204
- #
205
- def path_for_spec(request, slug_opts = {})
206
- path = root + 'Specs' + request.slug(**slug_opts)
207
- Pathname.new(path.to_path + '.podspec.json')
208
- end
209
-
210
- # @param [Request] request
211
- # the request to be downloaded.
212
- #
213
- # @return [Response] The download response for the given `request` that
214
- # was found in the download cache.
215
- #
216
- def cached_pod(request)
217
- cached_spec = cached_spec(request)
218
- path = path_for_pod(request)
219
-
220
- return unless cached_spec && path.directory?
221
- spec = request.spec || cached_spec
222
- Response.new(path, spec, request.params)
223
- end
224
-
225
- # @param [Request] request
226
- # the request to be downloaded.
227
- #
228
- # @return [Specification] The cached specification for the given
229
- # `request`.
230
- #
231
- def cached_spec(request)
232
- path = path_for_spec(request)
233
- path.file? && Specification.from_file(path)
234
- rescue JSON::ParserError
235
- nil
236
- end
237
-
238
- # @param [Request] request
239
- # the request to be downloaded.
240
- #
241
- # @return [Response] The download response for the given `request` that
242
- # was not found in the download cache.
243
- #
244
- def uncached_pod(request)
245
- in_tmpdir do |target|
246
- result, podspecs = download(request, target)
247
- result.location = nil
248
-
249
- podspecs.each do |name, spec|
250
- destination = path_for_pod(request, :name => name, :params => result.checkout_options)
251
- copy_and_clean(target, destination, spec)
252
- write_spec(spec, path_for_spec(request, :name => name, :params => result.checkout_options))
253
- if request.name == name
254
- result.location = destination
255
- end
256
- end
257
-
258
- result
259
- end
260
- end
261
-
262
- def download(request, target)
263
- Downloader.download_request(request, target)
264
- end
265
-
266
- # Performs the given block inside a temporary directory,
267
- # which is removed at the end of the block's scope.
268
- #
269
- # @return [Object] The return value of the given block
270
- #
271
- def in_tmpdir(&blk)
272
- tmpdir = Pathname(Dir.mktmpdir)
273
- blk.call(tmpdir)
274
- ensure
275
- FileUtils.remove_entry(tmpdir, :force => true) if tmpdir && tmpdir.exist?
276
- end
277
-
278
- # Copies the `source` directory to `destination`, cleaning the directory
279
- # of any files unused by `spec`.
280
- #
281
- # @param [Pathname] source
282
- #
283
- # @param [Pathname] destination
284
- #
285
- # @param [Specification] spec
286
- #
287
- # @return [Void]
288
- #
32
+ public
289
33
  def copy_and_clean(source, destination, spec)
34
+ attributes_hash = spec.send(:attributes_hash) || {}
35
+ name = attributes_hash["name"] ||= ""
290
36
  specs_by_platform = group_subspecs_by_platform(spec)
291
37
  destination.parent.mkpath
292
- Cache.write_lock(destination) do
293
- FileUtils.rm_rf(destination)
294
- FileUtils.cp_r(source, destination)
295
- Pod::Installer::PodSourcePreparer.new(spec, destination).prepare!
296
- Sandbox::PodDirCleaner.new(destination, specs_by_platform).clean!
297
- end
298
- end
299
-
300
- def group_subspecs_by_platform(spec)
301
- specs_by_platform = {}
302
- [spec, *spec.recursive_subspecs].each do |ss|
303
- ss.available_platforms.each do |platform|
304
- specs_by_platform[platform] ||= []
305
- specs_by_platform[platform] << ss
38
+ Pod::Downloader::Cache.write_lock(destination) do
39
+ if source && source.exist? && !source.children.empty?
40
+ FileUtils.rm_rf(destination)
41
+ FileUtils.cp_r(source, destination)
306
42
  end
43
+ LgPodPlugin.log_green "-> Copy #{name} from #{source} to #{destination}"
44
+ Pod::Installer::PodSourcePreparer.new(spec, destination).prepare!
45
+ Pod::Sandbox::PodDirCleaner.new(destination, specs_by_platform).clean!
307
46
  end
308
- specs_by_platform
309
47
  end
310
48
 
311
- # Writes the given `spec` to the given `path`.
312
- #
313
- # @param [Specification] spec
314
- # the specification to be written.
315
- #
316
- # @param [Pathname] path
317
- # the path the specification is to be written to.
318
- #
319
- # @return [Void]
320
- #
49
+ public
321
50
  def write_spec(spec, path)
322
51
  path.dirname.mkpath
323
- Cache.write_lock(path) do
52
+ Pod::Downloader::Cache.write_lock(path) do
324
53
  path.open('w') { |f| f.write spec.to_pretty_json }
325
54
  end
326
55
  end
56
+
327
57
  end
328
58
  end
329
- end
59
+ end
@@ -6,7 +6,7 @@ module LgPodPlugin
6
6
  class LRequest
7
7
  attr_reader :target
8
8
  attr_reader :name
9
- attr_accessor :lg_spec
9
+ attr_accessor :podspec
10
10
  attr_reader :released_pod
11
11
  attr_accessor :single_git
12
12
  attr_accessor :config
@@ -16,12 +16,10 @@ module LgPodPlugin
16
16
  attr_accessor :checkout_options
17
17
  def initialize(pod)
18
18
  @name = pod.name
19
+ @podspec = pod.spec
19
20
  @target = pod.target
20
21
  @released_pod = pod.released_pod
21
22
  @checkout_options = pod.checkout_options
22
- if pod.spec
23
- @lg_spec = pod.spec
24
- end
25
23
  self.preprocess_request
26
24
  end
27
25
 
@@ -5,7 +5,7 @@ module LgPodPlugin
5
5
 
6
6
  class GithubAPI
7
7
 
8
- #获取 gitlab最新 commit_id
8
+ # 获取 gitlab最新 commit_id
9
9
  def self.request_github_refs_heads(git, branch)
10
10
  base_url = LUtils.get_gitlab_base_url git
11
11
  if base_url.include?("https://github.com/")
@@ -55,6 +55,7 @@ module LgPodPlugin
55
55
  end
56
56
 
57
57
  public
58
+
58
59
  def self.get_gitlab_repository_tree(git, sha)
59
60
  base_url = LUtils.get_gitlab_base_url git
60
61
  if base_url.include?("https://github.com/")
@@ -85,54 +86,6 @@ module LgPodPlugin
85
86
  end
86
87
  end
87
88
 
88
- public
89
-
90
- def self.get_podspec_file_content(git, sha, filename)
91
- base_url = LUtils.get_gitlab_base_url git
92
- if base_url.include?("https://github.com/")
93
- repo_name = base_url.split("https://github.com/", 0).last
94
- elsif base_url.include?("git@github.com:")
95
- repo_name = base_url.split("git@github.com:", 0).last
96
- else
97
- repo_name = nil
98
- end
99
- return nil unless repo_name
100
- trees = self.get_gitlab_repository_tree git, sha
101
- return nil if trees.empty?
102
- request_url = nil
103
- trees.each do |dict|
104
- type = dict["type"]
105
- next if type == "tree"
106
- path = dict["path"]
107
- next unless path.include?(".podspec")
108
- if path == filename
109
- request_url = dict["url"]
110
- break
111
- end
112
- end
113
- begin
114
- uri = URI(request_url)
115
- res = Net::HTTP.get_response(uri)
116
- if res.body
117
- json = JSON.parse(res.body)
118
- else
119
- json = nil
120
- end
121
- return nil unless json && json.is_a?(Hash)
122
- content = json["content"]
123
- return nil unless content && LUtils.is_a_string?(content)
124
- encoding = json["encoding"] ||= "base64"
125
- if encoding == "base64"
126
- content = LUtils.base64_decode(content)
127
- return content
128
- else
129
- return nil
130
- end
131
- rescue
132
- return nil
133
- end
134
- end
135
-
136
89
  end
137
90
 
138
91
  end
@@ -1,15 +1,17 @@
1
1
  require 'uri'
2
2
  require_relative 'git_download'
3
3
  require_relative '../utils/l_util'
4
- require_relative '../config/podspec'
5
4
 
6
5
  module LgPodPlugin
7
6
 
8
7
  class GitHubArchive
9
8
  private
9
+
10
10
  attr_reader :checkout_options
11
+
11
12
  public
12
- REQUIRED_ATTRS ||= %i[git tag name commit branch config path spec].freeze
13
+
14
+ REQUIRED_ATTRS ||= %i[git tag name commit branch config path].freeze
13
15
  attr_accessor(*REQUIRED_ATTRS)
14
16
 
15
17
  def initialize(checkout_options = {})
@@ -17,7 +19,6 @@ module LgPodPlugin
17
19
  self.tag = checkout_options[:tag]
18
20
  self.name = checkout_options[:name]
19
21
  self.path = checkout_options[:path]
20
- self.spec = checkout_options[:spec]
21
22
  self.config = checkout_options[:config]
22
23
  self.commit = checkout_options[:commit]
23
24
  self.branch = checkout_options[:branch]
@@ -41,15 +42,7 @@ module LgPodPlugin
41
42
  download_params["name"] = self.name
42
43
  download_params["type"] = "github-tag"
43
44
  download_params["path"] = root_path.to_path
44
- download_params["download_urls"] = download_urls
45
- if self.spec
46
- download_params["podspec"] = self.spec
47
- download_params["source_files"] = self.spec.source_files.keys
48
- download_params["podspec_content"] = nil
49
- else
50
- download_params["podspec"] = nil
51
- download_params["source_files"] = ["All"]
52
- end
45
+ download_params = download_params.merge(download_urls)
53
46
  download_params
54
47
  end
55
48
 
@@ -60,14 +53,7 @@ module LgPodPlugin
60
53
  download_params["name"] = self.name
61
54
  download_params["type"] = "github-branch"
62
55
  download_params["path"] = root_path.to_path
63
- download_params["download_urls"] = download_urls
64
- if self.spec
65
- download_params["podspec"] = self.spec
66
- download_params["source_files"] = self.spec.source_files.keys
67
- else
68
- download_params["podspec"] = nil
69
- download_params["source_files"] = ["All"]
70
- end
56
+ download_params = download_params.merge(download_urls)
71
57
  download_params
72
58
  end
73
59
 
@@ -78,14 +64,7 @@ module LgPodPlugin
78
64
  download_params["name"] = self.name
79
65
  download_params["type"] = "github-commit"
80
66
  download_params["path"] = root_path.to_path
81
- download_params["download_urls"] = download_urls
82
- if self.spec
83
- download_params["podspec"] = self.spec
84
- download_params["source_files"] = self.spec.source_files.keys
85
- else
86
- download_params["podspec"] = nil
87
- download_params["source_files"] = ["All"]
88
- end
67
+ download_params = download_params.merge(download_urls)
89
68
  download_params
90
69
  end
91
70
 
@@ -102,18 +81,18 @@ module LgPodPlugin
102
81
  return nil unless repo_name
103
82
  if self.git && self.tag
104
83
  download_url = "https://codeload.github.com/#{repo_name}/tar.gz/refs/tags/#{self.tag}"
105
- [{ "filename" => "#{project_name}.tar.gz", "url" => download_url }]
84
+ { "filename" => "#{project_name}.tar.gz", "url" => download_url }
106
85
  elsif self.git && self.branch
107
86
  if self.branch == "HEAD"
108
87
  download_url = "https://gh.api.99988866.xyz/" + "#{base_url}" + "/archive/#{self.branch}.tar.gz"
109
- [{ "filename" => "#{project_name}.tar.gz", "url" => download_url }]
88
+ { "filename" => "#{project_name}.tar.gz", "url" => download_url }
110
89
  else
111
90
  download_url = "https://codeload.github.com/#{repo_name}/tar.gz/refs/heads/#{self.branch}"
112
- [{ "filename" => "#{project_name}.tar.gz", "url" => download_url }]
91
+ { "filename" => "#{project_name}.tar.gz", "url" => download_url }
113
92
  end
114
93
  elsif self.git && self.commit
115
94
  download_url = "https://codeload.github.com/#{repo_name}/tar.gz/#{self.commit}"
116
- return [{ "filename" => "#{project_name}.tar.gz", "url" => download_url }]
95
+ return { "filename" => "#{project_name}.tar.gz", "url" => download_url }
117
96
  else
118
97
  nil
119
98
  end
@@ -23,10 +23,11 @@ module LgPodPlugin
23
23
  return self.get_gitlab_access_token_input(uri, user_id, nil, nil) if encrypt_access_token.nil?
24
24
  end
25
25
  user_id = LUserAuthInfo.get_user_id(uri.hostname)
26
+ now_time = Time.now.to_i
26
27
  refresh_token = json["refresh_token"]
27
28
  expires_in = json["expires_in"] ||= 7879680
28
- created_at = json["created_at"] ||= Time.now.to_i
29
- user_model = LUserAuthInfo.new(user_id, "", "", uri.hostname, access_token, refresh_token, (created_at + expires_in))
29
+ created_at = json["created_at"] ||= now_time
30
+ user_model = LUserAuthInfo.new(user_id, "", "", uri.hostname, access_token, refresh_token, (created_at + expires_in), now_time, 1)
30
31
  LSqliteDb.shared.insert_user_info(user_model)
31
32
  LgPodPlugin.log_green "请求成功: `access_token` => #{access_token}, expires_in => #{expires_in}"
32
33
  return user_model
@@ -48,13 +49,12 @@ module LgPodPlugin
48
49
  def self.check_gitlab_access_token_valid(uri, user_info)
49
50
  time_now = Time.now.to_i
50
51
  refresh_token = user_info.refresh_token
51
- # 判断 token 是否失效
52
- if user_info.expires_in <= time_now
53
- if refresh_token.nil? || refresh_token == "" # 使用本地令牌访问
52
+ if user_info.type == 1
53
+ if user_info.expires_in <= time_now
54
54
  project_name = LUtils.get_git_project_name(uri.to_s)
55
- token_vaild = GitLabAPI.request_user_emails(uri.hostname, user_info.access_token)
56
- if token_vaild == "success"
57
- new_user_info = LUserAuthInfo.new(user_info.id, "", "", uri.hostname, user_info.access_token, nil, (time_now + 7879680))
55
+ token_valid = GitLabAPI.request_user_emails(uri.hostname, user_info.access_token)
56
+ if token_valid == "success"
57
+ new_user_info = LUserAuthInfo.new(user_info.id, "", "", uri.hostname, user_info.access_token, nil, (time_now + 7879680), time_now, 1)
58
58
  LSqliteDb.shared.insert_user_info(user_info)
59
59
  return new_user_info
60
60
  else
@@ -63,21 +63,25 @@ module LgPodPlugin
63
63
  return self.get_gitlab_access_token_input(uri, user_info.id, nil, nil)
64
64
  end
65
65
  else
66
- # 刷新 token 失败时, 通过已经保存的用户名密码来刷新 token
67
- return refreshUserToken uri, refresh_token, user_info.id, user_info.username, user_info.password
66
+ return user_info
68
67
  end
69
68
  else
70
- update_time = user_info.update_time.to_i
71
- if time_now - update_time > 1800
72
- user_info = refreshUserToken uri, refresh_token, user_info.id, user_info.username, user_info.password
73
- return user_info
69
+ # 判断 token 是否失效
70
+ if user_info.expires_in <= time_now
71
+ return refresh_user_token uri, refresh_token, user_info.id, user_info.username, user_info.password
74
72
  else
75
- return user_info
73
+ update_time = user_info.update_time.to_i
74
+ if time_now - update_time > 1800
75
+ user_info = refresh_user_token uri, refresh_token, user_info.id, user_info.username, user_info.password
76
+ return user_info
77
+ else
78
+ return user_info
79
+ end
76
80
  end
77
81
  end
78
82
  end
79
83
 
80
- def self.refreshUserToken(uri, refresh_token, user_id, username, password)
84
+ def self.refresh_user_token(uri, refresh_token, user_id, username, password)
81
85
  # 刷新 token 失败时, 通过已经保存的用户名密码来刷新 token
82
86
  new_user_info = GitLabAPI.refresh_gitlab_access_token uri.hostname, refresh_token
83
87
  unless new_user_info
@@ -109,7 +113,7 @@ module LgPodPlugin
109
113
  expires_in = json["expires_in"] ||= 7200
110
114
  created_at = json["created_at"] ||= Time.now.to_i
111
115
  time_now = Time.now.to_i
112
- user_model = LUserAuthInfo.new(user_id, username, password, host, access_token, refresh_token, (created_at + expires_in), time_now)
116
+ user_model = LUserAuthInfo.new(user_id, username, password, host, access_token, refresh_token, (created_at + expires_in), time_now, 0)
113
117
  LSqliteDb.shared.insert_user_info(user_model)
114
118
  LgPodPlugin.log_green "请求成功: `access_token` => #{access_token}, expires_in => #{expires_in}"
115
119
  rescue => exception
@@ -148,6 +152,7 @@ module LgPodPlugin
148
152
  user_model.access_token = access_token
149
153
  user_model.refresh_token = refresh_token
150
154
  user_model.update_time = time_now
155
+ user_model.type = 0
151
156
  LSqliteDb.shared.insert_user_info(user_model)
152
157
  LgPodPlugin.log_green "刷新token成功: `refresh_token` => #{refresh_token}, expires_in => #{expires_in}"
153
158
  return user_model
@@ -259,46 +264,46 @@ module LgPodPlugin
259
264
  end
260
265
  end
261
266
 
262
- public
263
- def self.get_podspec_file_content(host, token, project_id, sha, filepath)
264
- begin
265
- hash_map = Hash.new
266
- hash_map["ref"] = sha
267
- hash_map["access_token"] = token
268
- uri = URI("#{host}/api/v4/projects/#{project_id}/repository/files/#{filepath}")
269
- uri.query = URI.encode_www_form(hash_map)
270
- res = Net::HTTP.get_response(uri)
271
- case res
272
- when Net::HTTPSuccess, Net::HTTPRedirection
273
- json = JSON.parse(res.body)
274
- else
275
- body = JSON.parse(res.body)
276
- message = body["message"]
277
- if message == "404 Project Not Found"
278
- LSqliteDb.shared.delete_project_by_id(project_id)
279
- end
280
- json = nil
281
- end
282
- return nil unless json && json.is_a?(Hash)
283
- content = json["content"]
284
- return nil unless content && LUtils.is_a_string?(content)
285
- encoding = json["encoding"] ||= "base64"
286
- if encoding == "base64"
287
- require 'base64'
288
- content = Base64.decode64(content)
289
- if content.respond_to?(:encoding) && content.encoding.name != 'UTF-8'
290
- text = content.force_encoding("gb2312").force_encoding("utf-8")
291
- return text
292
- else
293
- return content
294
- end
295
- else
296
- return nil
297
- end
298
- rescue
299
- return nil
300
- end
301
- end
267
+ # public
268
+ # def self.get_podspec_file_content(host, token, project_id, sha, filepath)
269
+ # begin
270
+ # hash_map = Hash.new
271
+ # hash_map["ref"] = sha
272
+ # hash_map["access_token"] = token
273
+ # uri = URI("#{host}/api/v4/projects/#{project_id}/repository/files/#{filepath}")
274
+ # uri.query = URI.encode_www_form(hash_map)
275
+ # res = Net::HTTP.get_response(uri)
276
+ # case res
277
+ # when Net::HTTPSuccess, Net::HTTPRedirection
278
+ # json = JSON.parse(res.body)
279
+ # else
280
+ # body = JSON.parse(res.body)
281
+ # message = body["message"]
282
+ # if message == "404 Project Not Found"
283
+ # LSqliteDb.shared.delete_project_by_id(project_id)
284
+ # end
285
+ # json = nil
286
+ # end
287
+ # return nil unless json && json.is_a?(Hash)
288
+ # content = json["content"]
289
+ # return nil unless content && LUtils.is_a_string?(content)
290
+ # encoding = json["encoding"] ||= "base64"
291
+ # if encoding == "base64"
292
+ # require 'base64'
293
+ # content = Base64.decode64(content)
294
+ # if content.respond_to?(:encoding) && content.encoding.name != 'UTF-8'
295
+ # text = content.force_encoding("gb2312").force_encoding("utf-8")
296
+ # return text
297
+ # else
298
+ # return content
299
+ # end
300
+ # else
301
+ # return nil
302
+ # end
303
+ # rescue
304
+ # return nil
305
+ # end
306
+ # end
302
307
 
303
308
  # 通过名称搜索项目信息
304
309
  public